http://www.ncgia.ucsb.edu/giscc/units/u014/u014.html
Tutorial on lat, long
http://www.movable-type.co.uk/scripts/latlong.html
http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/
calculating if a point is in a polygon
http://williams.best.vwh.net/avform.htm
Monday, August 20, 2007
Sunday, August 19, 2007
Attribute writers
attr_writer bla
There are numerous ways to define class methods.
Make methods public, protected and public by using the keyword then any methods that come after that keyword fall under accessor.
Protected methods are accessible from the objects of the defining class and its subclasses. Private methods can only be called by the object of class that defines them. Protected access can also occur between objects of the same class. Methods are public by default.
dup method
Freeze an object from modification using the 'freeze' method
Creating arrays
There are all sorts of ways you can manipulate arrays, similar to perl. There are also apparently lots of methods on arrays that lets you use them as queues, stacks eg push, pop
To support chaining, return "self" (have self as last line in method).
Iterators and blocks
Blocks
inject for accummulating along a list. (can leave the parameter off and it will use the first element)
Args pointer
If File.open has an associated block, then that block will be invoked with a file object, and the file will be closed when the block terminates.
Some kernel methods:
That code block is converted to an object of class Proc and assigned to the parameter
Associated with a block (and hence a Proc object)
is all the context in which the block was defined: the value of self and the methods,
variables, and constants in scope. Part of the magic of Ruby is that the block can still
use all this original scope information even if the environment in which it was defined
would otherwise have disappeared. In other languages, this facility is called a closure.
The method n_times returns a Proc object that references the method’s parameter,
thing. Even though that parameter is out of scope by the time the block is called, the
parameter remains accessible to the block.
attr_writer bla
There are numerous ways to define class methods.
Make methods public, protected and public by using the keyword then any methods that come after that keyword fall under accessor.
Protected methods are accessible from the objects of the defining class and its subclasses. Private methods can only be called by the object of class that defines them. Protected access can also occur between objects of the same class. Methods are public by default.
dup method
person1 = "Jim"
person2 = person1.dup
person1[0] = 'T'
person1 -> "Tim"
person2 -> "Jim"
Freeze an object from modification using the 'freeze' method
Creating arrays
a = [1.3, "foo", 55]
a = Array.new
a[0] = "bla"
a[1] = 4
a[5] -> nil
There are all sorts of ways you can manipulate arrays, similar to perl. There are also apparently lots of methods on arrays that lets you use them as queues, stacks eg push, pop
To support chaining, return "self" (have self as last line in method).
Iterators and blocks
@songs.find {|song| title == song.name }
Blocks
- start on same line as method call after last parameter or parentheses
- variables and scope is a little complicated - if you are passed local variables from the method, the block can alter these. it can have its own locally defined variables, or also inherit the variables from surrounding code.
[1, 2].collect{ |d| d+=1 } -> [2, 3]
inject for accummulating along a list. (can leave the parameter off and it will use the first element)
[1,2,3].inject(0) { |sum, element| sum+=element }
Args pointer
class File
def File.open_and_process(*args)
f = File.open(*args)
yield f
f.close()
end
end
If File.open has an associated block, then that block will be invoked with a file object, and the file will be closed when the block terminates.
Some kernel methods:
- defined?
- Kernel.block_given?
songlist = SongList.new
class JukeboxButton < action =" action" start_button =" JukeboxButton.new(">
That code block is converted to an object of class Proc and assigned to the parameter
Associated with a block (and hence a Proc object)
is all the context in which the block was defined: the value of self and the methods,
variables, and constants in scope. Part of the magic of Ruby is that the block can still
use all this original scope information even if the environment in which it was defined
would otherwise have disappeared. In other languages, this facility is called a closure.
def n_times(thing)
return lambda {|n| thing * n }
end
p1 = n_times(23)
p1.call(3) ! 69
The method n_times returns a Proc object that references the method’s parameter,
thing. Even though that parameter is out of scope by the time the block is called, the
parameter remains accessible to the block.
Thursday, August 16, 2007
Wednesday, August 8, 2007
Monday, August 6, 2007
Mashing Google Maps with Oracle Database - shows how to create google maps from datasets in a database
http://www.oracle.com/technology/pub/articles/schalk-googlemaps.html
Use decimal/numeric for storing lat long values. Apparently 5 digits after decimal gives 1 metre accuracy.
There was a project spatial-db-in-a-box or something I should look into, which shows how to use GeoTools with non-spatial databases.
SQL datatypes: http://www.sql-server-helper.com/faq/data-types-p01.aspx
http://www.oracle.com/technology/pub/articles/schalk-googlemaps.html
Use decimal/numeric for storing lat long values. Apparently 5 digits after decimal gives 1 metre accuracy.
There was a project spatial-db-in-a-box or something I should look into, which shows how to use GeoTools with non-spatial databases.
SQL datatypes: http://www.sql-server-helper.com/faq/data-types-p01.aspx
Saturday, August 4, 2007
On ruby being a genuine OO language - no static method library thingies.. eg.
Classes and Objects
Create setters using equals sign after method name
eg
-1942.abs instead of Math.abs(-1942)Ruby notes
- String interpolation - "#{name.capitalize}"
- Global variable - $greeting
- Instance variable - @name
- Class variables - @@count
- Arrays use integers as keys, hashes can have any object as key
- convenient word array instantiation: a = %w{ ant bee cat dog elk }
- nil also means false
- you can specify the default empty return value of a hash, eg. instead of return nil when lookup fails, you can return 0 - myhash = Hash.new(0)
- Statement modifiers - convenient alternative ways of writing if and while statements if the body is just one line:
puts "Danger, Will Robinson" if radiation > 3000
square = square*square while square <>
- Regular expressions are also objects. they are built into the language
- matching: if line =~ /Perl|Python/
- line.sub(/Perl/, 'Ruby') or line.gsub(/Perl/, 'Ruby')
- one line use braces, multi-line use do, end
- pass them to methods, after all parameters
- method can run the block any number of times using the yield method
- Some people like to think of the association of a block with a method as a kind of parameter passing. This works on one level, but it isn’t really the whole story. You may be better off thinking of the block and the method as coroutines, which transfer control back and forth between themselves.
- You can provide parameters to the call to yield: these will be passed to the block.
Within the block, you list the names of the arguments to receive these parameters
between vertical bars (|). - example uses of iterators:
[ 'cat', 'dog', 'horse' ].each {|name| print name, " " }
5.times { print "*" }
3.upto(6) {|i| print i }
('a'..'e').each {|char| print char }
Classes and Objects
- initialize method is the constructor - what gets called when you do Song.new
- subclassing
class KaraokeSong < lyrics =" lyrics">
- when subclassing, ruby doesn't know which object will provide the implementation of a method until runtime - it looks for an implementation of a method in the inheritance chain starting with the child.
- shortcut for creating getters for instance variables :
class Song
attr_reader :name, :artist, :duration
end
Create setters using equals sign after method name
eg
def duration=(new_duration)
@duration = new_duration
end
then call it like this: song.duration = 33
I need a way of organising a project and tasks. Somewhere to write what I plan to achieve, and then checklist of steps to achieve, like what I use paper for.
So something like "new activity" with the aim, then a list of steps.
I can have a separate "notes" section where I put notes.
I would have a timer associated with the activity, and if I wanted, each step even. The activity would belong to the overarching task/goal
Maybe goals, and tasks associated to a goal. So goal could be "learn ruby". And task could be "setup environment".
in order not to forget tech fixes, add them as a blog
So something like "new activity" with the aim, then a list of steps.
I can have a separate "notes" section where I put notes.
I would have a timer associated with the activity, and if I wanted, each step even. The activity would belong to the overarching task/goal
Maybe goals, and tasks associated to a goal. So goal could be "learn ruby". And task could be "setup environment".
in order not to forget tech fixes, add them as a blog
Subscribe to:
Posts (Atom)