Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@khayrov
khayrov / serialize.py
Last active January 26, 2022 02:17
Serializable transactions and retry in SQLAlchemy
from sqlalchemy import (create_engine, event,
Column, Integer,
ForeignKey)
from sqlalchemy import event
from sqlalchemy.orm import sessionmaker, scoped_session
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base, declared_attr
from sqlalchemy.exc import DBAPIError
import sqlite3
@khayrov
khayrov / dropcache.c
Created January 28, 2013 12:05
Try to remove file from page cache
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@khayrov
khayrov / Makefile
Created September 10, 2012 06:55
luabind example: export Bullet vector algebra and inheriting C++ classes in Lua
CXXFLAGS=-O2 -Wall -g -fPIC $(shell pkg-config --cflags lua5.1 luabind) -I/usr/local/include/bullet
LDFLAGS=-lstdc++ $(shell pkg-config --libs lua5.1 luabind) -lLinearMath
all: luavector
luavector: luavector.o
luavector.o: luavector.cpp
.PHONY: clean
@khayrov
khayrov / Lexer.java
Created August 28, 2012 16:25 — forked from lucassmagal/Lexer.java
Ragel with Java
// line 1 "Lexer.rl"
public class Lexer {
// line 19 "Lexer.rl"
// line 10 "Lexer.java"
private static byte[] init__simple_lexer_actions_0()
@khayrov
khayrov / Makefile
Created July 21, 2012 20:40
stock quote parsing with Ragel
CFLAGS=-O2
CXXFLAGS=-O2
all: parser
parser.cpp: parser.rl
ragel -G2 $^ -o $@
parser.o: parser.cpp RawQuote.h
#include <stdio.h>
struct B;
struct A
{
struct B *ptr;
};
struct B
@khayrov
khayrov / capture.c
Created March 6, 2012 12:21
Packet capture
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
@khayrov
khayrov / wcl.c
Created November 11, 2011 15:34
fast wc -l
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#define BUF_SIZE 1048576
@khayrov
khayrov / simplecalc.hs
Created May 15, 2011 17:20
very simple expression parser
expr :: String -> (Double, String)
expr s = expr1 x rest where (x, rest) = term s
expr1 lhs ('+' : s) = expr1 (lhs + x) rest where (x, rest) = term s
expr1 lhs ('-' : s) = expr1 (lhs - x) rest where (x, rest) = term s
expr1 lhs s = (lhs, s)
term s = term1 x rest where (x, rest) = factor s
term1 lhs ('*' : s) = term1 (lhs * x) rest where (x, rest) = factor s
term1 lhs ('/' : s) = term1 (lhs / x) rest where (x, rest) = factor s
term1 lhs s = (lhs, s)
factor ('(' : s) = (x, rest) where (x, ')' : rest) = expr s