This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| to compile: | |
| valac -o sum --pkg vala-1.0 stdin_reader.vala sum_application.vala |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using GLib; | |
| namespace snuxoll { | |
| class StdinReader : Object { | |
| public StdinReader () { | |
| } | |
| public bool eof() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| total = 0 | |
| STDIN.each_line do |line| | |
| total += line.split(" ").inject(0) { |sum, x| sum + x.to_i } | |
| end | |
| puts "GRAND TOTAL: #{total}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module YCombinator | |
| def y_comb(&generator) | |
| proc { |x| | |
| proc { |*args| | |
| generator.call(x.call(x)).call(*args) | |
| } | |
| }.call(proc { |x| | |
| proc { |*args| | |
| generator.call(x.call(x)).call(*args) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'network_connection' | |
| conn = NetworkConnection.new('irc.freenode.net', 6667) | |
| # Create a new handler for the event | |
| conn.data_received + lambda do |server, text| | |
| if text =~ /^PING/ | |
| server.send(text.gsub(/^PING/, "PONG")) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'ruby-event' | |
| # General purpose wrapper for network connections | |
| class NetworkConnection | |
| attr_reader :hostname, :port, :thread | |
| # Create a new event to be fired when we recieve data | |
| # from the server | |
| event :data_received | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Stefan Nuxoll | |
| age: 17 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # adds two named arguments passed in, named :first and | |
| # :second respectively | |
| def add(args) | |
| args[:first] + args[:second] | |
| end | |
| # Call it using 1.8 and below style | |
| puts add(:first => 2, :second => 4) # 6 | |
| # Call it using the 1.9 style hash syntax |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Adds the two arguments passed in to the method | |
| def add(num1, num2) | |
| num1 + num2 | |
| end | |
| # We have an array that we want to pass in to add, | |
| # with each item as a seperate argument | |
| my_args = [1, 2] | |
| # Prefixing a variable name with a * will attempt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Return UTM Zone for a geom | |
| # | |
| # Return Integer | |
| def utm_zone | |
| geomgeog = srid == 4326 ? self[get_column_name] : transform(4326) | |
| puts geomgeog.class | |
| geom = case geomgeog | |
| when Point then geomgeog | |
| when LineString then geomgeog.first |