Skip to content

Instantly share code, notes, and snippets.

View tobsn's full-sized avatar

Tobsn tobsn

  • US/EU/SEA
View GitHub Profile
@tobsn
tobsn / outout.txt
Created May 24, 2012 16:21
pspell language detection
////////////////////////////////////////
// output for text.en.txt
Array
(
[count] => 100
[de] => Array
(
[found] => 12
[percent] => 12
@tobsn
tobsn / gist:2925744
Created June 13, 2012 18:44
fish bash git branch and status color
tobias:~$ cat .config/fish/config.fish
function fish_prompt
set_color normal
echo -n (whoami)
set_color normal
echo -n ':'
set_color purple
echo -n (prompt_pwd)
set_color normal
<?php
$mongo = assumeMongoConnectHere();
$loop = new React\EventLoop\StreamSelectLoop();
$stack = new React\Espresso\Stack(function ($req, $res) {
$query = $req->getQuery();
@tobsn
tobsn / mongolog.js
Created August 1, 2012 08:28
save access log into mongodb with pipe from lighttpd
#!/usr/local/bin/node
var fs = require('fs'),
useragent = require('/www/utils/node_modules/useragent'),
zoneinfo = require('/www/utils/node_modules/zoneinfo'),
TZDate = zoneinfo.TZDate,
countrycodes = require('/www/utils/node_modules/zoneinfo/lib/countrycodes');
mongo = require('/www/utils/node_modules/mongoq'),
db = mongo('mongodb:\/\/localhost/logs'),
access = db.collection( 'access' );
@tobsn
tobsn / create_countrycodes.php
Created August 1, 2012 23:18
laravel migration for country codes table
<?php
class Create_Country_Codes_Table {
/**
* Make changes to the database.
*
* @return void
*/
public function up()
-- bookmarklet
if( ( string.len( lighty.env["uri.path-raw"] ) == 81 or string.len( lighty.env["uri.path-raw"] ) == 82 ) and lighty.env["request.method"] == "GET" and lighty.env["uri.query"] and string.find( lighty.env["uri.query"], "u=" ) == 1 ) then
get = {}
for k, v in string.gmatch(lighty.env["uri.query"], "(%w+)=(%w+)") do
get[k] = v
end
if( get["u"] ) then
r = math.random(10000,1000000)
lighty.content = { [[
function _UNIQUENAME]] .. r .. [[(){
@tobsn
tobsn / url.query.js
Created September 14, 2012 03:29
node.js parse array form from query string into array like php does
url.query = function( url ) {
var parsed = this.parse( url, true, false ),
query = Object.keys( parsed.query ),
result = {};
if( query.length > 0 ) {
query.forEach(function(key){
if( key.match( /([^\[]+)\[([^\]]+)\]/g ) ) {
key.replace( /([^\[]+)\[([^\]]+)\]/g, function( $0, $1, $2 ) {
result[$1] = result[$1] || {};
result[$1][$2] = parsed.query[key];
@tobsn
tobsn / create.php
Created November 5, 2012 17:13
-rw-r--r-- 1 root root 1100 2007-07-14 11:21 create.php
<?php
# create stats
$c['folder']['logs'] = '/www/logs/';
$c['folder']['stats'] = '/www/stats/htdocs/';
$c['visitors']['bin'] = '/www/stats/visitors/visitors';
$c['visitors']['options'] = '-A -m 100 --screen-info -Z -H -M -X -Y -S -r 200 -g 100 --max-adsensed 100 --trails --prefix';
foreach( glob( $c['folder']['logs'].'access_*.log' ) as $logfile ) {
@tobsn
tobsn / gist:4282275
Created December 14, 2012 02:58
clean open in menu duplicates
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain l,s,u
@tobsn
tobsn / getmime.php
Last active December 16, 2015 18:29
<?php
function getmime( $url ) {
@exec( 'curl -s -I '.escapeshellcmd( $url ), $data );
if( is_array( $data ) && count( $data ) > 3 ) {
$result = array();
foreach( $data as $line ) {
if( stripos( $line, 'Content-Type:' ) !== false || stripos( $line, 'Content-Length:' ) !== false ) {
$line = explode( ':', $line );
$line[1] = trim( $line[1] );
$result[substr(strtolower($line[0]),8)] = ( is_numeric( $line[1] ) ) ? (int)$line[1] : $line[1];