Skip to content

Instantly share code, notes, and snippets.

View citizen428's full-sized avatar

Michael Kohl citizen428

View GitHub Profile
require 'tweetstream'
require 'rtranslate'
TweetStream::Client.new('username','password').track('keyword') do |status|
puts Translate.t(status[:text], 'en', 'de')
end
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
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 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
# 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
class Lucky < [String, Array][rand(2)]; end
puts Lucky.superclass
require 'clojure'
class MyClojureObj < Clojure::Object
def initialize
dosync { @foo = 'foo' }
end
def foo; @foo; end
def foo=(f); @foo = f; end
end
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
(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"