Skip to content

Instantly share code, notes, and snippets.

View nkuln's full-sized avatar

Gant Kulnirundorn nkuln

View GitHub Profile
@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");
}
@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 / 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 / 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 / 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 / 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 / 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 / filename_replace.sh
Created September 15, 2012 11:54
Simple batch file name replace in bash
!/bin/bash
# Debugging .. print all commands executed
set -x
for f in *
do
# Replace all occurrences of '%20' with ' ' (single space)
newname=${f//%20/ }
# We're safer with quotes around ..
mv "$f" "$newname"
@nkuln
nkuln / v8_code_sample.cpp
Created August 6, 2012 08:44
V8 Code Sample
// UpaV8PerfTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace v8;
std::string readSourceFile(std::string fileName)
{
std::ifstream t(fileName);
Date & Time: 7/12/2012 9:01:28 AM
Event Class: File System
Operation: CreateFile
Result: ACCESS DENIED
Path: C:\Users\nkuln\Desktop\APISnapshot_100b\bin\APISnapshot_Service.exe
TID: 164
Duration: 0.0015702
Desired Access: Read Data/List Directory, Execute/Traverse, Read Attributes, Synchronize
Disposition: Open
Options: Synchronous IO Non-Alert, Non-Directory File