This file contains 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 'tweetstream' | |
require 'rtranslate' | |
TweetStream::Client.new('username','password').track('keyword') do |status| | |
puts Translate.t(status[:text], 'en', 'de') | |
end |
This file contains 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
db = Connection.new(ENV['DATABASE_URL']).db(db_name) | |
if ENV['DATABASE_USER'] && ENV['DATABASE_PASSWORD'] | |
auth = db.authenticate(ENV['DATABASE_USER'], ENV['DATABASE_PASSWORD']) | |
end |
This file contains 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
class Polynomial | |
def initialize(coefficients) | |
raise ArgumentError, "Need at least 2 coefficients" if coefficients.size < 2 | |
@co = coefficients | |
@powers = Array.new(@co.size - 2) { |i| "x^#{i+2}"}.reverse << 'x' << nil | |
end | |
def to_s | |
return "0" if @co.all? { |c| c.zero? } # not much to do in this case | |
@co.zip(@powers).map do |el| |
This file contains 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
# This is how you can get a user's location using MacRuby and CoreLocation | |
framework 'CoreLocation' | |
def locationManager(manager, didUpdateToLocation: new_location, fromLocation: old_location) | |
puts "location: #{new_location.description}" | |
exit | |
end | |
loc = CLLocationManager.alloc.init | |
loc.delegate = self |
This file contains 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
# Reincarnation for classes | |
class Class | |
def reincarnate | |
buried = Object.__send__(:remove_const, self.name) | |
Object.const_set(self.name, Class.new(buried)) | |
end | |
end | |
class Abc |
This file contains 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
class Lucky < [String, Array][rand(2)]; end | |
puts Lucky.superclass |
This file contains 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 'clojure' | |
class MyClojureObj < Clojure::Object | |
def initialize | |
dosync { @foo = 'foo' } | |
end | |
def foo; @foo; end | |
def foo=(f); @foo = f; end | |
end |
This file contains 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
Usage: clj [java-opt*] [init-opt*] [main-opt] [arg*] | |
With no options or args, runs an interactive Read-Eval-Print Loop | |
java options: | |
-<javaopt> Configure JVM (see `java -help` for full list) | |
-d, --debug port Open a port for debugging | |
init options: | |
-i, --init path Load a file or resource |
This file contains 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
(use '(incanter core charts io)) | |
(def usage (read-dataset "report.csv" :header true)) | |
(def instance-types | |
(set (filter #(re-find #"BoxUsage" %) ($ :UsageType usage)))) | |
(with-data (->> ($rollup :sum :UsageValue :UsageType usage) | |
($where {:UsageType {:$in instance-types}})) | |
(view (bar-chart :UsageType :UsageValue | |
:title "EC Instance Usage" |