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:
I hereby claim:
To claim this, I am signing this object:
| # 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. |
| 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 |
| 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' }) |
| # 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) |
| #!/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 |
| 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) |
| 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 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 | |
| } |
| #!/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 |