Skip to content

Instantly share code, notes, and snippets.

@kamawanu
kamawanu / blogger_post_tagcleaner.py
Last active February 6, 2016 03:54
clean blogger(blogspot) posts.
#!/usr/bin/env python
import sys, logging
sys.path.insert(0,"./gdata-2.0.11.final.zip/src")
from gdata import service
import gdata
import atom
import simplejson
@kamawanu
kamawanu / fstab_creater.sh
Created December 26, 2010 11:01
append fstab from current mount
#!/bin/bash -x
# https://gist.github.com/755352
for DEV in $( mount | awk '{print $1}'|fgrep /dev/ )
do
PUREDEV=$( echo $DEV | cut -d/ -f3- )
UUIDIS=$( ls -l /dev/disk/by-uuid/ | fgrep $PUREDEV | awk '{print $8}' )
fgrep $UUIDIS /etc/fstab || (
echo $UUIDIS
echo UUID=$UUIDIS $( mount | fgrep $PUREDEV | awk '{print $3,$5}') defaults,noatime 0 0 | sudo tee -a /etc/fstab
)
@kamawanu
kamawanu / facebook_oldxhr_hack.js
Created March 21, 2011 15:49
facebook old xd_receiver.js resize hack.
var pos = document.location.hash.search( /setCanvasHeight/ )
if( pos >= 0 ){
hashvpos = document.location.hash.search( /setCanvasHeight%22%2C%22([0-9]+)px/ );
crop = document.location.hash.substring(hashvpos+24);
pxpos = crop.search("px");
heighthack = crop.substring( 0, pxpos );
if( heighthack > 300 ){
newv = document.location.hash.replace( "setCanvasHeight%22%2C%22"+heighthack, "setCanvasHeight%22%2C%22300" );
document.location.hash = newv;
}
@kamawanu
kamawanu / object2array.php
Created April 16, 2011 10:51
converting between nested object and nested array, bidirectional
<?php
/**
* https://gist.github.com/923041
*
* converting between nested object and nested array, bidirectional
*/
function object2array( $srcobject , array $exclude_propnames = null ){
assert( gettype($srcobject) == "object" );
@kamawanu
kamawanu / unescape2utf8.php
Created April 24, 2011 14:42
unescape unicode string and convert utf-8
<?php
function unicode2utf8($aa){
###var_dump(func_get_args());
return mb_convert_encoding( pack("n", hexdec($aa[1]) ), "utf-8", "ucs2" );
}
while( ($f=fgets(STDIN))!==false ){
$a = str_replace('\\','\',$a );
$a = preg_replace_callback('/\\\u([a-f0-9]{4})/i', "unicode2utf8", $f );
@kamawanu
kamawanu / dict2list.py
Created October 9, 2011 13:05
dict2list
#!python
def dict2list(dict1):
assert isinstance(dict1,dict)
indexes = sorted(dict1.keys())
## try:
[ int(xx) for xx in indexes ] # validation: all keys is integer
assert indexes[0] == 0 and indexes[-1] == len(indexes)-1, "can not convert to list"
return [ dict1[xx] for xx in indexes ]
@kamawanu
kamawanu / debugmode.py
Created November 23, 2011 07:47
DEBUGMODE = ( time.time() - timeo.st_mtime ) < 60
import sys,os, time
timeo = os.stat(sys.argv[0])
DEBUGMODE = ( time.time() - timeo.st_mtime ) < 60
@kamawanu
kamawanu / __init__.py
Last active February 9, 2022 00:21
wrap sqlite3 as dict
#! https://gist.github.com/4502712
@kamawanu
kamawanu / add-sparse-vdisk.sh
Last active December 15, 2015 07:59
add sparse virtualdisk for linuxmint
#!/bin/sh -x
PART=$1
MSIZE=${2-20}
FS=${3-ext4}
SIZE=$( expr $MSIZE \* 1024 \* 1024 )
LAST=$( expr $SIZE - 1 )
dd if=/dev/zero bs=1k count=1 seek=$LAST of=/host/linuxmint/$PART.disk
mkfs.$FS /host/linuxmint/$PART.disk || exit 9
ls -l /host/linuxmint/$PART.disk
du -sm /host/linuxmint/$PART.disk