Skip to content

Instantly share code, notes, and snippets.

View koorukuroo's full-sized avatar
🎯
Focusing

Kyunghoon Kim koorukuroo

🎯
Focusing
View GitHub Profile
@koorukuroo
koorukuroo / gist:825f3dacdd02dd613194
Created March 8, 2015 07:42
Google Spreadsheet Load in python
import gspread
import pandas
gc = gspread.login('my@email.com', 'supersecretepassword')
book = gc.open('Spreadsheet name')
sheet = book.sheet1 #choose the first sheet
dataframe = pandas.DataFrame(sheet.get_all_records())
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def epsg_4326_to_900913(lon, lat):
x = lon * 20037508.34 / 180
y = (math.log(math.tan((90 + lat) * math.pi / 360)) / (math.pi / 180)) * (20037508.34 / 180)
return x, y
def epsg_900913_to_4326(x, y):
lon = x * 180 / 20037508.34
lat = (360 / math.pi) * math.atan(math.exp(y * math.pi / 20037508.34)) - 90
return lon, lat
def read_gdf(path,directed = False):
if directed:
G = nx.DiGraph()
else:
G = nx.Graph()
state = None
nodes = []
edges = []
for line in open(path,'r'):
line = line.rstrip()
@koorukuroo
koorukuroo / views.py
Last active August 29, 2015 14:18
Python Flask JSONP Method
def support_jsonp(f):
"""Wraps JSONified output for JSONP"""
@wraps(f)
def decorated_function(*args, **kwargs):
callback = request.args.get('callback', False)
if callback:
content = str(callback) + '(' + str(f(*args,**kwargs).data) + ')'
return current_app.response_class(content, mimetype='application/javascript')
else:
return f(*args, **kwargs)
def to_unicode_or_bust(obj, encoding='utf-8'):
# http://farmdev.com/talks/unicode/
if isinstance(obj, basestring):
if not isinstance(obj, unicode):
obj = unicode(obj, encoding)
return obj
from IPython.display import HTML
# To solve the problem : UnicodeDecodeError: 'ascii' codec can't decode byte 0xea in position 83: ordinal not in range(128)
def pdhtml(frame):
return HTML(frame.to_html())
@koorukuroo
koorukuroo / infinite.html
Last active August 29, 2015 14:21
AngularJS : Infinite Scroll Demo
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Infinite Scroll Demo...</title>
<script type='text/javascript' src="http://code.angularjs.org/1.0.0rc9/angular-1.0.0rc9.js"></script>
<style type='text/css'>
li {
height: 120px;
border-bottom: 1px solid gray;
@koorukuroo
koorukuroo / Select2.html
Created May 25, 2015 12:59
Select2.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Select2 Remote Data Select Example - jsFiddle demo by marcrazyness</title>
<script type='text/javascript' src='//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/masonry/3.3.0/masonry.pkgd.min.js"></script>
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import sys
import urllib2
# This script uses HEAD requests (with fallback in case of 405)
# to follow the redirect path up to the real URL
# (c) 2012 Filippo Valsorda - FiloSottile
# Released under the GPL license