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 'tweetstream' | |
require 'rtranslate' | |
TweetStream::Client.new('username','password').track('keyword') do |status| | |
puts Translate.t(status[:text], 'en', 'de') | |
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
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 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
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 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
class Lucky < [String, Array][rand(2)]; end | |
puts Lucky.superclass |
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
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 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
(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" |
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
user=> ; generate random number | |
user=> (rand) | |
0.8545074632292601 | |
user=> ; infinite list of random numbers | |
user=> ; make sure to set *print-length* | |
user=> (set! *print-length* 10) | |
10 | |
user=> (repeatedly rand) | |
(0.13569783475252373 0.585868618595554 0.7048671603900427 0.1440943435265447 0.24546858003727567 0.15406959135696596 0.41117257771529947 0.1115848319639422 0.669215744258339 0.1521494621978804 ...) | |
user=> ; get the reductions function from seq-utils |
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
class Fixnum | |
alias_method :intdiv, :/ | |
def /(divisor) | |
(self % divisor) == 0 ? self.intdiv(divisor) : self.to_f/divisor | |
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
user=> ; get the expt funtion | |
user=> (use '[clojure.contrib.math :only (expt)]) | |
nil | |
user=> (expt 2 3) | |
8 | |
user=> ; function to calculate no. of pairs for n people | |
user=> (defn number-pairs [n] (/ (* n (- n 1)) 2)) | |
#'user/number-pairs | |
user=> ; how many pairs for 23 people? | |
user=> (number-pairs 23) |