Skip to content

Instantly share code, notes, and snippets.

@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
Created February 2, 2015 17:00
Java ThreadLocal demo
package net.momoka;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Hello world!
*
*/
@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 / 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 / app.py
Created April 22, 2015 09:42
Native usage of Jinja2
# -*- coding: utf-8 -*-
from jinja2 import Environment, FileSystemLoader
env = Environment(loader=FileSystemLoader('templates'))
t = env.get_template('test.jinja2')
print(t.render(name='world'))
@sp3c73r2038
sp3c73r2038 / app.py
Created April 24, 2015 06:19
Python garbage collection statistics...
# -*- coding: utf-8 -*-
import gc
s = {}
for i in gc.get_objects():
_ = str(type(i))
if _ in s:
s[_] += 1
else:
@sp3c73r2038
sp3c73r2038 / drm-call-stack.md
Created May 30, 2015 12:50
Linux kernel, DRM and VGA_SWITCHEROO call stack
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)
	=&gt; drm_pci_init() (drm_pci.c)
@sp3c73r2038
sp3c73r2038 / ddns_updater.py
Last active August 29, 2015 14:23
Update Dynamic DNS record when it's really needed.
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import logging
import os
import re
import subprocess
import sys
import syslog
import dns.resolver
@sp3c73r2038
sp3c73r2038 / time.date.convertion.php
Created January 13, 2011 04:22
php time and date convertion
<?php
/* from unix timestamp to date */
$time = time();
echo date("Y-m-d H:i:s", $time),"\n";
/* from date string to timestamp */
$date = '2011-01-01 00:00:00';
echo strtotime($date),"\n";
<?php
/* input the year and week you want, then get the date! */
function getFirstDayOfWeek($year, $weeknr, $date_format="Y-m-d"){
$offset = date('w', mktime(0,0,0,1,1,$year));
$offset = ($offset < 5) ? 1-$offset : 8-$offset;
$monday = mktime(0,0,0,1,1+$offset,$year);
$date = strtotime('+' . ($weeknr - 1) . ' weeks', $monday);
return date($date_format,$date);
}