Skip to content

Instantly share code, notes, and snippets.

View nkuln's full-sized avatar

Gant Kulnirundorn nkuln

View GitHub Profile
@nkuln
nkuln / gettimestamp_cpp_windows.cpp
Created October 19, 2011 11:00
Demonstrate problem from getting 64-bit timestamp to nanosec in Windows
// Demonstrate problem in GetSystemTimeAsFileTime(..) call
// The time returned is not very precised
//
ULARGE_INTEGER prev_timestamp, timestamp;
prev_timestamp.QuadPart = 0;
for(int i = 0 ; i < 100 ; ++i, prev_timestamp = timestamp){
FILETIME now;
GetSystemTimeAsFileTime(&now);
@nkuln
nkuln / perf_counter_timer.hpp
Created October 20, 2011 10:36
Example for QueryPerformanceCounter to get current time in Windows C++
//
// PerfCounterTimer:
// To get current time in millisecond, use (1000.0 * GetCurrentTime() / GetFrequency()).
// Practically, you must cache value from GetFrequency() so that you don't need to
// re-query the frequency every time
//
#pragma once
#include <windows.h>
@nkuln
nkuln / test_mixin.py
Created October 20, 2011 18:00
Playing with Mixin which is basically a multiple inheritance. I was confused before on what the line 'cls = TestMixin' does ..
class TestMixin(object):
member1 = ['gant','from','mixin']
def mixin_method(self):
print 'member 1 from self: %s' % self.member1
cls = TestMixin
print 'member 1 from cls: %s' % cls.member1
class Cat(TestMixin):
member1 = 'meow meow'
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
// ..
struct timeval t;
gettimeofday(&t, NULL);
rfa::common::Int64 now;
now = t.tv_sec;
@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 / blogger_snippet.js
Created May 1, 2012 12:11
Adding source code to my blogger account
<script class="brush: js; toolbar: false" type="syntaxhighlighter">
<![CDATA[
System.Threading.Parallel.For(0, maxNum + 1, => IsPrime(x));
]]>
</script>
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
@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);
@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 / 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: