Skip to content

Instantly share code, notes, and snippets.

View hhatto's full-sized avatar
⛰️
enjoy

Hideo Hattori hhatto

⛰️
enjoy
View GitHub Profile
@hhatto
hhatto / grin_rev80_force-word-match.patch
Created September 18, 2010 08:17
patch of grin force word regex match
Index: grin.py
===================================================================
--- grin.py (revision 80)
+++ grin.py (working copy)
@@ -762,6 +762,8 @@
help="show program's version number and exit")
parser.add_argument('-i', '--ignore-case', action='append_const',
dest='re_flags', const=re.I, default=[], help="ignore case in the regex")
+ parser.add_argument('-w', '--word-regexp', action='store_true', default=False,
+ dest='is_matchword', help="force regex to match only whole words")
@hhatto
hhatto / gist:888295
Created March 26, 2011 13:56
pgmagick image diff
from pgmagick import Image
from pgmagick import CompositeOperator as co
img_a = Image('a.jpg')
img_b = Image('b.jpg')
img_c = Image('c.jpg')
print img_a.compare(img_b)
print img_a.compare(img_c)
@hhatto
hhatto / gist:888447
Created March 26, 2011 17:07
fast scale with pgmagick (jpeg only)
import pgmagick
import time
# fast read
b = time.time()
img = pgmagick.Image(pgmagick.Blob(open('org.jpg').read()), pgmagick.Geometry(180, 120))
img.scale('180x120')
img.write('t.jpg')
print time.time() - b
@hhatto
hhatto / gist:919441
Created April 14, 2011 13:07
image file base64 encode
import sys
from base64 import encodestring
with open(sys.argv[1]) as f: # argv[1] is 'xx.png'
print encodestring(f.read())
@hhatto
hhatto / gist:1704380
Created January 30, 2012 13:26
groongaql example
from groongaql import Context, ENC_DEFAULT, SUCCESS
"""groongaql test scrip
1. groonga -s
2. python script.py
"""
def main():
ctx = Context(flags=0, encoding=ENC_DEFAULT)
#include <stdio.h>
#include <string.h>
#include "groonga.h"
static void execute_gql(grn_ctx *ctx, char *gql, int len)
{
unsigned int result_size;
char *result = NULL;
@hhatto
hhatto / faketail.py
Created June 2, 2012 15:55
tail -f when multi file
import sys
import os
import time
MAX_INTERVAL = 1.0
class Poller:
def __init__(self, files):
@hhatto
hhatto / gist:4162611
Created November 28, 2012 17:13
print raw sql for peewee
from peewee import *
from models import News, database
compiler = database.get_compiler()
print(News.select().where(News.url == 'test').sql(compiler))
@hhatto
hhatto / gist:5020052
Created February 23, 2013 14:58
occur error install pulsar via easy_install
$ easy_install -ZU pulsar
Searching for pulsar
Reading http://pypi.python.org/simple/pulsar/
Reading https://github.com/quantmind/pulsar
Best match: pulsar 0.4.6
Downloading http://pypi.python.org/packages/source/p/pulsar/pulsar-0.4.6.tar.gz#md5=9425e2110a6d2b0a6216121d52b12fc2
Processing pulsar-0.4.6.tar.gz
Running pulsar-0.4.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-4qNzrr/pulsar-0.4.6/egg-dist-tmp-oozueS
warning: no files found matching '*.py' under directory 'lib'
warning: no files found matching '*.h' under directory 'lib'
import folium
# osaka
osaka_location = [34.702, 135.4951]
mapobj = folium.Map(location=osaka_location,
zoom_start=15)
mapobj.simple_marker(osaka_location, popup='Osaka Station')
mapobj.circle_marker(osaka_location, popup='An on foot 5-minute within the circle',
radius=500, fill_color='#33cccc')
mapobj.create_map(path='osm.html')