Skip to content

Instantly share code, notes, and snippets.

View k-bx's full-sized avatar

Kostia R k-bx

View GitHub Profile
@k-bx
k-bx / mock_descriptor_issue.py
Created May 4, 2012 19:14
mock descriptor issue
from mock import patch
class RealOne(object):
def quack(self):
print '> quack'
class BarDescriptor(object):
def __get__(self, obj, type=None):
(defun un-camelcase-string (s &optional sep start)
"Convert CamelCase string S to lower case with word separator SEP.
Default for SEP is a hyphen \"-\".
If third argument START is non-nil, convert words after that
index in STRING."
(let ((case-fold-search nil))
(while (string-match "[A-Z]" s (or start 1))
(setq s (replace-match (concat (or sep "-")
(downcase (match-string 0 s)))
@k-bx
k-bx / gist:2660237
Created May 11, 2012 14:51
mock autospeccing harming
>>> from mock import create_autospec
>>> class A(object):
... def __init__(self, data):
... self.cleaned_data = data
...
>>> m_A = create_autospec(A)
>>> m_A({'a': 'b'}).cleaned_data
Traceback (most recent call last):
File "<ipython-input-5-66064b709d22>", line 1, in <module>
m_A({'a': 'b'}).cleaned_data
@k-bx
k-bx / sublime-text-2.el
Created June 10, 2012 22:02
sublime text 2 like theme for emacs
(defun sublime-text-2 ()
(interactive)
(color-theme-install
'(sublime-text-2
((background-color . "#171717")
(background-mode . light)
(border-color . "#1a1a1a")
(cursor-color . "#fce94f")
(foreground-color . "#cfbfad")
(mouse-color . "black"))
class A(object):
def __init__(self):
self.foo = 'foofoo'
def print_foo(self):
print self.foo
pf = A().print_foo
pf()
@k-bx
k-bx / hem.js
Created July 18, 2012 11:49
hem error
#!/usr/bin/env node
var path = require('path'),
Module = require('module'),
fs = require('fs');
if (path.existsSync('./slug.js')) {
return Module._load('./slug.js');
}
require('../lib/hem').exec();
@k-bx
k-bx / previous.el
Created October 15, 2012 16:32
emacs get into previous window
;;;; get back
(defun frame-bck()
(interactive)
(other-window -1))
(global-set-key [?\C-x ?\O] 'frame-bck)
@k-bx
k-bx / python_get_runcmd_for_current_unit_test.el
Created December 7, 2012 14:02
Emacs Lisp function to get nose path to current python unit-test
(defun python-get-runcmd-for-current-unit-test ()
"Runs current python unit-test."
(interactive)
(defun get-test-name ()
(setq before-everything (point))
(setq def-start (search-backward "def "))
(forward-char (length "def "))
(setq name-start (point))
# -*- coding: utf-8 -*-
from collections import defaultdict
def get_row_key(row):
return str(row[4] + row[15])
def main():
Wed Jan 23 12:01 2013 Time and Allocation Profiling Report (Final)
duplicates +RTS -p -RTS /home/kb/Ubuntu One
total time = 44.42 secs (44417 ticks @ 1000 us, 1 processor)
total alloc = 4,068,850,736 bytes (excludes profiling overheads)
COST CENTRE MODULE %time %alloc
insert Data.IxSet.Ix 33.1 13.9