Skip to content

Instantly share code, notes, and snippets.

kevinlynx kevinlynx

Block or report user

Report or block kevinlynx

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kevinlynx
kevinlynx / thread_id_pool.cpp
Last active Feb 16, 2018
simple read/write thread memory gc
View thread_id_pool.cpp
#include "thread_id_pool.h"
#include <pthread.h>
#include <assert.h>
static pthread_key_t s_tkey;
static pthread_once_t s_tkey_once;
static void freeKey(void *p)
{
ThreadIdPool::TVal *val = (ThreadIdPool::TVal*) p;
@kevinlynx
kevinlynx / dummy_httpd.py
Created Mar 3, 2015
create a dummy tcp/http server in python to accept connections only, which can be used in unittest, to mock a tcp/http server
View dummy_httpd.py
# dummy_httpd.py
# based on python 2.7
import BaseHTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler
from SocketServer import ThreadingMixIn
import threading
import time
class ThreadedHTTPServer(ThreadingMixIn, BaseHTTPServer.HTTPServer):
daemon_threads = True
View stl-data-impl.cpp
#include <stdio.h>
#include <string>
#include <map>
#include <vector>
#include <list>
void ds_str_i(void *p) {
char **raw = (char**)p;
char *s = *raw;
size_t len = *(size_t*)(s - sizeof(size_t) * 3);
View Makefile
all:
g++ -o thread -g -Wall -lpthread -ldl thread.cpp -DTEST_DTV_OVERFLOW
g++ -rdynamic -shared -fPIC dso_shared.cc -o shared.so
mkdir -p so
for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do cp shared.so so/shared-$$i.so; done
clean:
rm *.so so/*.so
@kevinlynx
kevinlynx / localfn.cpp
Last active Aug 29, 2015
define local function in c++
View localfn.cpp
#define deflocal(name, ret, body) \
struct name { \
ret operator() body \
}
#define callocal(name) name()
int main() {
// example
deflocal(hello, char*, (const char *from, const char *to) {
View threadpool-dynamic.hpp
_status :
HANGUP, // nothing to do
INCING, // increasing threads
DECING, // decreasing threads
manager_thread_proc {
while (_run) {
CondtionLock guard(ctrlCond);
View smooth.js
$('#container').highcharts({
chart: {
zoomType: 'x'
},
title: {
text: 'service latency sample'
},
subtitle: {
text: document.ontouchstart === undefined ?
'Click and drag in the plot area to zoom in' :
@kevinlynx
kevinlynx / actor.cpp
Last active Aug 29, 2015
actor model
View actor.cpp
class Printer : public Theron::Actor
{
public:
// Constructor, passes the framework to the baseclass.
Printer(Theron::Framework &framework) : Theron::Actor(framework)
{
// Register the message handler.
RegisterHandler(this, &Printer::Print);
}
View futureList.scala
package lichecker
import scala.concurrent._
import scala.concurrent.duration.Duration
import ExecutionContext.Implicits.global
import com.codemacro.AsyncTask
object FutureList {
def run[T, T2](args: List[T], fn: => T => T2, max: Int): List[T2] = {
View reverse-str.c
int length(char *str) {
int s = 0;
for (; *str; ++str) ++s;
return s;
}
char *reverse(char *str) {
int size = length(str);
for (int i = 0; i < size / 2; ++i) {
str[i] ^= str[size - i - 1];
You can’t perform that action at this time.