Skip to content

Instantly share code, notes, and snippets.

View puzzlet's full-sized avatar

정 경훈 (Kyung-hown Chung) puzzlet

View GitHub Profile
@hrldcpr
hrldcpr / tree.md
Last active May 1, 2024 00:11
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@crofty
crofty / index.html
Last active October 22, 2021 08:24
A example of using Google Map tiles with the Leaflet mapping library - http://matchingnotes.com/using-google-map-tiles-with-leaflet
<!DOCTYPE html>
<html>
<head>
<title>Leaflet</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.3.1/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.3.1/leaflet.js"></script>
<script src="http://maps.google.com/maps/api/js?v=3.2&sensor=false"></script>
<script src="http://matchingnotes.com/javascripts/leaflet-google.js"></script>
</head>
<body>
@lifthrasiir
lifthrasiir / magicalmd5.py
Created August 20, 2012 08:37
마법의 MD5 스펙 생성기
# coding=utf-8
def score(s, encoding=None):
if encoding: s = s.encode(encoding)
import hashlib; a = hashlib.md5(s).digest()
return (int(round(10+ord(a[0])/255.*90)), # 공격
int(round(10+ord(a[5])/255.*90)), # 민첩
int(round(10+ord(a[1])/255.*90)), # 방어
int(round(10+ord(a[2])/255.*90)), # 명중
int(round(10+ord(a[3])/255.*90)), # 운
int(round(100+ord(a[4])/255.*200))) # 체력
@euphoris
euphoris / cd_hook.sh
Created August 20, 2012 16:20 — forked from dahlia/cd_hook.sh
[virtualenvwrapper] automatic workon hook on cd
export PROJECTS_HOME="$HOME/Projects"
function has_virtualenv__() {
if [[ ${PWD##$PROJECTS_HOME} != $PWD ]]; then
IFS="/" read -ra ADDR <<< "${PWD##$PROJECTS_HOME}"
venvname=${ADDR[1]}
cur_env=${VIRTUAL_ENV##$WORKON_HOME}
if [[ $venvname != "" ]] && [[ -d "$WORKON_HOME/$venvname" ]]; then
if [[ ${cur_env:1} != $venvname ]]; then
workon "$venvname"

파이썬 웹개발 요리책

바로 실전에 적용할 수 있는 파이썬 웹 개발 레시피. 기초적인 파이썬 지식이 필요합니다.

파이썬 복습

앞으로 다룰 내용에서 알아둬야 할 파이썬 기능을 다시 한번 짚고 넘어갑니다. 이미 파이썬 고수라면 건너뛰셔도 좋습니다!

  • 모듈
@puzzlet
puzzlet / id_anomaly.py
Created October 22, 2012 05:41
never use id() with unbound function
$ python2.7 id_anomaly.py
old_func is not new_func
('old_func:', 41458576, <bound method classobj.member_func of <class __main__.A at 0x278bf58>>)
('new_func:', 41314096, <bound method classobj.member_func of <class __main__.A at 0x278bf58>>)
$ python3.2 id_anomaly.py
old_func is not new_func
old_func: 140100968595896 <bound method type.member_func of <class '__main__.A'>>
new_func: 140100968596184 <bound method type.member_func of <class '__main__.A'>>
@puzzlet
puzzlet / gist:3998342
Created November 2, 2012 02:36
The wild world of ZeroDivisionError messages
# Python 2.5 & 2.6
1/0 # ZeroDivisionError: integer division or modulo by zero
1%0 # ZeroDivisionError: integer division or modulo by zero
1.0/0 # ZeroDivisionError: float division
1.0%0 # ZeroDivisionError: float modulo
# Python 2.7
1/0 # ZeroDivisionError: integer division or modulo by zero
1%0 # ZeroDivisionError: integer division or modulo by zero
1.0/0 # ZeroDivisionError: float division by zero
1.0%0 # ZeroDivisionError: float modulo
@inbeom
inbeom / parse.rb
Created November 11, 2012 14:20
Parser for HTML files generated by Microsoft Excel
# encoding = utf-8
require 'nokogiri'
require 'iconv'
require 'table_parser'
module TableParser
class Table
def each
return unless block_given?
anonymous
anonymous / gist:4336370
Created December 19, 2012 12:32
import re
import urllib
from bs4 import BeautifulSoup
import datetime
def read_percentage(soup):
return float(re.search(r'\((\d+\.\d+)\)',repr(soup)).groups()[0])
f = urllib.urlopen('http://info.nec.go.kr/electioninfo/electionInfo_report.xhtml?electionId=0020121219&requestURI=%2Felectioninfo%2F0020121219%2Fvc%2Fvccp09.jsp&topMenuId=VC&secondMenuId=VCCP&menuId=VCCP09&statementId=VCCP09_%231&electionCode=1&cityCode=0&sggCityCode=0&x=26&y=8')
html = f.read()
@stania
stania / setupVSEnv.py
Last active June 11, 2016 21:45
python implementation replacing "call vsvars32.bat"
from subprocess import Popen
import os, subprocess
def parseEnv(envoutput):
handle_line = lambda l: tuple(l.rstrip().split("=", 1))
pairs = map(handle_line, envoutput)
valid_pairs = filter(lambda x: len(x) == 2, pairs)
valid_pairs = [(x[0].upper(), x[1]) for x in valid_pairs]
return dict(valid_pairs)