Skip to content

Instantly share code, notes, and snippets.

View somma's full-sized avatar

somma somma

View GitHub Profile
@somma
somma / pgfunction sample
Last active August 29, 2015 13:57
pgsql function sample
-- Table: bytea_test
-- DROP TABLE bytea_test;
CREATE TABLE bytea_test
(
md5_key bytea
)
WITH (
OIDS=FALSE
class handle_placeholder
{
public:
handle_placeholder(HANDLE handle): _handle(handle){}
~handle_placeholder(){ close(); }
void close()
{
if (INVALID_HANDLE_VALUE != _handle)
{
/******************************************************************************
* RAII (Resource Acquisition Is Initialization )
******************************************************************************/
/* ex)
raii_handle map_handle(
CreateFileMapping(file_handle, NULL, PAGE_READONLY, 0, 1, NULL),
raii_CloseHandle
);
if (NULL == map_handle.get())
{
@somma
somma / gist:69c15c0f7043d4fc696d
Created September 19, 2014 05:31
callback function in python
#! /usr/bin/python3.2
def repeat (function, params, times):
for calls in range (times):
function (*params)
def foo (a, b):
print ('{} are {}'.format (a, b) )
repeat (foo, ['roses', 'red'], 4)
@somma
somma / gist:14ae7d3de31a1b2f4172
Created September 22, 2014 05:03
_WIN64 macro
#if defined(_WIN64)
//> x64 code
ULONG64 x64_read_msr(IN UINT32 msr_index);
void x64_write_msr(IN UINT32 msr_index, IN UINT32 msr_low, IN UINT32 msr_high);
#elif defined(_X86_)
//> x86 code
void __stdcall x86_read_msr(IN UINT32 msr_index, OUT MSR* msr);
void __stdcall x86_write_msr(IN UINT32 msr_index, IN UINT32 msr_low, IN UINT32 msr_high);
$$ WinDbg script to hook NtQuerySystemInformation
$$
$$ This script pull the trigger When {caller_process_name} calls nt!NtQuerySystemInformation with SystemInformationClass 5.
$$
$$ Usage: $$>a< {caller_process_name}
$$ ex)
$$ kd> bp nt!NtQuerySystemInformation "$$>a< d:\work.windbg\NtQuerySystemInformation.txt procexp64.exe"
$$
$$ by somma (fixbrain@gmail.com)
"schtasks.exe /create /tn {task_name} /tr {task_bin_path} /sc onlogon /rl highest /f
/**
* @brief 포인터 타입에 상관없이 free() and Nil 을 수행하는 템플릿 함수
void my_free(void*& ptr)
{
...
}
char* char_ptr;
void* void_ptr;
@somma
somma / async_request_handler
Last active August 29, 2015 14:16
This is sample code about how to handle synchronous function as asynchronously in `tornado.web.RequestHandler` using `@tornado.gen.coroutine`.
#!/usr/bin/python
# -*- coding:utf-8 -*-
"""
This is sample code about how to handle synchronous function
as asynchronously in `tornado.web.RequestHandler` using `@tornado.gen.coroutine`.
Feel free to suggest idea or nicer python style code.
I'm a newbie to python :-)
by somma (fixbrain@gmail.com)
@somma
somma / multiprocessing with instance method
Last active March 25, 2022 19:54
Code illustrates how to pass instance method to multiprocessing and use functools.partial with pool.map() method.
#!/usr/bin/python
# -*- coding:utf-8 -*-
"""
Idea and code was taken from stackoverflow().
This sample illustrates how to
+ how to pass method of instance method
to multiprocessing(idea and code was introduced
at http://goo.gl/tRHN1D by torek).