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
######## | |
# Hash # | |
######## | |
def function(opts) | |
request = {} | |
request[:name] = opts[:name] if opts[:name] | |
request[:email] = opts[:email] if opts[:email] | |
request[:address] = opts[:name] if opts[:name] | |
post_to_service(request) | |
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
(ns clojure-euler.core | |
(:gen-class)) | |
;The prime factors of 13195 are 5, 7, 13 and 29. | |
;What is the largest prime factor of the number 600851475143 ? | |
(defn divides_cleanly | |
"[arg1 arg2] True if the remainder of arg1 / arg2 is 0" | |
[arg1 arg2] |
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 Fatter | |
def self.included(base) | |
base.class_eval do | |
def self.fattr_accessor(_symbol) | |
raise "NotASymbol" unless _symbol.is_a? Symbol | |
ivar_as_symbol = ("@" + _symbol.to_s).to_sym | |
define_method(_symbol.to_s) do | |
self.instance_variable_get(ivar_as_symbol) | |
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
# gem install sinatra | |
# sinatra.rb | |
require 'rubygems' | |
require 'sinatra' | |
get "/" do | |
"This is the main page" | |
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 Person | |
attr_accessor :name, :age, :weight | |
def initialize(hash) | |
hash.each do |key, value| | |
setter_method = key.to_s + "=" | |
send(setter_method, value) | |
end | |
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
methods = ['foo', 'bar', 'baz'] | |
methods.each do |method_name| | |
define_method(method_name) do |arg| | |
puts arg.upcase | |
end | |
end | |
foo("hi") | |
# => HI |
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
# Let's play hangman! | |
module HangmanErrors | |
class YaDunGoofedError < StandardError; end | |
class HolyShitYouWon < StandardError; end | |
end | |
class TheGame | |
include HangmanErrors | |
attr_accessor :round |
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
10.times do | |
@rate ||= 0.0 | |
start_time = Time.now.to_i | |
start_count = Property.external.count.to_f | |
sleep rand(30..60) | |
end_time = Time.now.to_i | |
end_count = Property.external.count.to_f | |
properties_per_second = ((end_count - start_count) / (end_time - start_time) ) | |
@rate += properties_per_second | |
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
cities_array = IO.readlines('cities.txt') | |
cities_array.each do |entry| | |
entry.gsub!("\\n","") | |
entry.gsub!("{\"Name\":\"","") | |
entry.gsub!(/\",\"Type\":\"City\",\"BID\":null,\"City\":null,\"State\":\"..\"}/,"") | |
entry.gsub!("][","],[") | |
end | |
cities_array = cities_array.first.split(",").select{ |i| i != "[]" } | |
cities_array.each do |city| | |
city.gsub!("[","") |
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
#!/bin/bash | |
for a in {a..z} | |
do | |
for b in {a..z} | |
do | |
q=$a$b | |
curl "http://www.homeseekers.com/Include/AJAX/MapSearch/GetLocations.aspx?q="$q"&type=city" >> cities.txt | |
done | |
done |