Skip to content

Instantly share code, notes, and snippets.

aleiphoenix

Block or report user

Report or block aleiphoenix

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@aleiphoenix
aleiphoenix / db.py
Created Apr 1, 2015
SQLAlchemy: change table schema, on the fly
View db.py
# -*- 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
@aleiphoenix
aleiphoenix / screenshot
Last active Apr 24, 2019
a script using ImageMagick to take screenshots
View screenshot
#!/bin/bash
DIR="${HOME}/images/screenshots"
DATE="$(date +%Y%m%d-%H%M%S)"
NAME="${DIR}/screenshot-${DATE}.png"
LOG="${DIR}/screenshots.log"
# Check if the dir to store the screenshots exists, else create it:
if [ ! -d "${DIR}" ]; then mkdir -p "${DIR}"; fi
@aleiphoenix
aleiphoenix / ipconv.go
Created Apr 3, 2019
golang ipv4 string to uint32.
View ipconv.go
package ipconv
import (
"fmt"
"strconv"
"strings"
)
func Conv(ip string) (uint32, error) {
segs := strings.Split(ip, ".")
@aleiphoenix
aleiphoenix / post.py
Last active Nov 9, 2018
urlopen with proxy support
View post.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
import urllib2
data = urllib2.urlencode({'foo': 'bar'})
r = urllib2.Request('https://www.google.com', # url
data, # post data
@aleiphoenix
aleiphoenix / linux_net_tcp.py
Created Feb 6, 2015
a toolkit Python script looking into /proc/net/tcp
View linux_net_tcp.py
# -*- 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:
@aleiphoenix
aleiphoenix / app.py
Last active Jan 31, 2018
how to acccess multiple database with same tablename, in Flask and SQLAlchemy.
View app.py
# -*- coding: utf-8 -*-
from flask import Flask
from sqlalchemy import SQLAlchemy
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+oursql://foo:bar@localhost/test1"
# binds multiple database definition
app.config['SQLALCHEMY_BINDS'] = {
"db1": "mysql+oursql://foo:bar@localhost/test1",
@aleiphoenix
aleiphoenix / local.py
Created Jun 29, 2016
run command in child process without
View local.py
# -*- coding: utf-8 -*-
import errno
import os
import fcntl
# !! License GPLv2 !!
# only work on Linux, MacOSX, may work on Windows, no tested.
# some syscall/flags not available on other OS(like Solaris), so not supported
@aleiphoenix
aleiphoenix / ruby.markdown
Last active Feb 19, 2016
executable host ruby is required. use --with-baseruby option
View ruby.markdown

When compiling ruby from source tarball by hand, if you got executable host ruby is required. use --with-baseruby option. Then this can be the reason.

make distclean (assume you configure'ed once) then configure and make, got

executable host ruby is required. use --with-baseruby option

distclean cleans out some file generated from erb, which requiring a existing ruby.

@aleiphoenix
aleiphoenix / sig_queue.py
Created Jan 23, 2014
handle signal using a queue, stolen from unicorn :)
View sig_queue.py
#!/usr/bin/env python
import errno
from fcntl import fcntl, F_SETFL
import os
from select import select
from signal import signal, SIGQUIT, SIGINT, SIGTERM, SIGUSR1, SIGUSR2, SIGHUP
from time import sleep
class Server(object):
@aleiphoenix
aleiphoenix / fork.py
Created Jan 20, 2014
master/worker prefork process model.
View fork.py
#!/usr/bin/env python
from __future__ import unicode_literals, print_function
import os
from time import sleep
WORKERS = 3
_cnt = 0
while _cnt < WORKERS:
You can’t perform that action at this time.