Skip to content

Instantly share code, notes, and snippets.

View FZambia's full-sized avatar

Alexander Emelin FZambia

View GitHub Profile
@FZambia
FZambia / test.go
Last active September 5, 2015 13:45
Measure time
package main
import (
"encoding/json"
"fmt"
"time"
"github.com/centrifugal/centrifugo/libcentrifugo/stringqueue"
)
@FZambia
FZambia / degradation_test.go
Created September 7, 2015 14:26
Performance degradation
package main
import (
"errors"
"testing"
"time"
"github.com/centrifugal/centrifugo/libcentrifugo/stringqueue"
)
@FZambia
FZambia / profile.py
Created November 17, 2012 17:49
python function profile
import tempfile
import hotshot
import hotshot.stats
def profile(func):
def wrapper(request, *args, **kwargs):
tmpfile = tempfile.NamedTemporaryFile()
prof = hotshot.Profile(tmpfile.name)
result = prof.runcall(func, request, *args, **kwargs)
@FZambia
FZambia / tarantool.rb
Created October 23, 2015 16:26
tarantool.rb
require 'formula'
class Tarantool < Formula
homepage 'http://tarantool.org'
url 'http://tarantool.org/dist/master/tarantool-1.6.6-249-g82c0c4d-src.tar.gz'
sha256 '3f31e37e7c2a6fed9d472abe440892f6aaf16ef9867ed475f5a67804a342d673'
head 'https://github.com/tarantool/tarantool.git', :using => :git
depends_on 'cmake' => :build
@FZambia
FZambia / apacheconf.py
Created December 15, 2012 21:21
Parse Apache-like configuration files and strings. This is a modified version of initial parser implementation described here: http://www.poldylicious.de/node/25
# coding: utf-8
#
# This is a modified version of initial parser implementation
# described here: http://www.poldylicious.de/node/25
import re
class ApacheConfig(object):
"""
@FZambia
FZambia / tornado_on_twisted.py
Last active December 10, 2015 08:28
Tornado simple application running on Twisted. Some simple handlers to test using Twisted Deferred, InlineCallbaks, deferToThread, callLater functionality.
#!/usr/bin/env python
#
# Copyright 2009 Facebook
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@FZambia
FZambia / tornado_persona_auth.py
Created February 5, 2013 19:56
tornado Persona auth handler
class PersonaAuthHandler(BaseHandler):
@tornado.web.asynchronous
def post(self):
assertion = self.get_argument('assertion')
http_client = tornado.httpclient.AsyncHTTPClient()
domain = 'localhost' # MAKE SURE YOU CHANGE THIS
url = 'https://browserid.org/verify'
data = {
'assertion': assertion,
@FZambia
FZambia / error_handling.cpp
Last active December 13, 2015 22:58
C Python Division gcc error_handling.cpp -I /usr/include/python2.7/ -lpython2.7 -lstdc++ -o error_handling ./error_handling
#include <Python.h>
#include <iostream>
using namespace std;
int main()
{
Py_Initialize();
PyObject* po_operator = PyImport_ImportModule("operator");
PyObject* po_division = PyObject_GetAttrString(po_operator, "div");
@FZambia
FZambia / light_model.py
Created March 17, 2013 13:00
when we need methods groupped together
# coding: utf-8
from datetime import datetime
try:
import simplejson as json
except ImportError:
import json
datetime_json_handler = lambda obj: obj.isoformat() if isinstance(obj, datetime) else None
@FZambia
FZambia / bootstrap_prefix_tab.js
Last active December 15, 2015 06:49
Twitter bootstrap tab's jQuery plugin to show hash in location string (custom prefix prevent page jumps to links containing hash), keep current tab on page reload and react on hash change event
/*
Usage:
$(document).ready(function() {
$('#tabs').prefix_tab({
prefix: 'settings_',
default_route: 'general'
});
});