Skip to content

Instantly share code, notes, and snippets.

View mapix's full-sized avatar

mapix mapix

View GitHub Profile
# use mixin
class SingletonMixin(object):
_instance = None
def __new__(cls, *args, **kwargs):
if not cls._instance:
cls._instance = super(SingletonMixin, cls).__new__(cls, *args, **kwargs)
elif hasattr(cls, '__init__'):
del cls.__init__
@mapix
mapix / fix_flask_restful.py
Created June 6, 2014 10:40
error handler fix in flask-restful
class RestfulApi(Api):
def __init__(self, *args, **kwargs):
self.ignore_errors = kwargs.pop('ignore_errors', [])
super(RestfulApi, self).__init__(*args, **kwargs)
def error_router(self, original_handler, e):
for ignore_error in self.ignore_errors:
if isinstance(e, ignore_error):
return original_handler(e)
@mapix
mapix / user.py
Created June 5, 2014 08:27
many_to_many_self_relations_in_sqlalchemy
# -*- coding: utf-8 -*-
from app.libs.store import store
user_relations = store.Table('user_relations',
store.Column('source_id', store.Integer, store.ForeignKey('users.id')),
store.Column('target_id', store.Integer, store.ForeignKey('users.id')))

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

git --first-parent log
git --no-merges log
@mapix
mapix / gist:8214073
Created January 2, 2014 02:21
short command.vcs
function sw { svn sw "^/branches/$USER/$1" ;}
function co { svn copy "^/trunk" "^/branches/$USER/$1" ;}
function sl { svn ls "^/branches/$USER" ;}
function swt { svn sw "^/trunk" ;}
function stq { svn st -q ;}
function si { svn info ;}
function su { svn up ;}
function sd { svn diff | colordiff | less -R ;}
function st { svn st;}
@mapix
mapix / gist:8214067
Created January 2, 2014 02:20
proxy.sh
# Enable proxy setting from terminal in ubuntu 12.04
function myProxyOn() {
gsettings set org.gnome.system.proxy mode 'manual' # ' manual / nome / automatic '
gsettings set org.gnome.system.proxy.http host '10.8.0.1'
gsettings set org.gnome.system.proxy.http port 8118
gsettings set org.gnome.system.proxy.https host '10.8.0.1'
gsettings set org.gnome.system.proxy.https port 8118
gsettings set org.gnome.system.proxy.ftp host '10.8.0.1'
gsettings set org.gnome.system.proxy.ftp port 8118
@mapix
mapix / zsh.md
Created January 2, 2014 02:17 — forked from tsabat/zsh.md
def setup_stub_mc():
class StubClient(object):
def __getattr__(self, key):
def _(*args, **kwargs):
return None
return _
_mc.cache_mc.mc = StubClient()
@mapix
mapix / stderr_ignore_pattern.py
Created November 18, 2013 04:02
stderr ignore pattern
from contextlib import contextmanager
class ObjectWrapper(object):
def __init__(self, wrapped_object):
self.wrapped_object = wrapped_object
def __getattr__(self, attr):
return self.wrapped_object.__getattribute__(attr)
@contextmanager