Skip to content

Instantly share code, notes, and snippets.

View codeb2cc's full-sized avatar
🎯
Focusing

Codeb Fan codeb2cc

🎯
Focusing
  • Eastworld AI
  • Singapore
View GitHub Profile
@codeb2cc
codeb2cc / gist:3302754
Created August 9, 2012 09:48
Sqlalchemy get_or_create implement
# -*- coding: utf-8 -*-
from sqlalchemy.exc import IntegrityError
from sqlalchemy.sql.expression import ClauseElement
def _get_or_create(session, model, defaults=None, **kwargs):
try:
query = session.query(model).filter_by(**kwargs)
instance = query.first()
@codeb2cc
codeb2cc / gist:3347349
Created August 14, 2012 08:02
Terminator config file
[global_config]
title_hide_sizetext = True
title_transmit_bg_color = "#ededed"
enabled_plugins = LaunchpadCodeURLHandler, APTURLHandler, LaunchpadBugURLHandler
title_transmit_fg_color = "#080808"
title_inactive_bg_color = "#ededed"
[keybindings]
[profiles]
[[default]]
use_system_font = False
@codeb2cc
codeb2cc / postMessageA.html
Created August 30, 2012 10:37
window.postMessage
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p></p>
<div style="border: 1px solid whiteSmoke">
<iframe src="./postMessageB.html" frameborder="0" style="width: 100%;"></iframe>
/*jshint asi:true, browser:true */
define(function (require, exports) {
var extend = function (obj) {
each(slice.call(arguments, 1), function (source) {
for (var prop in source) {
obj[prop] = source[prop]
}
})
@codeb2cc
codeb2cc / .bashrc
Last active October 10, 2015 00:48
PS1 on server
# Reset
Color_Off='\e[0m' # Text Reset
# Regular Colors
Black='\e[0;30m' # Black
Red='\e[0;31m' # Red
Green='\e[0;32m' # Green
Yellow='\e[0;33m' # Yellow
Blue='\e[0;34m' # Blue
Purple='\e[0;35m' # Purple
@codeb2cc
codeb2cc / ip.sh
Created October 29, 2012 02:50
Get PPPoe IP address
#!/bin/sh
if [ `nm-tool | ack eth0 -A 5 | ack State | sed 's/ *//g' | cut -f 2 -d ':'` == "connected" ]; then
# Interface eth0 UP
:
else
# Interface eth0 DOWN. Try to restart
ifup eth0
fi
@codeb2cc
codeb2cc / issue.txt
Created November 29, 2012 06:03
Text base issue system template
==== ==== ==== ==== Issue #0 ==== ==== ==== ====
Summary:
Description:
Priority: Critical | Major | Normal | Minor
Type: Bug | Feature | Optimization
State: Open | In Progress | Fixed | Closed
Assignee:
Comments:
@codeb2cc
codeb2cc / monitor.sh
Last active October 13, 2015 09:37
Memeory usage monitor
#!/bin/sh
MEM=$(cat /proc/meminfo | ack 'MemFree: +(\d+)' --output "\$1" | bc)
CAC=$(cat /proc/meminfo | ack '^Cached: +(\d+)' --output "\$1" | bc)
FREE=$(echo "$MEM + $CAC" | bc)
THRESHOLD=1048576
echo "Free Memory: $MEM kb"
@codeb2cc
codeb2cc / iptables
Created January 3, 2013 15:44 — forked from anonymous/iptables
Linode PPTP VPN iptables configuration
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*nat
:PREROUTING ACCEPT [10:532]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
# PPTP
-A POSTROUTING -s 10.18.1.0/24 -o eth0 -j MASQUERADE
@codeb2cc
codeb2cc / gist:4994086
Created February 20, 2013 08:56
Remove control characters
import unicodedata
import re
chars = (unichr(i) for i in xrange(0x110000))
cc = ''.join(c for c in chars if unicodedata.category(c) == 'Cc')
# or equivalently and much more efficiently
cc = ''.join(map(unichr, range(0,32) + range(127,160)))
cc_re = re.compile('[%s]' % re.escape(cc))