Skip to content

Instantly share code, notes, and snippets.

@shun115
shun115 / gist:749581
Created December 21, 2010 06:36
Pythonの特殊メソッド
>>> class Test(object):
... a = ''
... def __new__(clazz, a): #インスタンス生成
... print 'new'
... #__new__はインスタンスではなくクラスを引数に取る(インスタンス生成前だから)
... #この__new__が呼び出されたコンテキスト内(clazz)で、Testクラスのスーパークラス呼び出し
... return super(Test, clazz).__new__(clazz) #object.__new__(clazz)と同義
... def __init__(self, a): #インスタンス生成後のコンストラクタ
... self.a = a
... print 'init'
@shun115
shun115 / gist:789529
Created January 21, 2011 10:51
Python : pythonbrew + virtualenv 環境の構築
$ curl -kLO https://github.com/utahta/pythonbrew/raw/master/pythonbrew-install
$ chmod +x pythonbrew-install
$ ./pythonbrew-install
$ echo "source ~/.pythonbrew/etc/bashrc" >> .bashrc
$ source .bashrc
$ pythonbrew install -f 2.6.6 # なぜかtest_ioctlでこけたためforce
$ pythonbrew install -f 2.7.2 # 同上
$ pythonbrew install -f 3.2.2 # 同上
@shun115
shun115 / gist:794564
Created January 25, 2011 05:44
Ruby rvm 環境の構築
$ curl -kLO http://rvm.beginrescueend.com/releases/rvm-install-latest
$ chmod +x rvm-install-latest
$ ./rvm-install-latest
$ echo "[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"" >> .bashrc
$ rvm install 1.8.7
$ rvm install 1.9.2
@shun115
shun115 / gist:830842
Created February 17, 2011 02:40
C# LastIndexの不思議な挙動
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
namespace TestCodes
{
[TestFixture]
public class LastIndexTest
{
@shun115
shun115 / gist:860132
Created March 8, 2011 10:39
PythonでImageからSHA1 Hashを取得
$ wget http://k.yimg.jp/images/top/sp/logo.gif
--2011-03-08 19:34:32-- http://k.yimg.jp/images/top/sp/logo.gif
k.yimg.jp をDNSに問いあわせています... 202.93.65.122
k.yimg.jp|202.93.65.122|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 2077 (2.0K) [image/gif]
`logo.gif' に保存中
100%[====================================================================================================================================================================>] 2,077 --.-K/s 時間 0s
@shun115
shun115 / gist:964069
Created May 10, 2011 08:01
emacs 23 用の.emacs
;; .emacs
;; enable visual feedback on selections
(setq transient-mark-mode t)
;; default to better frame titles
(setq frame-title-format
(concat "%b - emacs@" (system-name)))
;; default to unified diffs
@shun115
shun115 / webtail.py
Created February 15, 2012 09:49 — forked from maximebf/webtail.py
Web tail / tail -f as a webpage using websocket
#!/usr/bin/python
# Equivalent of "tail -f" as a webpage using websocket
# Usage: webtail.py PORT FILENAME
# Tested with tornado 2.1
# Thanks to Thomas Pelletier for it's great introduction to tornado+websocket
# http://thomas.pelletier.im/2010/08/websocket-tornado-redis/
import tornado.httpserver
@shun115
shun115 / gist:2026632
Created March 13, 2012 03:54
Ubuntuではじめにインストールするパッケージ群
$ sudo apt-get install zsh zsh-dev
$ sudo apt-get install curl
$ sudo apt-get install make
$ sudo apt-get install gcc
$ sudo apt-get install g++
$ sudo apt-get install emacs
$ sudo apt-get install emacs-goodies-el
$ sudo apt-get install git
$ sudo apt-get install subversion
$ sudo apt-get install zlib1g
@shun115
shun115 / gist:2717001
Created May 17, 2012 06:32
CentOS minimalでのOracle Virtualbox VMセットアップ(Chef)
## CentOS-6.2-x86_64-minimal.iso完了後
# shutdown -h now
## ネットワーク設定はeth0をNATに、eth1をホストオンリーアダプタにする
# cd /etc/sysconfig/network-scripts/
# vi ifcfg-eth0
DEVICE="eth0"
BOOTPROTO=dhcp
HWADDR="00:00:00:00:00:00"
NM_CONTROLLED="yes"
ONBOOT="yes"
@shun115
shun115 / gist:5418736
Last active December 16, 2015 10:18
openframeworks でできたプログラムを、X Window System無し(Headless)に Ubuntu 12.10 にて動作させるための環境づくり。 Headless X として xvfb with GLX extension (Mesa 9.0.3) 使用。 サーバはEC2 使用。
### install Mesa
$ cd
$ mkdir lib
$ cd lib/
$ wget ftp://ftp.freedesktop.org/pub/mesa/9.0.3/MesaLib-9.0.3.tar.gz
$ tar xvzf MesaLib-9.0.3.tar.gz
$ cd Mesa-9.0.3/
$ sudo apt-get update
$ sudo apt-get install gcc g++ make autoconf wdiff libtool bison flex libxml2 python-libxml2 xutils-dev pkg-config libx11-dev libxext-dev libx11-xcb-dev libxcb-dri2-0-dev libxcb-xfixes0-dev libdrm-dev llvm-dev
$ ./configure --enable-xlib-glx --disable-dri