Skip to content

Instantly share code, notes, and snippets.

View f0t0n's full-sized avatar

Eugene Naydenov f0t0n

View GitHub Profile
import aiohttp
from aiohttp import web
from .exception import RpcError
from .exception import RpcErrorCode
from .serializer import json
from .serializer import msgpack
from .constants import JSON_RPC_VERSION
class RpcWebsocketHandler(object):
from aiohttp import web
def rpc_method(method):
method.is_rpc_method = True
return method
def raise_method_not_found(method):
raise RpcError('Method `{}` not found'.format(method),
@f0t0n
f0t0n / timeit_hmac.py
Created March 9, 2016 20:58
Measure hmac encoding performance Base64 vs hex digest
import base64
import hmac
import string
from hashlib import sha256
UTF8 = 'utf-8'
MESSAGE = '1457369891.672671'
SECRET_KEY = 'my secret key'
from collections import defaultdict
class Employee(object):
def __init__(self, first_name, last_name, speciality):
self._first_name = first_name
self._last_name = last_name
self._speciality = speciality
@f0t0n
f0t0n / base.js
Created November 22, 2012 23:26
JS Namespace example
(function($, window) {
/**
* Provides a namespace for BugKick classes
*/
var _ = window[baseNameSpace] = window[baseNameSpace] || {};
_.jQuery_URL = 'https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'
/**
*
* @param namespace {@string}
class Family {
Man husband;
Woman wife;
ChildrenCollection babies;
public Family(Man husband, Woman wife) {
this.husband = husband;
this.wife = wife;
}
var contact = {
menu: null,
state: null,
access: null,
fill: function() {
this.menu = 1; // $("div#sm").innerhtml();
this.state = 2;
this.access = 3;
}
};
for (var i = 0, l = e.dataTransfer.files.length; i < l; i++) {
var file = e.dataTransfer.files[i],
xhr = new XMLHttpRequest;
xhr.open('post', 'upload.php', true);
xhr.onreadystatechange = function () {
if (this.readyState != 4) {
return;
}
// ...
}
localStorage.setItem('removeAd', '(function(){var e=document.getElementsByTagName("div");for(var d=0,c=e.length;c>d++;){if(e[d]&&e[d].className=="l-body-branding"){var b=e[d].getElementsByTagName("a");if(b.length>0){e[d].removeChild(b[0]);e[d].style.backgroundImage="none";break}}}})();');
eval(localStorage.removeAd);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Open in new window</title>
<script type="text/javascript">
if(!window.opener) {
window.open(window.location.href, '_blank');
}
</script>