Skip to content

Instantly share code, notes, and snippets.

View taichino's full-sized avatar

Matsumoto Taichi taichino

View GitHub Profile
@taichino
taichino / pg_trgm_patch.diff
Created September 21, 2012 15:21
pg_trgm patch for support non alphanumeric characters in index
--- contrib/pg_trgm/trgm.h 2012-09-06 17:26:17.000000000 -0400
+++ contrib/pg_trgm/trgm.h 2012-09-21 03:53:47.000000000 -0400
@@ -13,5 +13,5 @@
#define LPADDING 2
#define RPADDING 1
-#define KEEPONLYALNUM
+//#define KEEPONLYALNUM
/*
* Caution: IGNORECASE macro means that trigrams are case-insensitive.
@taichino
taichino / gist:4562132
Last active December 11, 2015 06:49
amazonのフォームテスト
<html>
<head>
<title>amazon フォームテスト</title>
</head>
<body>
<form method="GET" action="http://www.amazon.co.jp/gp/aws/cart/add.html">
<input type="hidden" name="AWSAccessKeyId" value="1JRXNW71YEBAQ25GRA82" /><br/>
<input type="hidden" name="AssociateTag" value="taichino-22" /><br/>
<p>One Product<br/>
ASIN:<input type="text" name="ASIN.1" value="B009MDR3GA"/><br/>
<source>
type tail
format /^\[(?<meta>[^\]]*)\] (?<host>[^ ]*) \(\) {[^}]*} \[(?<time>[^\]]*)\] (?<method>\S+) (?<path>[^ ]+) => generated (?<bytes>[^ ]*) bytes in (?<response_time>[^ ]*) msecs \(HTTP\/1.1 (?<code>[^ ]*)\) .*$/
time_format %a %b %d %H:%M:%S %Y
path /home/bargainnet/site/logs/uwsgi.log
tag bargainnet.uwsgi
</source>
<match bargainnet.uwsgi>
type copy
@taichino
taichino / gist:4757429
Created February 11, 2013 20:42
This is django management commando to reload runserver automatically when .po files are modified.
# -*- coding: utf-8 -*-
import os
import time
from datetime import datetime
from django.core.management.base import BaseCommand, CommandError
from django.core.management.commands.compilemessages import compile_messages
from django.conf import settings
@taichino
taichino / gist:5247730
Created March 26, 2013 18:11
グラデーション生成の実験。RGB => HSVに変換してから、SとVをいじってグラデーションを作ってみた。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PySide import QtCore, QtGui
def rgb2hsv(R, G, B):
V_min = min(R, G, B)
V_max = max(R, G, B)

Problem

How to retrieve user data near by specific geo point efficiently?

My Approach

I'm assuming 1.7M rows of User and all users are in United States. I tested following approarch with MySQL 5.5 on my MBP.

class User(models.Model):
    name = models.TextField()
    lat = models.DecimalField(max_digits=9, decimal_places=6, default=0)

lon = models.DecimalField(max_digits=9, decimal_places=6, default=0)``

@taichino
taichino / gist:5594709
Last active December 17, 2015 10:28
bus ticket
# -*- coding: utf-8 -*-
import sys
import select
def to_base(num, base):
if num == 0:
return "0"
2013-10-04 15:36:08.874 a.out[2807:707] Person1
2013-10-04 15:36:08.876 a.out[2807:707] &name = self + 16
2013-10-04 15:36:08.877 a.out[2807:707] &age = self + 24
2013-10-04 15:36:08.877 a.out[2807:707] &married = self + 8
2013-10-04 15:36:08.878 a.out[2807:707] &sex = self + 9
2013-10-04 15:36:08.878 a.out[2807:707] &height = self + 32
2013-10-04 15:36:08.878 a.out[2807:707]
2013-10-04 15:36:08.879 a.out[2807:707] Person2
2013-10-04 15:36:08.879 a.out[2807:707] &name self + 24
2013-10-04 15:36:08.880 a.out[2807:707] &age self + 32
#import <Foundation/Foundation.h>
@interface A : NSObject
- (void)say;
@end
@taichino
taichino / gist:8778099
Created February 3, 2014 02:34
[self.obj description] doesn't guarantee obj's life even before calling description
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic, strong) NSObject *obj;
@end
@implementation ViewController
- (void)foo {
NSLog(@"foo");