Skip to content

Instantly share code, notes, and snippets.

@yangacer
yangacer / sqlite3_create_function_v2.c
Created February 3, 2013 16:36
sqlite3_create_functoin_v2 comment
int sqlite3_create_function_v2(
sqlite3 *db, // db connection
const char *zFunctionName, // function name
int nArg, // number of argument this function takes. -1 for arbitrary numbers
int eTextRep, // text encoding, e.g. SQLITE_UTF8 or SQLITE_ANY
void *pApp, // pinter to function context
void (*xFunc)(sqlite3_context*,int,sqlite3_value**), // a scalar function implementation
void (*xStep)(sqlite3_context*,int,sqlite3_value**), // a aggregate function implementation
void (*xFinal)(sqlite3_context*), // the same pointer with previous one
void(*xDestroy)(void*) // destroy function context
@yangacer
yangacer / OOFuse.cpp
Last active December 19, 2015 17:09
Glue class member function with fuse API.
#define FUSE_USE_VERSION 26
#include <fuse.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include "glue.hpp"
struct hello_fs
@yangacer
yangacer / fsevent.cpp
Created July 19, 2013 06:28
Minimum example of FSEvent (no thread creation)
#include <CoreServices/CoreServices.h>
#include <iostream>
void callback(
ConstFSEventStreamRef stream,
void *callbackInfo,
size_t numEvents,
void *evPaths,
const FSEventStreamEventFlags evFlags[],
const FSEventStreamEventId evIds[])
@yangacer
yangacer / impl.c
Created January 2, 2014 02:56
Member function with pure C
#include "impl.h"
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
struct obj_impl
{
int a;
};
@yangacer
yangacer / sortable.js
Last active August 29, 2015 14:02
Mini sort table with jquery
function sortable(table_dom, column_types, default_ordering) {
var rows = $(table_dom).find('tbody tr')
var dataset = [];
for (var i = 0; i < rows.length; ++i) {
var vals = $(rows[i]).find('td').toArray().map(function(v){
// console.log(arguments);
return v.innerText;
});
dataset.push(vals);
@yangacer
yangacer / jsonrpc_via_requests.py
Created June 10, 2015 10:10
JSONRPC over HTTP client invoker (within requests library)
import json
import requests
import functools
"""
Example:
cli = jsonrpc('http://rpcserver.com:6666')
try:
resp = cli.echo(hello='world')
@yangacer
yangacer / utf8_to_unicode_cp.cpp
Last active April 19, 2016 16:10
UTF8 to Unicode codepoint
#include <iostream>
#include <string>
using namespace std;
uint32_t to_unicode(size_t *bytes, char const *utf8)
{
if (!utf8 || !*utf8) {
*bytes = 0;
return 0;
@yangacer
yangacer / copy_move_observer.cpp
Last active July 16, 2016 13:47
Utility for observing C++ object copying/moving
#include <vector>
#include <string>
#include <iostream>
using namespace std;
struct obs {
obs() : m_mv(0), m_cp(0) { m_regs.insert(this); }
obs(obs const &cp) { m_regs.insert(this); m_cp++; m_total_cp++;}
obs(obs &&mv) { m_regs.insert(this); m_mv++; m_total_mv++;}
@yangacer
yangacer / profiler.cpp
Created July 16, 2016 14:07
Mini C++ profiler (support multicore)
struct profiler {
profiler() : m_start{chrono::high_resolution_clock::now()} {
}
size_t til_now() const {
return chrono::duration_cast<chrono::milliseconds>(
chrono::high_resolution_clock::now() - m_start).count();
}
chrono::high_resolution_clock::time_point m_start;
@yangacer
yangacer / lru_sub_opt.cpp
Created September 11, 2016 06:20
Sloppy LUR impl
#include <iostream>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
using namespace std;
template<typename T>
struct lru {