Skip to content

Instantly share code, notes, and snippets.

View lemonlatte's full-sized avatar

Jim Yeh lemonlatte

  • Taipei, Taiwan
  • 19:35 (UTC +08:00)
View GitHub Profile
@lemonlatte
lemonlatte / git-completion.sh
Created June 26, 2012 02:45 — forked from denis/gist:48774
This is the way to add git-completion from source
cd /tmp
git clone git://git.kernel.org/pub/scm/git/git.git
cd git
git checkout v`git --version | awk '{print $3}'`
cp contrib/completion/git-completion.bash ~/.git-completion.bash
cd ~
rm -rf /tmp/git
echo -e "source ~/.git-completion.bash" >> .profile
@lemonlatte
lemonlatte / gist:3074069
Created July 9, 2012 03:28
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@lemonlatte
lemonlatte / TruncateFilter.js
Created August 6, 2012 07:11 — forked from dcsg/TruncateFilter.js
Truncate Filter for AngularJS v1.0
// add the filter to your application module
angular.module('yourAppName', ['filters']);
/**
* Truncate Filter
* @Param string
* @Param int, default = 10
* @Param string, default = "..."
* @return string
*/
@lemonlatte
lemonlatte / 0_urllib2.py
Created August 20, 2012 08:06 — forked from kennethreitz/0_urllib2.py
urllib2 vs requests
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
@lemonlatte
lemonlatte / simple echo websocket server
Created September 12, 2012 10:02 — forked from anonymous/simple echo websocket server
for nodejs. need do a lot refactoring though.
var net = require('net'),
sys = require('sys');
function WSServer(port, ip) {
if(!port) throw('You should assign a port to listen.');
this.port = port;
this.ip = ip||'127.0.0.1';
this.server = null;
var clients = {};
var state = {
@lemonlatte
lemonlatte / profile_middleware.py
Created November 20, 2012 03:23 — forked from kesor/profile_middleware.py
Django cProfile middleware
from django.core.exceptions import MiddlewareNotUsed
from django.conf import settings
import cProfile
import pstats
import marshal
from cStringIO import StringIO
class ProfileMiddleware(object):
def __init__(self):
if not settings.DEBUG:
@lemonlatte
lemonlatte / testrunner.py
Created November 21, 2012 07:38 — forked from xintron/testrunner.py
Django testrunner for mongoengine
from django.test.simple import DjangoTestSuiteRunner
from django.test import TransactionTestCase
from mongoengine import connect
class TestRunner(DjangoTestSuiteRunner):
def setup_databases(self, **kwangs):
db_name = 'testsuite'
connect(db_name)
print 'Creating test-database: ' + db_name
@lemonlatte
lemonlatte / redmine gitlab sync
Created November 29, 2012 04:45 — forked from jakimowicz/redmine gitlab sync
simple (and dirty) sync between redmine issues and gitlab issues
#!/usr/bin/env ruby
require 'faraday'
require 'json'
require 'gitlab'
module Redmine
Host = nil
APIKey = nil
MongoDB upstart scripts for Ubuntu.
Run following commands after installing upstart scripts:
ln -s /lib/init/upstart-job /etc/init.d/mongoconf
ln -s /lib/init/upstart-job /etc/init.d/mongodb
ln -s /lib/init/upstart-job /etc/init.d/mongos
To start services use:
# Stolen from http://paste.pocoo.org/show/224441/
from pymongo.cursor import Cursor
from pymongo.connection import Connection
from pymongo.errors import AutoReconnect
from time import sleep
def reconnect(f):
def f_retry(*args, **kwargs):