Skip to content

Instantly share code, notes, and snippets.

View v2e4lisp's full-sized avatar

Yan Wenjun v2e4lisp

View GitHub Profile
@v2e4lisp
v2e4lisp / gist:4194576
Created December 3, 2012 12:04
necklace problem... (done)
# nl(s) is short for necklace(s)
# generate all candidate necklaces
def nls_init(n, m, necklaces = ['']):
if not m: return map(lambda x: n*'1'+x, necklaces)
if not n: return map(lambda x: m*'0'+x, necklaces)
n1 = nls_init(n, m-1, map(lambda x: '0'+x, necklaces))
n2 = nls_init(n-1, m, map(lambda x: '1'+x, necklaces))
return n1 + n2
@v2e4lisp
v2e4lisp / jsmin.js
Created December 5, 2012 10:32
javascript minifier written in javascript (todo);
var jsmin = function (js_string) {
js_min = {
holder: '/*wenjun.yan*/', // the minified js
pos: 0, // current position
chr: ' ', // current char
js_string: js_string, // unminified js
specs: ["'", '"', '{', '}', '(', ')',
'[', ']', '+', '-', '*', '/',
':', '?', '!', '|', '&', '\\',';'],
@v2e4lisp
v2e4lisp / js-note.org
Created December 5, 2012 16:31
My javascript's dark side

this

  • Use new to create an object x. Then x’s prototype is what?

Why can’t I do this x.prototype.some_method=…;

org-mode available?

org-mode with url-to-google

@v2e4lisp
v2e4lisp / automata.js
Created December 6, 2012 03:36
javascript string match automata. (tobefixed)
var string_automata = function (string) {
var length = string.length;
var init = string[0];
var automata = [];
automata[0][init] = [1];
// var get_state_by_id = function (id) {
// return automata[id];
// }
@v2e4lisp
v2e4lisp / string.c
Created December 6, 2012 07:42
string length is even or not #c
main()
{
for (;;) {
if (getchar() == EOF) return TRUE;
if (getchar() == EOF) return FALSE;
}
}
@v2e4lisp
v2e4lisp / jsmin.output.log
Created December 6, 2012 11:59
the output of the jsmin.... error!
WHILE current char : a
stepin blank:
step in next:
step out next: a
stepout blank: a
BLANK current char : a
WHILE current char : a r
ERROR current char : a
error4
@v2e4lisp
v2e4lisp / emacs-init.el
Last active February 26, 2017 07:02
run current script (py, rb, el, js, php...)
;;; THIS gist is from Xah Emacs Tutorial
;;; http://ergoemacs.org/emacs/emacs.html
(defun run-current-file ()
"Execute or compile the current file.
For example, if the current buffer is the file x.pl,
then it'll call “perl x.pl” in a shell.
The file can be php, perl, python, ruby, javascript, bash, ocaml, vb, elisp.
File suffix is used to determine what program to run.
@v2e4lisp
v2e4lisp / get_props_if.js
Last active December 9, 2015 20:58
get properties of an object;
// get properties of an object;
// if f(property) is true;
var get_props_if = function (obj, f) {
f = f || function (arg) {return true;};
var holder = [];
for (var p in obj) if (f.call(obj, p)) {
holder.push(p);
}
@v2e4lisp
v2e4lisp / only-current-buffer.el
Last active December 10, 2015 15:28
delete all other buffer except the current one.
(defun only-current-buffer ()
(interactive)
(mapc 'kill-buffer (cdr (buffer-list (current-buffer)))))
@v2e4lisp
v2e4lisp / init.el
Created January 6, 2013 15:30
plist-to-alist fix the bug of the color-theme for emacs 24
(defun plist-to-alist (the-plist)
(defsubst get-tuple-from-plist (the-plist)
(when the-plist
(cons (car the-plist) (cadr the-plist))))
(let ((alist '()))
(while the-plist
(add-to-list 'alist (get-tuple-from-plist the-plist))
(setq the-plist (cddr the-plist)))
alist))