Skip to content

Instantly share code, notes, and snippets.

@jin
jin / about.md
Last active September 11, 2019 16:52 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@jin
jin / rails-3.1-gemfile.rb
Created September 2, 2011 01:46
Gemfile of fresh Rails 3.1 app, clean RVM 1.9.2 gemset except for Rails itself
source 'http://rubygems.org'
gem 'rails', '3.1.0'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
@jin
jin / ex37.rb
Created September 13, 2011 08:16
Ruby symbols review: Learn Ruby The Hard Way
descriptions = {}
# ========
# KEYWORDS
# ========
# -----
# alias
# -----
array = [
{:name=>"site a", :url=>"http://example.org/site/1/"},
{:name=>"site b", :url=>"http://example.org/site/2/"},
{:name=>"site c", :url=>"http://example.org/site/3/"},
{:name=>"site d", :url=>"http://example.org/site/1/"},
{:name=>"site e", :url=>"http://example.org/site/2/"},
{:name=>"site f", :url=>"http://example.org/site/6/"},
{:name=>"site g", :url=>"http://example.org/site/1/"}
]
@jin
jin / git-restore-deleted-file.sh
Created October 2, 2011 13:24
Git: Restore a deleted file
#!/bin/sh
git log --diff-filter=D --summary
git checkout $commit~1 filename
@jin
jin / Q1.js
Last active December 22, 2015 13:59
DG3
// integration using Simpson's Law
function calc_integral (func, a, b, n) {
var h = (b - a) / n;
function helper (func, acc, k) {
if (k === n) {
if (k % 2 === 0) {
return (acc + 2 * func(a + k * h));
} else {
return (acc + 4 * func(a + k * h));
@jin
jin / osrc.rb
Last active August 29, 2015 14:01
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
# http://www.spoj.com/problems/TEST/
guess = STDIN.gets.chomp().to_i
while guess != 42
puts guess
guess = STDIN.gets.chomp().to_i
end
@jin
jin / Xcode wifi automatic build script
Last active August 29, 2015 14:02
Automatically installing apps on your device wirelessly when they are built in Xcode with Jailbroken iPhone
#!/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
@jin
jin / attribute_declaration.rb
Created June 18, 2014 09:09
better way of organizing attributes in ruby models
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
}