Skip to content

Instantly share code, notes, and snippets.

class GemBox
attr_accessor :filPattern
def initialize(boxSize, gemPattern, targetPattern)
@boxSize = boxSize
@gemPattern = gemPattern
@filPattern = Hash.new
@targetPattern = targetPattern
@dayNum = 0
end
class SegmentPatternSearch
attr_accessor :patternCache
def initialize()
@segPattern = Array.new(10)
@segPattern[0] = '1111110'
@segPattern[1] = '0110000'
@segPattern[2] = '1101101'
@segPattern[3] = '1111001'
@segPattern[4] = '0110011'
@e-mon
e-mon / gist:11051260
Last active August 29, 2015 14:00
proxy servrer(response image converted base64 encoding)
app.get('/proxy', function(req,res){
var url, proxyReq, proxyRequest;
if (req.param('url')) {
url = require('url').parse(req.param('url'));
options = {
host: url.hostname,
port: '80',
path: url.pathname,
method: 'GET'
@e-mon
e-mon / gist:72dd8f636459aa230e68
Created October 13, 2014 05:58
matplotでfigureを'q'で閉じるためのワンライナー(暫定版)
from pylab import *
gcf().canvas.mpl_connect('key_press_event', lambda event: event.key == 'q' and close(event.canvas.figure))
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use Digest::MD5 qw(md5_hex);
use File::Slurp;
use utf8;
my @fileList = <STDIN>;
shift @fileList;
@e-mon
e-mon / Dijkstra.py
Last active August 29, 2015 14:11
dijkstra
from heapq import heappush, heappop
def dijkstra(adjList,s):
num = len(adjList)
dist = [10**8 for i in range(num)]
prev = [-1 for i in range(num)]
queue = []
heappush(queue,(0,s))
dist[s] = 0
while len(queue) != 0:
@e-mon
e-mon / wn3.1.py
Created April 24, 2015 03:15
WordNet in NLTK version up from 3.0 to 3.1
import os
nltkdata_wn = '/path/to/nltk_data/corpora/wordnet/'
wn31 = "http://wordnetcode.princeton.edu/wn3.1.dict.tar.gz"
if not os.path.exists(nltkdata_wn+'wn3.0'):
os.mkdir(nltkdata_wn+'wn3.0')
os.system('mv '+nltkdata_wn+"* "+nltkdata_wn+"wn3.0/")
if not os.path.exists('wn3.1.dict.tar.gz'):
os.system('wget '+wn31)
os.system("tar zxf wn3.1.dict.tar.gz -C "+nltkdata_wn)
struct edge{
int to;
int cost;
bool operator>(const edge &e)const{
return cost > e.cost;
}
bool operator<(const edge &e)const{
return cost < e.cost;
# st = SegmentTree(n, lambda a,b: a if a > b else b)
class SegmentTree:
def __init__(self,n,f):
self.N = 1
self.f = f
while(self.N < n):
self.N *= 2
self.seg = [0] * (self.N * 2 -1)
def update(self,k,a):
struct rootedtree{
int V;
vector<vector<int> > T;
vector<vector<int> > parents;
vector<int> depth;
int log_N = 20;
rootedtree(int N, vector<vector<int> > &Tree){
V = N;
T = Tree;