Skip to content

Instantly share code, notes, and snippets.

to compile:
valac -o sum --pkg vala-1.0 stdin_reader.vala sum_application.vala
using GLib;
namespace snuxoll {
class StdinReader : Object {
public StdinReader () {
}
public bool eof() {
#!/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}"
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)
}
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
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
name: Stefan Nuxoll
age: 17
# 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
# 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
#
# 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