Skip to content

Instantly share code, notes, and snippets.

View ei-grad's full-sized avatar

Andrew Grigorev ei-grad

View GitHub Profile
@ei-grad
ei-grad / ListController.js
Last active February 1, 2018 02:58
Exception handling in async/await sailsjs controllers
/**
* ListController
*
* @description :: Server-side logic for managing lists
* @help :: See http://sailsjs.org/#!/documentation/concepts/Controllers
*/
import _ from 'lodash';
class AsyncController {
[alias]
st = status
ci = commit
co = checkout
br = branch
d = diff
dc = diff --cached
lg = log -p
lol = log --graph --decorate --pretty=oneline --abbrev-commit
lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
@ei-grad
ei-grad / twisted_pubsub.py
Last active August 29, 2015 14:22
PubSub pattern for twisted
from twisted.internet.defer import DeferredQueue
class PubSub(object):
def __init__(self):
self.queues = []
def subscribe(self, queue=None):
if queue is None:
@ei-grad
ei-grad / .hgrc
Last active August 29, 2015 14:18
hgrc
[ui]
username = Andrew Grigorev <[email protected]>
[extensions]
color =
pager =
[alias]
lol = log -G --template '{label("log.changeset", "{node|short}")} {desc|firstline}'
lg = log --patch --template '{label("log.changeset", "{node}")}\n{label("log.author", "Author: {author}")}\n{label("log.date", "Date: {date|date}\n\t{firstline}")}\n'
#!/usr/bin/env python
# encoding: utf-8
import time
import sys
import threading
import tornado.web
import tornado.ioloop
import tornado.gen
from functools import partial
from tornado.log import app_log as log
from twisted.internet task, reactor, defer
def sleep(delay):
return task.deferLater(reactor, delay, lambda: None)
def sleep(delay):
d = defer.Deferred()
reactor.callLater(delay, d.callback, None)
@ei-grad
ei-grad / restore_commit_times.py
Last active September 30, 2016 13:44
Restore files mtime from git commits
#!/usr/bin/env python
# encoding: utf-8
import logging
import os
import sys
import git
log = logging.getLogger(__name__)
@ei-grad
ei-grad / fork.py
Last active August 29, 2015 14:14
Create thread vs. create process in Linux (both use the clone syscall)
from os import fork
print fork()
# clone(child_stack=0, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=...)
from Conntrack import ConnectionManager, NFCT_O_XML
from lxml.etree import fromstring
def filter_nat(xml):
d = fromstring(xml)
orig_src = d.xpath("..//meta[@direction='original']/layer3/src/text()")[0]
repl_dst = d.xpath("..//meta[@direction='reply']/layer3/dst/text()")[0]
return orig_src != repl_dst
@ei-grad
ei-grad / cp-redis.py
Last active August 29, 2015 14:07
Copy keys from one Redis server to another
#!/usr/bin/env python
# encoding: utf-8
# the default py2.7 print doesn't accept 'file' argument
from __future__ import print_function
import sys
from redis import Redis