Skip to content

Instantly share code, notes, and snippets.

@bom-d-van
bom-d-van / ruby
Created February 5, 2012 04:18
gist testing
p "foo testing..."
@bom-d-van
bom-d-van / Rails AR Clone.rb
Created May 26, 2012 14:12
the simplest way to clone or duplicate an ar record in rails
# http://stackoverflow.com/questions/60033/what-is-the-easiest-way-to-duplicate-an-activerecord-record
# rails < 3.1
new_record = old_record.clone
#rails >= 3.1
new_record = old_record.dup
@bom-d-van
bom-d-van / gist:2794506
Created May 26, 2012 16:24 — forked from chad/gist:76951
How to find out where a method comes from.
# How to find out where a method comes from.
# Learned this from Dave Thomas while teaching Advanced Ruby Studio
# Makes the case for separating method definitions into
# modules, especially when enhancing built-in classes.
module Perpetrator
def crime
end
end
class Fixnum
@bom-d-van
bom-d-van / diverge branch.sh
Created May 26, 2012 16:40
Move recent commit to a new branch
# http://stackoverflow.com/questions/1628563/git-move-recent-commit-to-a-new-branch
git branch newbranch
git reset --hard HEAD~3 # Go back 3 commits. You *will* lose uncommitted work.
git checkout newbranch
@bom-d-van
bom-d-van / git.sh
Created May 31, 2012 15:37
Some git commands.
# How to add remote repo in git, the example is following:
git remote add origin git@github.com:caius/foo.git
@bom-d-van
bom-d-van / Gits.sh
Created June 9, 2012 07:16
Discard unstaged changes in git
# For a specific file use:
git checkout path/to/file/to/revert
# For all unstaged files use(Make sure to include the period at the end.):
git checkout -- .
@bom-d-van
bom-d-van / index.html
Created August 10, 2012 00:22
A web page created at CodePen.io.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- IF PEN IS PRIVATE -->
<!-- <meta name="robots" content="noindex"> -->
<!-- END -->
@bom-d-van
bom-d-van / asess_lesson.js
Created December 18, 2012 05:18
Half auto accessing lesson for students at Huizhou University.
javascript: (function () { var main = document.getElementsByTagName('frame')[2], selects = main.contentDocument.getElementsByTagName('select'); for (var i = 1; i < selects.length; i++) { selects.item(i).value = Math.random() > 0.5 ? "5(良好)" : "4(优秀)"; } main.contentDocument.getElementById('Button1').click();})();
package main
import (
"fmt"
)
func GetStructField(f interface{},path []string) interface{} {
rangeOver := f.( map[string]interface{})
counter := 0
maxLen := len(path)-1
@bom-d-van
bom-d-van / cp.go
Created May 3, 2013 13:26 — forked from elazarl/cp.go
package cp
import (
"io"
"os"
)
func cp(dst, src string) error {
s, err := os.Open(src)
if err != nil {