Skip to content

Instantly share code, notes, and snippets.

@aleiphoenix
aleiphoenix / jc.go
Created May 25, 2020
Quickly check JSON file syntax. Faster than `jq`. Good to use in git pre-commit hook.
View jc.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
)
@aleiphoenix
aleiphoenix / pyx
Created May 19, 2020
Python virtualenv exec helper like npx in NodeJS world.
View pyx
#!/bin/bash
function log() {
ts=$(date +%Y-%m-%d_%T,%6N)
level=$1
shift 1
case $level in
(err*)
echo ${ts} [ERROR]: $* 1>&2
;;
@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 / 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 / ddns_updater.py
Last active Aug 29, 2015
Update Dynamic DNS record when it's really needed.
View ddns_updater.py
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import logging
import os
import re
import subprocess
import sys
import syslog
import dns.resolver
@aleiphoenix
aleiphoenix / drm-call-stack.md
Created May 30, 2015
Linux kernel, DRM and VGA_SWITCHEROO call stack
View drm-call-stack.md
radeon module
  __init radeon_init()    (radeon_device.c)
	=> radeon_kms_pci_driver.probe = radeon_pci_probe
    => if (radeon_modeset == 1)
			"radeon kernel modesetting enabled.\n"
			driver = &kms_driver
			pdriver = &radeon_kms_pci_driver
			radeon_register_atpx_handler()    (radeon_atpx_handler.c)
	=> drm_pci_init()    (drm_pci.c)
@aleiphoenix
aleiphoenix / app.py
Created Apr 24, 2015
Python garbage collection statistics...
View app.py
# -*- coding: utf-8 -*-
import gc
s = {}
for i in gc.get_objects():
_ = str(type(i))
if _ in s:
s[_] += 1
else:
@aleiphoenix
aleiphoenix / app.py
Created Apr 22, 2015
Native usage of Jinja2
View app.py
# -*- coding: utf-8 -*-
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates'))
t = env.get_template('test.jinja2')
print(t.render(name='world'))
@aleiphoenix
aleiphoenix / app.py
Created Apr 2, 2015
native SQLAlchemy ORM usage...
View app.py
# -*- 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
@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
You can’t perform that action at this time.