Skip to content

Instantly share code, notes, and snippets.

View kosugi's full-sized avatar

KOSUGI Tomo kosugi

  • tokyo.japan
View GitHub Profile
/*-----------------------------------------------------
jQuery Google Maps 3 Plugin (by forestk)
Copyright (C) 2010 forestk <http://www.forestk.com/>
Code licensed under the MIT License <http://www.opensource.org/licenses/mit-license.php>
Date: 2010-03-18
@author forestk <http://www.forestk.com/>
@version 0.91
-----------------------------------------------------*/
(* Growl Toggler *)
(* based on http://veadardiary.blog29.fc2.com/blog-entry-2449.html *)
tell application "System Events"
set isRunning to (count of (every process whose name is "GrowlHelperApp")) > 0
end tell
if isRunning then
tell application "GrowlHelperApp"
set the allNotificationsList to {"Growl Toggler"}
def createFlipFlop():
def inner():
inner.p = not inner.p
return inner.p
inner.p = 0
return inner
ff = createFlipFlop()
print ff()
print ff()
# -*- coding: utf-8 -*-
import plurk
import plurk_api_urllib2
import simplejson
def do(key, username, password):
# login
api = plurk_api_urllib2.PlurkAPI(key)
@kosugi
kosugi / gist:1297505
Created October 19, 2011 04:58
FizzBuzz
# -*- coding: utf-8 -*-
fb = ((lambda n: str(n), lambda n: 'Buzz'), (lambda n: 'Fizz', lambda n: 'FizzBuzz'))
for n in range(1, 101):
print fb[n % 3 == 0][n % 5 == 0](n)
;; http://qiita.com/items/857
(define (xpl xs)
(let loop ((xs (reverse xs)) (ys '()))
(if (null? xs) (reverse ys)
(loop (cdr xs) (append ys (list (reverse xs)))))))
# -*- coding: utf-8 -*-
# http://d.hatena.ne.jp/JunichiIto/20111102/1320253815
A = ord('A')
N = ord('Z') - A + 1
def to_n(expr):
return reduce(lambda n, c: n * N + ord(c) - A + 1, expr, 0)
def to_aa(n):
@kosugi
kosugi / gist:2785478
Created May 25, 2012 02:53
mark current viewing position on YouTube
javascript:(function(x,d,t,n){try{t=yt.config_.PLAYER_REFERENCE.getCurrentTime()|0;for(n=0;n<3;++n){d=Math.pow(60,2-n);x[n*2]=(t/d)|0;t=t%d;}location.href=location.href.replace(/#.*/,'')+'#t='+x.join('');}catch(e){}})([0,'h',0,'m',0,'s'])
def deal(n, xs):
ys = [''] * n
for i in range(len(xs) // n * n):
ys[i % n] += xs[i]
return ys
assert deal(3, '123123123') == ['111', '222', '333']
assert deal(3, '123123123') == ['111', '222', '333']
assert deal(4, '123123123') == ['12', '23', '31', '12']
assert deal(6, '012345012345012345') == ['000', '111', '222', '333', '444', '555']
(use srfi-1)
(define (deal n s)
(let* ((size-s (string-size s))
(max-xs (- size-s (remainder size-s n)))
(xs (take (string->list s) max-xs))
(ys (make-vector n '())))
(let loop ((m 0) (xs xs))
(if (null? xs)
(map (lambda (xs) (list->string (reverse xs))) (vector->list ys))
(begin