Skip to content

Instantly share code, notes, and snippets.

View kaneshin's full-sized avatar
💡

Shintaro Kaneko kaneshin

💡
View GitHub Profile
@kaneshin
kaneshin / imply.js
Created September 19, 2011 04:51
a function is an object.
function foo() {
alert("Hello");
}
var foo = function() {
alert("Hello");
};
@kaneshin
kaneshin / constructor.js
Created September 19, 2011 05:07
function type constructor
var constructor = function(spec, my) {
var that = {},
/* private instance variables */
foo;
/* shared objects */
my = my || {};
/** accessible method */
that.hoge = function() {
huga();
" ***** mattn/gist-vim *****
" --- gist setting ---
" let g:github_user = 'kaneshin'
" let g:github_token = '<api token>'
" let g:gist_privates = 1
" --- key map ---
" post to gist
nnoremap ,gs :<C-u>Gist<CR>
" update gist
nnoremap ,ge :<C-u>Gist -e<CR>
@kaneshin
kaneshin / s_or_SID.vim
Created October 1, 2011 16:57
How to use s: or <SID>
" How to use 's:' or '<SID>'
"--------------------
" s:
" :autocmd, :command, :function/:endfunction
command! -nargs=1 Foo :call s:foo(<f-args>)
function! s:foo(bar)
let l:baz = 0
" ...
return s:foo(l:baz)
endfunction
" Fibonacci number - vim
command! -nargs=1 Fibonacci :echo s:fibonacci(<f-args>)
function! s:fibonacci(n)
if a:n < 1
return 1 " F_0
elseif a:n == 1
return 1 " F_1
endif
return s:fibonacci(a:n - 1) + s:fibonacci(a:n - 2)
endfunction
" Factorial - vim
command! -nargs=1 Factorial :echo s:factorial(<f-args>)
function! s:factorial(n)
if a:n <= 1
return 1
else
return a:n * s:factorial(a:n - 1)
endif
endfunction
" Greatest Common Divisor - vim
command! -nargs=+ GreatestCommonDivisor :echo s:gdb(<f-args>)
function! s:gdb(a, b)
let l:r = a:a % a:b
if l:r
return s:gdb(a:b, l:r)
else
return a:b
endif
endfunction
var foo = {
bar: 10,
baz: function(num, callback) {
callback(num * num);
},
qux: function(num, callback) {
var self = this;
this.baz(num, function(res) {
callback(res + self.bar);
});
$.each(section, function(i, line) {
@kaneshin
kaneshin / .screenrc
Created October 26, 2011 12:29
screen run command(dotfile)
# vim:set ts=8 sts=2 sw=2 tw=0:
#===========================================================================
# File: .screenrc
# Last Change: 19-Oct-2011.
# Maintainer: Shintaro Kaneko <[email protected]>
#===========================================================================
##############################
# encoding setting
##############################