Skip to content

Instantly share code, notes, and snippets.

View nkuln's full-sized avatar

Gant Kulnirundorn nkuln

View GitHub Profile
@nkuln
nkuln / wpphotomigrator.py
Created September 15, 2012 11:58
Download all images from a Wordpress posts, and then replace all the existing URLs
import MySQLdb as mdb
import HTMLParser
import random
import urllib2
import urlparse
from bs4 import BeautifulSoup
from os import path
class ImageMigrator:
@nkuln
nkuln / run_with_libumem.sh
Created September 17, 2012 04:38
Run with Solaris libumem memory profiler
#!/bin/bash
export LD_PRELOAD=libumem.so.1
export UMEM_DEBUG=default
export UMEM_LOGGING=transaction
./"$1"
@nkuln
nkuln / vimrc
Created March 22, 2013 10:06
Switch between C++ source/test/header in Vim
"switch between .h / -inl.h / .cc / .py / .js / _test.* / _unittest.* with ,h
",i ,c ,p ,j ,t ,u
""(portion from old mail from David Reiss)
let pattern = '\(\(_\(unit\)\?test\)\?\.\(cc\|js\|py\)\|\(-inl\)\?\.h\)$'
nmap ,c :e <C-R>=substitute(expand("%"), pattern, ".cc", "")<CR><CR>
nmap ,h :e <C-R>=substitute(expand("%"), pattern, ".h", "")<CR><CR>
nmap ,i :e <C-R>=substitute(expand("%"), pattern, "-inl.h", "")<CR><CR>
nmap ,t :e <C-R>=substitute(expand("%"), pattern, "_test.", "") . substitute(expand("%:e"), "h", "cc", "")<CR><CR>
nmap ,u :e <C-R>=substitute(expand("%"), pattern, "_unittest.", "") . substitute(expand("%:e"), "h", "cc", "")<CR><CR>
nmap ,p :e <C-R>=substitute(expand("%"), pattern, ".py", "")<CR><CR>
@nkuln
nkuln / hsv_rgb_led.ino
Created April 21, 2018 05:33
Color-changing RGB LED by rotating hue
#include <Keyboard.h>
#include <math.h>
#define BLUE 3
#define GREEN 5
#define RED 6
void setup()
{
pinMode(RED, OUTPUT);
@nkuln
nkuln / training_sample.csv
Last active July 5, 2018 04:24
Training data sample for gender classification
first_name gender
ธนชิต M
วงศธร M
กิตติศักดิ์ M
รุจ M
ทศวรรษ M
ธนพล M
รัตนา F
ธนรัตน์ F
สุดาพร F
@nkuln
nkuln / overly_simplistic_classifier.py
Created July 5, 2018 04:47
Overly simplistic classifier
def is_male(name):
if u"ศักดิ์" in name or name.endswith(u"วุฒิ"):
return True
elif name.endswith(u"พร") or name.endswith(u"พรรณ"):
return False
else:
return False
print(is_male(u"ณัฐวุฒิ")) # True
print(is_male(u"ณัฏฐ์พร")) # False
@nkuln
nkuln / cxa_throw_replace_backtrace.c
Created March 12, 2012 09:18
Override __cxa_throw and prints backtrace when exception is thrown (Linux)
#include <dlfcn.h>
#include <execinfo.h>
typedef void (*cxa_throw_type)(void *, void *, void (*) (void *));
cxa_throw_type orig_cxa_throw = 0;
void load_orig_throw_code()
{
orig_cxa_throw = (cxa_throw_type) dlsym(RTLD_NEXT, "__cxa_throw");
}