Skip to content

Instantly share code, notes, and snippets.

@GingerBear
GingerBear / state_machine.js
Created October 13, 2013 20:59
JavaScript State Machine
var Events = {
bind: function(){
if (!this.o) this.o = $({});
this.o.bind.apply(this.o, arguments);
},
trigger: function(){
if (!this.o) this.o = $({});
this.o.trigger.apply(this.o, arguments);
}
@GingerBear
GingerBear / add_remove_mongodb_field.js
Last active December 26, 2015 01:39
MongoDB add/remove a field
// Add a field
db.products.update(
{ },
{ $set:
{ quantity: "",
instock: ""
}
},
{ multi: true }
)
@GingerBear
GingerBear / match_type.c
Created December 8, 2013 21:12
Dummy matching of type of in string
#include <stdio.h>
int match_type(char *str, char *type)
{
printf("%s\n", str);
printf("%s\n", type);
int i = 0, j = 0, count = 0;
char tmp1[10];
char c;
while ((c = str[i]) != '\0')
@GingerBear
GingerBear / url_param.js
Created January 14, 2014 22:47
JavaScript URL parameters parsing by Regular Expression
function url_param(url) {
var _url = url || window.location.href;
var array = _url.match(/\w+=\w+/g);
var result = {};
var tmp = [];
for (var i = 0; i < array.length; i++) {
tmp = array[i].split("=");
result[tmp[0]] = tmp[1];
}
@GingerBear
GingerBear / dabblet.css
Created March 6, 2014 20:19
horizontal centering
/* horizontal centering
method 1; negative margin
h1 {
width: 350px;
position: relative;
left: 50%;
margin-left: -175px;
}*/
@GingerBear
GingerBear / dabblet.css
Created March 6, 2014 20:35 — forked from anonymous/dabblet.html
vertical and horizontal centering
/* vertical and horizontal centering
method 1: absolute position + negative margin
h1 {
position: absolute;
width: 350px;
height: 50px;
left: 50%;
top: 50%;
@GingerBear
GingerBear / dabblet.css
Created March 8, 2014 19:41 — forked from anonymous/dabblet.html
Untitled
h3 {
font-size: 15px;
color: #333;
font-family: 'arial';
}
ul {
list-style: none;
padding-left: 0px;
width: 600px;
}
#!/usr/bin/env bash
curl https://s3.amazonaws.com/heroku-jvm-buildpack-vi/vim-7.3.tar.gz --output vim.tar.gz
mkdir vim && tar xzvf vim.tar.gz -C vim
export PATH=$PATH:/app/vim/bin
@GingerBear
GingerBear / gist:fcec254d414d7134dfe4
Last active August 29, 2015 14:22
convert table tag to div
function tableToDiv(html) {
return html.replace(/<(\/?)(table|thead|tbody|tfoot|th|td|tr)/gi, '<$1div data-original-tag="$2"');
}
// save
require('fs').writeFile("/Users/guanxiongding/Desktop/test.html", body, function() {});
// load
body = require('fs').readFileSync('/Users/guanxiongding/Desktop/test.html', {encoding: 'utf8'})
$ = require('bb_platform/node_modules/cheerio').load(body);