Skip to content

Instantly share code, notes, and snippets.

@allieus
allieus / itunes_nowplaying_tweet.rb
Last active December 10, 2015 03:38
현재 재생 중인 iTunes 노래를 트윗할 수 있도록, 브라우저 창을 띄워줍니다.
#!/usr/local/bin/macruby
#
# http://merbist.com/2010/01/17/controlling-itunes-with-macruby/
#
# $ sdef /Applications/iTunes.app | sdp -fh --basename iTunes
# $ gen_bridge_metadata -c '-I.' iTunes.h > iTunes.bridgesupport
# $ macruby itunes_nowplaying_tweet.rb
#
@allieus
allieus / fib.py
Created January 8, 2013 00:32
Fibonachi Number
def cache(fn):
_cached = {}
def wrap(*args, **kwargs):
key = repr((args, kwargs))
if key not in _cached:
value = fn(*args, **kwargs)
_cached[key] = value
return _cached[key]
return wrap
@allieus
allieus / run_twisted.py
Last active December 11, 2015 22:39
Django 프로젝트를 Twisted 를 통해 실행
import os
import sys
from twisted.web import server, resource, wsgi, static
CURRENT_PATH = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.join(CURRENT_PATH, 'observer'))
class DjangoResource(resource.Resource):
def __init__(self, wsgi_resource):
resource.Resource.__init__(self)
@allieus
allieus / method1.py
Last active December 14, 2015 10:18
custom member function for Django User Model
#
# models.py
#
from django.db import models
from django.contrib.auth.models import User
def get_posts_count(self, date):
return self.post_set.filter(created_at__year = date.year,
created_at__month = date.month,
created_at__day = date.day).count()
@allieus
allieus / search_mathterm.py
Last active December 14, 2015 11:18
국가 지정 수리과학연구정보센터, 수학용어 검색 스크립트
# coding: utf-8
import sys
from urllib import urlencode, urlopen
from BeautifulSoup import BeautifulSoup
def search(term):
params = urlencode({
'mode': 'list',
'ftype': 'eng_term',
'fstr': term,
from django import forms
from .models import IPAddr, SomeModel
class SomeForm(forms.ModelForm):
ip = forms.IPAddressField()
def save(self, commit=True):
ip = self.cleaned_data['ip']
ip_addr, is_created = IPAddr.objects.get_or_create(ip=ip)
instance = super(SomeForm, self).save(commit=False)
@allieus
allieus / nginx
Created April 19, 2013 03:48
/etc/init.d/nginx 스크립트
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
def merge_sort[T](less: (T, T) => Boolean)(xs: List[T]): List[T] = {
def merge(xs: List[T], ys: List[T]): List[T] =
(xs, ys) match {
case (Nil, _) => ys
case (_, Nil) => xs
case (x :: xs1, y :: ys1) =>
if (less(x, y))
x :: merge(xs1, ys)
else
y :: merge(xs, ys1)
@allieus
allieus / gist:5779804
Last active December 18, 2015 11:59
openresty 1.2.8.6 에서 srcache + uwsgi
# django 단에서 데이터 변경 시에 캐싱된 데이터를 memcache 을 통해 직접 삭제하고 있습니다.
upstream memcached {
server 127.0.0.1:11211;
}
server {
memc_connect_timeout 100ms;
memc_send_timeout 100ms;
memc_read_timeout 100ms;
@allieus
allieus / gist:5864923
Created June 26, 2013 05:07
coffeescript 파일 변경 시에, 자동 빌드 수행
# coding: utf-8
import os
import time
files = {}
def check():
global files
for root, dirnames, filenames in os.walk('.'):