Skip to content

Instantly share code, notes, and snippets.

View zhuangya's full-sized avatar
🧛‍♂️
only silver bullet is silver bullet.

Ya Zhuang zhuangya

🧛‍♂️
only silver bullet is silver bullet.
View GitHub Profile
@nas
nas / gbgrep
Created May 20, 2011 18:19
git blame with grep
#!/usr/local/bin/ruby
grep = `git grep -n #{ARGV[0]} #{ARGV[1]}`
puts "\n-----------------------------------------------------------"
puts "GREP RESULT"
puts '-----------------------------------------------------------'
puts grep
files = grep.scan /.*\:\d+/
@spicycode
spicycode / tmux.conf
Created September 20, 2011 16:43
The best and greatest tmux.conf ever
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000
@venj
venj / torrent_spider.rb
Last active September 30, 2015 12:27
!!!!!DEPRECATED!!!!! Tracking the changes to the website is FUCKING BORING!!!! Torrent spider. Hard to maintain...Damn it, always changes web page...
#!/usr/bin/env ruby
# Download torrents from SOME WEBSITE.
require "rubygems"
require "open-uri"
require "hpricot"
require "uri"
require "colorize"
require 'uri'
require 'net/http'
@vidoss
vidoss / gist:2178987
Created March 24, 2012 06:20
Using underscore.js while scripting mongodb shell.
MongoDB provides a Javascript shell. But Javascript is no fun without underscore.js
Turned out its straight forward to use underscore.js while scripting mongodb.
Here are the steps.
1) Use underscore to write your db script file (say my_commands.js)
E.g: _.each(db.dbname.find().toArray(), function(itm) { ... })
@zhuangya
zhuangya / id.coffee
Created March 26, 2012 05:35
ID card verify
verify = (idcard) ->
factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
mask = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]
idcard[idcard.length - 1] is mask[((x * factor[i] for x, i in idcard[0...idcard.length - 1]).reduce (x, y) -> x + y) % mask.length].toString()
@seanhandley
seanhandley / gist:3089541
Created July 11, 2012 10:33
Gists - The second class citizens of Github

Gists - The second class citizens of Github

So, let me start by saying that gists are awesome. There's no faster, simpler way for me to share code snippts with syntax highlighting for all to see, clone, comment on and assist with.

Marvellous.

But something has been bothering me about gists for some time. A "Gist" in Github parlance, is a git repository backed file (or set of files) which can be edited in the browser by the owner and commented on by other users. Each edit is a github commit (with a commit SHA) and you can link people to different versions of a diff via a URL.

What I wish you could do is link people to diffs themselves, as you can with a full github repository.

@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@zhuangya
zhuangya / gist:3371803
Created August 16, 2012 17:17
brew installed php5.4 notes.
$ brew install php54 --width-mysql --with-intl --with-fpm --without-apache
==> Installing php54 dependency: icu4c
==> Downloading http://download.icu-project.org/files/icu4c/49.1.2/icu4c-49_1_2-
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/icu4c/49.1.2 --disable-samples --disa
==> make
==> make install
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.
@fphilipe
fphilipe / main.m
Created August 21, 2012 09:01
Objective-C -hash method clash
// This code demonstrates -hash collision on NSString. Two strings have the same
// hash when the first, center, and last 32 chars are identical. The other chars
// don't matter at all.
//
// I had to find this out the hard way when loading images from cache while
// using the url string hash as the cache key. Unfortunately the urls were all
// gravatar urls, thus first 32 chars were identical. Further, all urls also had
// a fallback image url appended as query which covered the 32
// center and end chars. The varying part was between the start and center parts
// and thus the hash was identical for all urls.
@tf198
tf198 / BaseX.php
Created August 23, 2012 01:30
Base encoder with customisable alphabets
<?php
class BaseX {
/** RFC4648 Base62 */
const BASE_64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
/** RFC4648 "URL and Filename safe" Base64 */
const URL_64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";
/** URL and filename safe Base64 in UCA order */