Skip to content

Instantly share code, notes, and snippets.

@yanolab
yanolab / .bashrc
Created July 23, 2012 09:34
display branch name and commit status of git repository
# http://lukasrieder.com/2009/07/14/extend-your-bash-ps1.html
function parse_git_dirty_and_branch() {
branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
[[ $branch != '' ]] && echo "($(parse_git_dirty)$branch)"
}
# set a fancy prompt (non-color, unless we know we "want" color)
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
@yanolab
yanolab / countdown.py
Created September 4, 2012 06:13
connpassからpyconjpの定員を取得して残数をツイートするスクリプト
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import re
import os
import sys
import lxml.html
import twitter
api = twitter.Api(
@yanolab
yanolab / codeiq-answer_in_pyconp2012.py
Created September 15, 2012 08:04
pyconjpで出題されたcodeiqの問題を解いてみた。
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import lxml.html
from collections import Counter
doc = lxml.html.parse(open("cache.html"))
users = [x.text.upper() for x in doc.xpath("//div[@class='side_sec_box side_article_area']/div/p[@class='user']/a")[:400]]
print "".join(map(lambda x: x[0], Counter("".join(users)).most_common(5)))
@yanolab
yanolab / cal.rb
Created December 7, 2012 12:38
print this month calendar
#! /usr/bin/env ruby
# -*- coding: utf-8 -*-
# This program works with both 1.8.7 and 1.9.3
#
# usage:
# ruby cal.rb [month] [year]
# month and year are optional
require "date"
@yanolab
yanolab / mutistarmap.py
Last active December 10, 2015 13:19
compatible with over python2.6
#! -*- coding: utf-8 -*-
from multiprocessing import Pool
class Worker(object):
def __init__(self, func, *args):
self.func = func
self.args = args
def __call__(self, *args, **kw):
#! /usr/bin/env python
import cmd
class MyShell(cmd.Cmd):
def precmd(self, line):
lines = line.split(';')
self.cmdqueue.extend(lines[1:])
return lines[0]
@yanolab
yanolab / gohttp.go
Last active December 24, 2015 21:29
Simple GO static web contents server.
package main
import (
"errors"
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
package main
import (
"fmt"
"sync"
)
var workerSize = 4
type Fetcher interface {
@yanolab
yanolab / coins.py
Created May 2, 2014 22:04
coins.py
# -*- coding: utf-8 -*-
def product(v, coins=[500, 100, 50, 10, 5, 1], used=[]):
if len(coins) == 1:
yield 1
else:
for i, coin in enumerate(coins):
diff = v - coin
if diff == 0:
yield 1
@yanolab
yanolab / .conkyrc
Last active August 29, 2015 14:05
My conkyrc file for dynabook KIRA
# .conkyrc
alignment bottom_left
gap_x 0
gap_y 0
background no
use_xft yes
xftfont Bitstream Vera Sans Mono:size=10:Bold