Skip to content

Instantly share code, notes, and snippets.

@hideshi
hideshi / show_process_id.py
Created December 8, 2013 13:44
You can get process id with keyword.
from subprocess import *
import sys, re
keyword = sys.argv[1]
(stdo, stde) = Popen(['ps'], stdout=PIPE).communicate()
lines = [j for i,j in enumerate(stdo.decode().split('\n')) if i > 0]
r = re.compile(r'\s+')
print('keyword', keyword)
for line in lines:
l = r.split(line.strip())
if len(l) > 1 and l[3].find(keyword) >= 0:
@hideshi
hideshi / jobnet.xml
Created December 24, 2013 15:35
Simple job scheduler with Apache Ant.
<?xml version="1.0" ?>
<project default="main" basedir="/path/to">
<target name="main" depends="begin, A0001, B0001, C0001, end">
</target>
<target name="begin">
<echo>
Begin execute jobnet.
</echo>
</target>
@hideshi
hideshi / doctest_sample.py
Last active January 1, 2016 10:49
Python standard library Doctest sample.
def three_times(num):
"""
>>> three_times(-1)
-3
>>> three_times(0)
0
>>> three_times(1)
3
>>> three_times(3)
9
@hideshi
hideshi / csv_parser.py
Created December 28, 2013 02:33
Parse CSV file.
with open("file.csv", "r") as f:
for line in f.readlines():
for col in line.strip().split(","):
print(col.split(":"))
@hideshi
hideshi / bottle_test_drive.py
Last active January 1, 2016 14:09
This test drive is made by Bottle which is the light weight web application framework for Python.
from bottle import view, route, get, post, request, redirect, template, run
@route('/')
@view('index')
def index():
return dict()
@route('/hello/<name>')
def index(name='World'):
return template('Hello {{name}}!', name=name)
@hideshi
hideshi / .vimrc
Last active January 1, 2016 14:29
My .vimrc
"This sets plugins directory.
set runtimepath+=~/.vim/vimdoc-ja
"This sets default help languages.
set helplang=ja,en
"This enables you to use syntax highlight.
syntax on
"This enables you to use pliugins.
@hideshi
hideshi / sqlite3.awk
Created December 28, 2013 11:43
How to use SQLite3 in Awk.
#!/usr/bin/awk -f
BEGIN {
db = "test.db"
command = "sqlite3 -noheader -separator \" \" " db " \" %s \""
create_table = "create table employee (id, name, age)"
insert1 = "insert into employee values (1, 'taro', 20)"
insert2 = "insert into employee values (2, 'hanako', 18)"
insert3 = "insert into employee values (3, 'ichiro', 26)"
select = "select * from employee order by age"
drop_table = "drop table employee"
@hideshi
hideshi / strip.py
Created December 29, 2013 07:32
Read from file and strip each lines and write to file.
import sys
if __name__ == '__main__':
with open(sys.argv[1]) as infile:
with open(sys.argv[2], 'w') as outfile:
for line in infile.readlines():
outfile.write(line.lstrip())
@hideshi
hideshi / g.scala
Created December 29, 2013 07:47
This is the Scala oneliner library. This make you feel easy when you code oneliner on the command line. See also: http://d.hatena.ne.jp/hideshi_o/20120501/1335886709
import scala.sys.process._
import scala.io.Source._
def in:List[String] = scala.io.Source.stdin.getLines.toList
implicit def pathToFileReader(path:String) = new FileReader(path)
class FileReader(path:String) {
def getLines():List[String] = {
try {
sealed abstract class AVLTree[A <% Ordered[A]] {
def +(v:A):AVLTree[A]
def -(v:A):AVLTree[A]
def reconstruct:AVLTree[A]
def depth:Int
def contains(v:A):Boolean
def size:Int
def isEmpty:Boolean
def nonEmpty:Boolean
def toList:List[A]