I hereby claim:
- I am jin on github.
- I am jin (https://keybase.io/jin) on keybase.
- I have a public key whose fingerprint is 124B CC2E 008C 650E FF3D EC71 47D0 E655 F065 B791
To claim this, I am signing this object:
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) |
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) |
#!/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 |
# 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) |
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' }) |
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 |
# A USB tether always make use of the 3G/4G connection of your iPhone. | |
# You can override this config by buying MyWi 8.0 for 20 bucks or | |
# do the following. :-) | |
# Skip to step 4 if you already have ssh set up. | |
# 1) Install OpenSSH from Cydia | |
# 2) ssh into your phone. default password is `alpine`. | |
# I use CCSystemInfo to access my iPhone's cellular IP address easily. |
I hereby claim:
To claim this, I am signing this object:
/**************************************************************** | |
* Sudoku Solver | |
* | |
* Translated into Javascript from original code in C++ | |
* by Lee Hsien Loong | |
* The MIT License (MIT) | |
* Copyright (c) 2015 Vivian Balakrishnan | |
* | |
* | |
****************************************************************/ |
require 'nokogiri' | |
require 'httparty' | |
require 'concurrent' | |
require 'pp' | |
class HWZRequest | |
def initialize | |
@host = "http://forums.hardwarezone.com.sg" | |
end |