Skip to content

Instantly share code, notes, and snippets.

@sp3c73r2038
sp3c73r2038 / app.py
Created April 2, 2015 09:56
native SQLAlchemy ORM usage...
# -*- coding: utf-8 -*-
import json
import logging
from sqlalchemy import create_engine
from sqlalchemy import types
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql.schema import MetaData, Table
from sqlalchemy import Column, Integer
@sp3c73r2038
sp3c73r2038 / db.py
Created April 1, 2015 05:15
SQLAlchemy: change table schema, on the fly
# -*- coding: utf-8; -*-
from tigger import app
app.ready()
from tigger import db
def decorate_timestamps():
from datetime import datetime
from sqlalchemy import TIMESTAMP, Column, text
@sp3c73r2038
sp3c73r2038 / model.py.tpl
Created March 26, 2015 06:36
reflect and generate models code from database schema :)
# -*- coding: utf-8 -*-
class {{ table.name }}:
__tablename__ = '{{ table.name }}'
{% for col in table.columns %}
{{ col.name }} = Column({{col.type}}{% if col.primary_key %}, primary_key=True{% endif%}{% if not col.nullable %}, nullable=False{% endif %})
{% endfor -%}
@sp3c73r2038
sp3c73r2038 / git-shell.py
Created March 2, 2015 09:45
a simple script to simplify git hosting for personal usage.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import os
import re
import shlex
import sys
import subprocess
@sp3c73r2038
sp3c73r2038 / linux_net_tcp.py
Created February 6, 2015 03:26
a toolkit Python script looking into /proc/net/tcp
# -*- coding: utf-8 -*-
import re
import sys
with open('/proc/net/tcp') as f:
lineno = 0
sockets = []
for line in f:
lineno += 1
if lineno == 1:
@sp3c73r2038
sp3c73r2038 / App.java
Created February 2, 2015 17:00
Java ThreadLocal demo
package net.momoka;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Hello world!
*
*/
@sp3c73r2038
sp3c73r2038 / subprocess.php
Last active August 29, 2015 14:11
a toolkit function for PHP
<?php
// I know, I know, there are proc_open, exec, system functions to use.
// But they just suck...
// So I wrote this, hope this will help ourselves out :3
function subprocess($cmd, $login = FALSE, $cwd = './',
$shell = '/bin/bash', $pipespec = NULL) {
$pid = getmypid();
@sp3c73r2038
sp3c73r2038 / App.java
Last active August 29, 2015 14:11
jackson-databind ObjectMapper demo
package net.momoka;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@sp3c73r2038
sp3c73r2038 / mozconfig
Created November 11, 2014 10:00
mozilla build config for Hardened Gentoo x86_64
export LDFLAGS="-Wl,-z,relro,-z,now"
mk_add_options PYTHON=/usr/bin/python2
mk_add_options AUTOCONF=autoconf-2.13
mk_add_options MOZ_MAKE_FLAGS="-j8"
export MOZ_JEMALLOC=1
ac_add_options --host=x86_64-pc-linux-gnu
ac_add_options --target=x86_64-pc-linux-gnu
@sp3c73r2038
sp3c73r2038 / ical_dump.py
Last active August 29, 2015 14:08
a simple python script dump ical basic info to stdout.
# -*- coding: utf-8 -*-
import sys
## It seems that locale will always be C(ascii) when
## mutt call this script via mailcap
reload(sys)
sys.setdefaultencoding('utf-8')
from icalendar import Calendar
import pytz