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 'json' | |
require 'net/http' | |
require 'rubygems' | |
staffs = %w(weesun knmnyn wgx731 Leventhan franklingu Limy Muhammad-Muneer) | |
baseurl = "http://osrc.dfm.io/" | |
# Construct the json URLs | |
def construct_urls(base_url, usernames, suffix) | |
urls = Array.new |
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
# http://www.spoj.com/problems/TEST/ | |
guess = STDIN.gets.chomp().to_i | |
while guess != 42 | |
puts guess | |
guess = STDIN.gets.chomp().to_i | |
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
#!/bin/sh | |
# Modified code from original at http://iphonedevwiki.net/index.php/Xcode#Automatically_installing_apps_on_your_device_wirelessly_when_they_are_built_in_Xcode | |
# Modify this to your device's IP address. | |
IP="192.168.1.67" | |
osascript -e 'display notification "Updating app on iPhone" with title "Xcode"' | |
# Verify that the build is for iOS Device and not a Simulator. | |
if [ "$NATIVE_ARCH" == "armv7" ]; then |
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 User | |
PROPERTIES = [:id, :name, :email] | |
PROPERTIES.each { |prop| | |
attr_accessor prop | |
} | |
def initialize(attributes = {}) | |
attributes.each { |key, value| | |
self.send("#{key}=", value) if PROPERTIES.member? key | |
} |
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
def check_string(str) | |
str.empty? || is_balanced(0, str) | |
end | |
def is_balanced(num_left_brackets, str) | |
if str.head == "[" | |
is_balanced(num_left_brackets + 1, str.tail) | |
elsif str.head == "]" | |
return false if num_left_brackets == 0 | |
is_balanced(num_left_brackets - 1, str.tail) |
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 Array | |
def reduce(func, init) | |
if self.length < func.arity | |
res = nil | |
elsif self.length == func.arity | |
res = func.call(*self) | |
else | |
res = func.call(self[0], self[1..-1].reduce(func, nil)) | |
end | |
init.nil? ? res : func.call(init, res) |
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
#!/usr/bin/env ruby | |
def sum_of_differences(arr) | |
total = 0 | |
arr.each_cons(2) do |x, y| | |
total += (x - y).abs | |
end | |
total | |
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
# Regular Ruby methods, can't pass them around like function objects | |
def length(xs) | |
return 0 if xs.empty? | |
1 + length(xs[1..-1]) | |
end | |
def map(xs, process = -> (x) { x }) | |
return [] if xs.empty? | |
[process.call(xs.first)] + map(xs[1..-1], process) |
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
def sort hash | |
hash.keys.map(&:to_s).sort(& -> (a, b) { a.length <=> b.length }) | |
end | |
p sort ({ abc: 'hello', 'another_key' => 123, 4567 => 'third' }) |
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
Node = Struct.new(:val, :next_node) do | |
def length | |
return 1 if next_node.nil? | |
1 + next_node.length | |
end | |
def to_s | |
self.to_a.join(", ") | |
end |
OlderNewer