Skip to content

Instantly share code, notes, and snippets.

View dchaplinsky's full-sized avatar

Dmytro Chaplynskyi dchaplinsky

View GitHub Profile
diff --git a/circus/arbiter.py b/circus/arbiter.py
index 006fed3..303b1ab 100644
--- a/circus/arbiter.py
+++ b/circus/arbiter.py
@@ -146,8 +146,8 @@ class Arbiter(object):
self.check_delay)
@classmethod
- def load_from_config(cls, config_file):
- cfg = get_config(config_file)
@dchaplinsky
dchaplinsky / maps.js
Created October 14, 2013 09:40
SVG/VML vector lib to draw simple maps with paths.
window.SVGMap = (function () {
var SM = function (){
return SM.init.apply(SM, arguments);
},
undefined,
doc = document,
win = window,
svgns = 'http://www.w3.org/2000/svg';
// Partially borrowed from RaphaelJS lib by D. Baranosvkiy.
def _transfer_foo(self, foo_id, new_parent_id):
try:
d = foobar.delete().where(
foobar.c.foo_id == foo_id)
self.session.execute(d)
self._add_relationship(new_parent_id, foo_id)
except:
self.session.rollback()
@dchaplinsky
dchaplinsky / memoize.py
Last active December 30, 2015 13:29
Version of @memoize decorator which works with redis backend.
# -*- coding: utf-8 -*-
from functools import partial
from redis import Redis
import settings
redis_client = Redis(host=settings.REDIS_HOST, port=settings.REDIS_PORT,
db=settings.REDIS_DB)
class memoize(object):
@dchaplinsky
dchaplinsky / memoize_decorator.py
Created December 13, 2013 23:53
Weirdest memoize decorator in world (modified version of http://code.activestate.com/recipes/577452-a-memoize-decorator-for-instance-methods/ by Daniel Miller)
# -*- coding: utf-8 -*-
from functools import wraps, partial
class memoize(object):
"""cache the return value of a method
This class is meant to be used as a decorator of methods. The return value
from a given method invocation will be cached on the instance whose method
was invoked. All arguments passed to a method decorated with memoize must
be hashable.
@dchaplinsky
dchaplinsky / redis_memoize.py
Created December 14, 2013 00:11
Memoization to redis with customizable key format.
# -*- coding: utf-8 -*-
from functools import wraps, partial
from redis import Redis
redis_client = Redis()
class redis_memoize(object):
"""cache the return value of a method into redis
@dchaplinsky
dchaplinsky / redis_tools.py
Created December 16, 2013 11:10
Very small but handy tool to export keys from redis to json by wildcards and load them back. Dead simple, no error processing, no warnings, no support for huge datasets (beware, dumping/loading 1GB of data will most likely consume way more ram that you are happy to allocate for that purpose)
import os
import sys
from redis import Redis
import argparse
import simplejson as json
import settings
redis_client = Redis(host=settings.REDIS_HOST, port=settings.REDIS_PORT,
db=settings.REDIS_DB)
@dchaplinsky
dchaplinsky / double_ip_test.py
Created January 4, 2014 00:09
Simple scrapy spider to utilize bindaddress meta param
from scrapy.spider import BaseSpider
from scrapy.conf import settings
from scrapy.http import Request
from random import choice
class DoubleIPSpider(BaseSpider):
name = "double_ip_test"
allowed_domains = ["httpbin.org"]
@dchaplinsky
dchaplinsky / bq6.js
Created January 5, 2014 16:04
bit's quest #6 especially for IlyaF
if (!String.prototype.endsWith) {
Object.defineProperty(String.prototype, 'endsWith', {
enumerable: false,
configurable: false,
writable: false,
value: function (searchString, position) {
position = position || this.length;
position = position - searchString.length;
var lastIndex = this.lastIndexOf(searchString);
return lastIndex !== -1 && lastIndex === position;
@dchaplinsky
dchaplinsky / bq7.js
Created January 5, 2014 16:20
bit's quest #7
/*
* Not only does your robot come equipped with sensors and thrusters. It also
* has a radar that can be used to determine distances.
*
* The radar has two methods:
*
*
* - angle() - the current direction the radar is pointing (0-359)
* - angle(number) - set the radar direction (0-359)
*