Skip to content

Instantly share code, notes, and snippets.

View zs1621's full-sized avatar
💭
I may be slow to respond.

zs1621

💭
I may be slow to respond.
View GitHub Profile
@zs1621
zs1621 / create_index1.mysql
Created January 14, 2014 06:50
创建实验index1表-mysql地理搜索
CREATE TABLE `index1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`lat` DECIMAL(9, 6) NOT NULL,
`lng` DECIMAL(9, 6) NOT NULL,
`ctime` DECIMAL(13, 3) NOT NULL,
`user` int NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
desc `index1`;# check the table index1 u create
@zs1621
zs1621 / comprise_index.mysql
Last active January 3, 2016 05:09
mysql地理位置搜索 比较 给lat-lng加B-tree索引和不加索引
use test;
set @er=6366.564864;
set @lat=56.14262;
set @lng=32.605853;
set @dist=20;
#1.
SELECT id,lat,lng,@er*2*ASIN(SQRT(POWER(SIN((@lat - lat)*pi()/180 / 2), 2) + COS(@lat * pi()/180) * COS(lat * pi()/180) * POWER(SIN((@lng - lng) * pi()/180 / 2), 2) )) as dist FROM `unindex1` HAVING dist < @dist ORDER BY dist;
#
#2.
@zs1621
zs1621 / mysql_geographic_coordinates_search.mysql
Created January 14, 2014 06:28
按照地理坐标搜索附近100km的人 1. 确定范围, 且找到附近100km的人 2. 确定范围,且找到附近100km最后checkin的人的数据 3. 不确定范围搜索附近的人
use test
set @er=6366.564864;
set @lat=-80.655719;#set the latitude where to find
set @lng=91.099119;
set @dist=100; #100km set the range 0-100km
set @lat_length=20003.93/180;#lat length
set @lat_left=@lat-(@dist/@lat_length);
set @lat_right=@lat+(@dist/@lat_length);
set @lng_left=@lng-@dist/abs(cos(radians(@lat))*@lat_length);
set @lng_right=@lng+@dist/abs(cos(radians(@lat))*@lat_length);
@zs1621
zs1621 / create_lat_lng.py
Created January 14, 2014 06:13
script create 200million lat-lng data to test
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#
# Author : Rhapsodyzs
# E-mail : zs1213yh@gmail.com
# Date : 14/01/08 11:01:17
# Desc :
#
import MySQLdb
import random
#!/bin/env python
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
import tornado.httpclient
import tornado.gen
from tornado.concurrent import run_on_executor
#if < python3.2 you need do `sudo pip install futures`
import unittest, os, os.path, sys, urllib
import tornado.database
import tornado.options
from tornado.options import options
from tornado.testing import AsyncHTTPTestCase
# add application root to sys.path
APP_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(os.path.join(APP_ROOT, '..'))
@zs1621
zs1621 / node_mongodb_pool.js
Created December 7, 2013 02:26
test node-pool module
var http = require('http');
var mongodb = require('mongodb');
var poolModule = require('generic-pool');
var pool = poolModule.Pool({
name: 'mongodb',
create: function(callback) {
mongodb.MongoClient.connect('mongodb://localhost/test', {server: {poolSize: 1}}, function(err, db) {
callback(err, db);
});
@zs1621
zs1621 / reident
Created November 12, 2013 07:46
reindent the python from spaces tab 8 to spaces tab 4
#! /usr/bin/env python
# Released to the public domain, by Tim Peters, 03 October 2000.
"""reindent [-d][-r][-v] [ path ... ]
-d (--dryrun) Dry run. Analyze, but don't make any changes to, files.
-r (--recurse) Recurse. Search for all .py files in subdirectories too.
-n (--nobackup) No backup. Does not make a ".bak" file before reindenting.
-v (--verbose) Verbose. Print informative msgs; else no output.
@zs1621
zs1621 / reset_myql_root_secret
Created October 15, 2013 06:18
重置mysql root 密码
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
# Check if user is root
if [ $(id -u) != "0" ]; then
printf "Error: You must be root to run this script!\n"
exit 1
fi
@zs1621
zs1621 / gist:6291586
Last active December 21, 2015 10:19
why the check_palin() function return 'None', not True or False
def check_palin(lister):
if len(lister) <= 1 :
print 'True'
return True
else:
if lister[0] == lister[-1]:
lister.pop()
del lister[0]
check_palin(lister)
else: