Skip to content

Instantly share code, notes, and snippets.

View lambdalisue's full-sized avatar
🎮

Λlisue (Ali sue・ありすえ) lambdalisue

🎮
View GitHub Profile
@lambdalisue
lambdalisue / singleton.py
Created May 16, 2011 05:40
Singleton Mixin Class of Python
#!/usr/bin/env python
# vim: set fileencoding=utf8 :
"""Singleton Mixin"""
class Singleton(object):
"""Singleton Mixin Class
Inherit this class and make the subclass Singleton.
Usage:
@lambdalisue
lambdalisue / attrdict.py
Created May 16, 2011 08:02
Attribute accessable dictionary for Python
class Attrdict(dict):
"""Attribute accessible dictionary class
Usage:
>>> attrdict = Attrdict(alice='in the wonderland')
>>> attrdict.alice
'in the wonderland'
>>> attrdict['hello'] = 'world'
>>> attrdict['hello']
'world'
@lambdalisue
lambdalisue / gist:1145772
Last active September 26, 2015 19:17
Get absolute execution directory path in Sh
#!/bin/sh
# --- long way
ROOT=`dirname $0`
ROOT=`cd $ROOT;pwd`
# --- short way
ROOT=$(cd $(dirname $0);pwd)
# --- with readlink
SELF=$(readlink -f $0)
Array::fold = (f, init)->
c = init
for e in this
c = f(e, c)
c
if Array::reduce is undefined
Array::reduce = (f) -> @[1..].fold(f, @[0])
sum = (a)->
toDegree = (rad) ->
# Convert radian to degree
rad * 180 / Math.PI
toRadian = (deg) ->
# Convert degree to radian
deg * Math.PI / 180
@lambdalisue
lambdalisue / collision_sector_vs_point.coffee
Created August 29, 2011 04:19
Collision detection of Circular sector vs Point written in CoffeeScript
#!coffee
#
# required
# - vector.coffee - gist: 1177722
#
vector = require './vector'
isCollided = (sector, point) ->
# Collision detection of circular sector and point
toRadian = (d) -> d * Math.PI / 180
@lambdalisue
lambdalisue / flatten.coffee
Created August 30, 2011 06:28
flatten (convert multidimensional array to one dimensinal array) function written in CoffeeScript
#!coffee
#
# Convert multidimensional array to one dimensional array.
# Return an empty list when passed array is an empty list.
#
# Usage::
#
# assert = require 'assert'
# matrix = [
@lambdalisue
lambdalisue / .xprofile
Created September 4, 2011 08:51
xprofile
# iBUS
#export XMODIFIERS="@im=ibus"
#export GTK_IM_MODULE="ibus"
#export QT_IM_MODULE="xim"
#ibus-daemon -d -x
# uim
export XMODIFIERS="@im=uim"
export GTK_IM_MODULE="uim"
export QT_IM_MODULE="uim"
@lambdalisue
lambdalisue / buildenv.sh
Last active January 25, 2016 14:16
Build python develop environment via pythonbrew
#!/bin/bash
PLATFORM=`uname`
PYTHON_VERSION=2.7.2
if [ "$PLATFORM" = 'Linux' ]; then
echo "Installing required packages..."
yes | sudo apt-get install curl python-all-dev python3-all-dev
yes | sudo apt-get install libreadline6-dev libsqlite3-dev libgdbm-dev
yes | sudo apt-get install libbz2-dev build-essential libxml2-dev libxslt1-dev
# Patch for PIL
@lambdalisue
lambdalisue / vbforward.sh
Created September 18, 2011 13:16
VirtualBox SSH Connection
#!/bin/bash
echo "Please input your virtual machine name"
read NAME
SSH=2222
HTTP=8080
# SSH
VBoxManage setextradata "$NAME" "VBoxInternal/Devices/e1000/0/LUN#0/Config/guestssh/Protocol" TCP
VBoxManage setextradata "$NAME" "VBoxInternal/Devices/e1000/0/LUN#0/Config/guestssh/GuestPort" 22
VBoxManage setextradata "$NAME" "VBoxInternal/Devices/e1000/0/LUN#0/Config/guestssh/HostPort" $SSH