Skip to content

Instantly share code, notes, and snippets.

@tompng
tompng / gist:3719273
Created September 14, 2012 01:32
youtube gen playlist
var sc=document.createElement("script");
sc.src="https://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js";
document.body.appendChild(sc);
document.body.innerHTML="<div id='video'></div>";
url=location.href;
var http=new XMLHttpRequest();
http.open("GET",url,true);
setTimeout(function(){
@tompng
tompng / gist:3728290
Created September 15, 2012 14:44
Dictionary(ja<->en) for Safari #save this html-file to your local disk.
<meta http-equiv="content-type" content="charset=utf-8">
<title>dictionary</title>
<script>
var http;
var lang=["en","ja"];
var url="http://translate.google.co.jp/translate_a/t?client=t";
function $(id){return document.getElementById(id);}
function getText(){
return $("text").value.split("\n").join(" ");
}
@tompng
tompng / QliveExtension.js
Created November 10, 2012 04:23
Qlive extension. run this in developer console.
function sendMessage(msg){
if(!msg)return;
var form=document.getElementById('new_post_modal');
var texts=form.getElementsByTagName('textarea');
var text=texts[texts.length-1];
text.value=msg;
$(form).submit();
text.value='';
}
var div=document.createElement("form");var text=document.createElement("input");div.appendChild(text);
for(s='',x=y=n=40;y+n;s+='-*\n'[x+n?x*x--+y*y<900|0:(x=n,y-=2,2)]);return s
@tompng
tompng / era.rb
Last active December 13, 2015 20:28
Japanese Era Calendar Scheme
#-*- encoding:utf-8 -*-
require 'date'
date=Date.parse ARGV[0]
eras = [
[Date.parse('1989-01-08'), '平成'],
[Date.parse('1926-12-25'), '昭和'],
[Date.parse('1912-07-30'), '大正'],
[Date.parse('1868-09-08'), '明治'],
@tompng
tompng / number.rb
Last active December 14, 2015 04:59
rubyの0.zero?を強くしてみた。 (five-thousand).minusninehundredninetyfive? && (twopointzero*314/onehundred).sixpointtwoeight? => true
class NumberParser
def self.parse(s)
match=->(str){
if s.start_with? str
s=s[str.length..-1]
true
end
}
find=->(arr){
key,value=arr.find{|x|s.start_with? x[0]}
@tompng
tompng / a.js
Created March 13, 2013 14:20
fadein,fadeout
function show(html){
var target=$("#targetID");
var old=target.children();
var next=$("<div>");
next.html(html);
next.css({position:'absolute',left:0,top:0,width:'100%',height:'100%',display:'none',background:'white'})
target.append(next)
next.fadeIn(1000,function(){old.remove()})
}
@tompng
tompng / lisp.rb
Last active December 15, 2015 04:50
lispもどき
require './lisp_base'
LISPRUN [:cdr,[:cons,L(1,2,3),L(4,5,6)]]
LISPRUN [:cdr,D(L(1,2,3,D(4,5)),L(6,7,8))]
LISPRUN [:do,
[:print,[:car,[:cons,3,[:cons,4,5]]]],
[:print,[:+,3,[:+,6,3]]],
[:defun,:dist2,[:a,:b],[:+,[:*,:a,:a],[:*,:b,:b]]],
[:print,[:dist2,3,4]],
[:defun,:fact,[:a],[:ifelse,[:==,:a,0],1,[:*,:a,[:fact,[:-,:a,1]]]]],
@tompng
tompng / lisp2.rb
Last active December 15, 2015 07:19
もうちょっとLispっぽいLispもどき
require './lisp_base.rb'
LISP do (cons 1,2) end
LISP do (cond true,(cond false,(cons 1,2),(cons 3,4)),(cons 5,6)) end
LISP do (defun :fact,:x,(cond (eq :x,0),1,(mult (sqrt (square :x)),(fact (minus :x,1))))) end
LISP do (defun :abs,:x,(cond (lt :x,0),(minus 0,:x),:x)) end
LISP do
(defun :sqrtrec,:x,:y,:d,
(cond (lt :d,0.0000000001),
:y,
(cond (lt (mult :y,:y),:x),
@tompng
tompng / lisp3.rb
Last active December 15, 2015 07:49
Lisp2.rbの続き コードがふくれあがったから別gistにしました。 追記 さらに膨らんだから移動 https://github.com/tompng/rubyhogelisp
require './lisp_base.rb'
require 'tweetstream'
twitter_token={
:CONSUMER_KEY => 'aaa',
:CONSUMER_SECRET => 'bbb',
:OAUTH_TOKEN => 'ccc',
:OAUTH_TOKEN_SECRET => 'ddd'
}
Lisp twitter_token do
(progn\