Skip to content

Instantly share code, notes, and snippets.

@laclefyoshi
laclefyoshi / gist:856860
Created March 6, 2011 00:24
copy the source of active tab in Google Chrome
tell application "Google Chrome"
view source of active tab of window 1
repeat while loading of active tab of window 1
delay 0.1
end repeat
select all of active tab of window 1
copy selection of active tab of window 1
delete tab (active tab index of window 1) of window 1
end tell
@laclefyoshi
laclefyoshi / calc555.bc
Created March 19, 2011 04:00
bc script for calculating 555 timer
define af(r1, r2, c) {
auto defscale, t1, t2, total, freq, duty;
defscale = scale;
scale = 6;
t1 = l(2) * (r1 + r2) * c;
t2 = l(2) * r2 * c;
total = t1 + t2;
freq = 1 / total;
duty = t1 / total;
@laclefyoshi
laclefyoshi / erc.py
Created March 19, 2011 09:07
東京大学環境放射線情報 最新暫定値取得
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright : (c) SAEKI Yoshiyasu
# License : MIT-style license
# <http://www.opensource.org/licenses/mit-license.php>
# last updated: 2011/03/19
import lxml.html
root = lxml.html.parse("http://www2.u-tokyo.ac.jp/erc/index.html")
tell application "Google Chrome"
tell window 1
set newTab to make new tab with properties {URL:"https://bitbucket.org/account/signin/"}
repeat while loading of active tab
delay 0.1
end repeat
tell active tab
execute javascript "document.forms[1]['id_username'].value = 'bitbucket_mail@gmail.com'"
execute javascript "document.forms[1]['id_password'].value = 'bitbucket_password'"
execute javascript "document.forms[1].childNodes[8].childNodes[1].click()"
@laclefyoshi
laclefyoshi / gist:922955
Created April 16, 2011 07:37
latex snippet for outputting vertical document
\documentclass[10pt]{tarticle}
% ...
\newcommand{\tsetpagesize}[2]{%
\usepackage[paperwidth=#2, paperheight=#1,%
top=1truemm, bottom=1truemm, left=1truemm, right=1truemm]{geometry}%
\special{papersize=#1,#2}%
}
@laclefyoshi
laclefyoshi / gist:922950
Created April 16, 2011 07:27
latex document for being displayed on iPod touch or Kindle
\documentclass[10pt]{article}
\pagestyle{empty}
\def\kindlewidth{85.09truemm}
\def\kindleheight{111.76truemm}
\def\ipodtouchwidth{49.31truemm}
\def\ipodtouchheight{73.97truemm}
@laclefyoshi
laclefyoshi / gist:938214
Created April 23, 2011 03:09
try Mercurial API
>>> from mercurial import ui, hg
>>> repo = hg.repository(ui=ui.ui(), path='.', create=True)
# create a repository
>>> repo
<mercurial.localrepo.localrepository object at 0x1019581d0>
>>> f = open("foo", "w")
>>> f.write("foofoo")
>>> f.close()
>>> repo.status(unknown=True)
([], [], [], [], ['foo'], [], [])
@laclefyoshi
laclefyoshi / test_rint_round.c
Created April 25, 2011 13:55
compare rint() to round()
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define MAX_NUM 1000
int main() {
double x;
double rint_x, round_x;
@laclefyoshi
laclefyoshi / test_kqueue.c
Created May 7, 2011 06:02
using kqueue for monitoring a file
/**
Copyright: (c) SAEKI Yoshiyasu
License : MIT-style license
<http://www.opensource.org/licenses/mit-license.php>
last updated: 2011/05/07
**/
#include<stdio.h>
#include<stdlib.h>
#include <sys/event.h>
@laclefyoshi
laclefyoshi / test_kqueue.py
Created May 7, 2011 06:04
using select.kqueue for monitoring a file
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright : (c) SAEKI Yoshiyasu
# License : MIT-style license
# <http://www.opensource.org/licenses/mit-license.php>
# last updated: 2011/05/07
import select
# import os