Skip to content

Instantly share code, notes, and snippets.

View utahta's full-sized avatar

Yuta UEKUSA utahta

  • Merpay, Inc.
  • Tokyo, Japan
View GitHub Profile
@utahta
utahta / vbcode.py
Created December 14, 2010 15:55
Variable Byte Code
#!/usr/bin/env python
from struct import pack, unpack
def vb_encode(numbers):
if isinstance(numbers, int):
numbers = [numbers]
bytestream = ''
for n in numbers:
bytes = []
while True:
@utahta
utahta / vb.py
Created December 19, 2010 16:55
Variable Byte Code
#!/usr/bin/env python
from struct import pack, unpack
def vb_encode(number):
bytes = []
while True:
bytes.insert(0, number % 128)
if number < 128:
break
number /= 128
@utahta
utahta / chap6_vbencode.py
Created December 19, 2010 16:57
huge data book chapter 6. vb encode.
#!/usr/bin/env python
import sys
from struct import pack
from vb import vb_encode
if len(sys.argv) < 2:
print "usage: %s in.txt > out.txt" % sys.argv[0]
sys.exit(1)
fp = open(sys.argv[1], 'r')
@utahta
utahta / chap6_vbdecode.py
Created December 19, 2010 17:11
huge data book chapter 6. vb decode.
#!/usr/bin/env python
import sys
from struct import unpack
from vb import vb_decode
if len(sys.argv) < 2:
print "usage: %s in.txt > out.txt" % sys.argv[0]
sys.exit(1)
fp = open(sys.argv[1], 'rb')
@utahta
utahta / hoge.cpp
Created January 21, 2011 02:57
aaa
#include <stdio.h>
int main()
{
return 0;
}
@utahta
utahta / hugedatabook-chap8.py
Created May 8, 2011 19:06
huge data book chapter 8 AhoCorasick
# vim:fileencoding=utf8
from pyahocorasick import AhoCorasick
terms = []
fp = open('keyword.utf8.uniq.txt', 'rb')
for line in fp:
terms.append(line.strip().decode('utf8'))
fp.close()
ac = AhoCorasick(terms)
@utahta
utahta / amzn-sample.py
Created June 8, 2011 15:21
sample: amazon product advertising api
# coding=utf8
import bottlenose
from lxml import objectify
amazon = bottlenose.Amazon(access_key_id, secret_access_key, Region='JP')
res = amazon.ItemSearch(Keywords=u'東野圭吾', SearchIndex='Books', ItemPage='1', ResponseGroup='Small')
root = objectify.fromstring(res)
for item in root.Items.Item:
print unicode(item.ItemAttributes.Title)
@utahta
utahta / kaijou.c
Created December 13, 2011 09:15
階乗計算1
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
typedef struct mulnum_t{
int32_t fig; // 桁
char *data; // 整数データ
int32_t size; // 確保したメモリのサイズ
}mulnum;
@utahta
utahta / gyakuhibu3gatu.rb
Created March 25, 2012 06:38
3月末優待逆日歩
# coding:utf-8
require 'rubygems'
require 'jpstock'
# 逆日歩最高料率の計算
def max_gyakuhibu(price, lot)
m = price * lot
g = (m / 50000.0).ceil * 100
g = g / lot.to_f
if g <= 1
@utahta
utahta / IncomeResult.vb
Last active October 5, 2015 14:17
岡三RSSで当日の損益を計算するプログラム
' 銘柄コードと銘柄名
Public ccode As Integer
Public name As String
' 損益
Public income As Long
' 信用新規買, 返済売
Public buy_price As Double
Public buy_amount As Long