Skip to content

Instantly share code, notes, and snippets.

View hideshi's full-sized avatar

Hideshi Ogoshi hideshi

View GitHub Profile
@hideshi
hideshi / mapdb.clj
Created December 29, 2013 08:10
This is hash map database written in Clojure. See also: http://d.hatena.ne.jp/hideshi_o/20121123/1353698397
;mapdb.clj
(ns db.mapdb
(:use
[clojure.contrib.duck-streams :only (reader)]
[clojure.java.io :only (writer)]
[clojure.string :only (split)]
[clojure.contrib.server-socket :only (create-server close-server)]))
(def database-file "/Users/hideshi/Dev/Clojure/db/dbfile")
@hideshi
hideshi / sigmetparser.scala
Created December 29, 2013 07:59
This is a parser for SIGMET which is a format for weather information. See also: http://d.hatena.ne.jp/hideshi_o/20130105/1357367954
abstract sealed class Bulletin
case class SigmetBulletin (
header:Header
,firstLine:FirstLine
,mainBody:MainBody
) extends Bulletin
case class Header(
identificationMessage:String = ""
@hideshi
hideshi / metarparser.scala
Created December 29, 2013 07:57
This is a parser for METAR which is a format for weather information. See also: http://d.hatena.ne.jp/hideshi_o/20130105/1357376552
import scala.util.parsing.combinator.RegexParsers
abstract class Bulletin
case class MetarBulletin (
icao:String
,datetime:String
,windDirection:String
,windSpeed:String
,windShift:String
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]
@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 {
@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 / 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 / .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 / 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 / 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(":"))