This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# django 단에서 데이터 변경 시에 캐싱된 데이터를 memcache 을 통해 직접 삭제하고 있습니다. | |
upstream memcached { | |
server 127.0.0.1:11211; | |
} | |
server { | |
memc_connect_timeout 100ms; | |
memc_send_timeout 100ms; | |
memc_read_timeout 100ms; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import os | |
import time | |
files = {} | |
def check(): | |
global files | |
for root, dirnames, filenames in os.walk('.'): |