Skip to content

Instantly share code, notes, and snippets.

View igorsobreira's full-sized avatar

Igor Sobreira igorsobreira

View GitHub Profile

Keybase proof

I hereby claim:

  • I am igorsobreira on github.
  • I am igorsobreira (https://keybase.io/igorsobreira) on keybase.
  • I have a public key whose fingerprint is 18D1 8D60 1540 D1E9 AAB0 747A 06EA A27A 4328 5FA7

To claim this, I am signing this object:

@igorsobreira
igorsobreira / gist:5059143
Last active December 14, 2015 08:39
Context manager to help monkeypatch global variables used by a function under test. Uses the mock library
import types
import mock
def patch_func_globals(func, **vars):
'''
Monkeypatches global variables used by a function or method
It's useful if you need to mock a global function or variable
your function uses
def patch_func_globals(func, **vars):
'''
Monkeypatches global variables used by a function or method
It's useful if you need to mock a global function or variable
your function uses
Usage:
with patch_func_globals(your_func, used_func=mocked_func):
def assert_file_like_object(self, obj):
interface = set(('open', 'close', 'encoding', 'fileno', 'flush', 'isatty',
'newlines', 'read', 'readinto', 'readline', 'readlines',
'seek', 'softspace', 'tell', 'truncate', 'write', 'writelines',
'xreadlines', 'name'))
methods = set(dir(obj))
has_valid_api = interface.issubset(methods)
missing_methods = ', '.join(interface.difference(methods))
@igorsobreira
igorsobreira / hexdump.c
Created May 6, 2012 02:39
Hexdump, useful to debug C code. From ##c irc channel
/* HEXDUMP */
#include <stddef.h>
#include <stdio.h>
#include <ctype.h>
void hexdump(const void * memory, size_t bytes) {
const unsigned char * p, * q;
int i;
class _O(dict):
"""Makes a dictionary behave like an object."""
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError(name)
def __setattr__(self, name, value):
self[name] = value
(setq make-backup-files nil)
(setq inferior-lisp-program "clisp")
(add-to-list 'load-path "~/elisp")
(add-to-list 'load-path "~/elisp/emacs-nav")
(require 'magit)
(require 'actionscript-mode)
(require 'go-mode-load)
(require 'ess-site)
[merge]
tool = opendiff
[color]
mbranch = auto
diff = auto
interactive = auto
status = auto
[alias]
st = status --short
cm = commit -m
llg = log --graph --color --decorate --date-order
lg = log --graph --color --pretty='format:%C(yellow)%h%C(cyan)%d %Creset%s %C(blue)%an, %ar' --date-order
lga = log --graph --color --pretty='format:%C(yellow)%h%C(cyan)%d %Creset%s %C(blue)%an, %ar' --date-order --all
co = checkout
#INPUT = 'example.txt'
INPUT = "A-large-practice.in"
def main():
file_obj = open(INPUT)
cases = int(file_obj.readline())
for i in range(cases):