Skip to content

Instantly share code, notes, and snippets.

View inirudebwoy's full-sized avatar
🏗️
putting things on top of other things

Michael Klich inirudebwoy

🏗️
putting things on top of other things
View GitHub Profile
@inirudebwoy
inirudebwoy / gist:ffddb854ce537dd21053
Created February 6, 2015 15:44
Pretty print json in curl.
function p_curl() {
{
curl "$@"
}|python -mjson.tool
}
@inirudebwoy
inirudebwoy / Vagrantfile
Created February 11, 2015 12:53
Install Ubuntu 10.04 with couchdb 1.2.1
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box_url = "http://files.vagrantup.com/lucid64.box"
config.vm.box = "ubuntu/lucid64"
config.vm.network "forwarded_port", guest: 5984, host: 5984
config.vm.provision "shell", inline: <<-SHELL
sudo apt-get update
sudo apt-get install -y python-software-properties curl
@inirudebwoy
inirudebwoy / api_check_logger.py
Last active August 29, 2015 14:15
Decorator logging calls with specified arguments, useful when deprecating API's
import logging
from inspect import getouterframes, currentframe
from functools import wraps
logger = logging.getLogger(__name__)
def _get_caller_details(curframe):
"""
Helper retrieving caller details from current frame
@inirudebwoy
inirudebwoy / initial_data.json
Last active August 29, 2015 14:17
Admin user initial data for Django < 1.7, password is 'admin'
[{"model": "auth.user",
"pk": 1,
"fields":
{"username": "admin",
"first_name": "",
"last_name": "",
"is_active": true,
"is_superuser": true,
"is_staff": true,
"password": "pbkdf2_sha256$15000$TrGrqtzwNJUa$omLG886xVSLNxYOvjrceDbWQS5ISmzyPM9ka0rAhu3Y=",
class SettingsReader:
def __init__(self, opts, config, settings):
self.opts = opts
self.config = config
self.settings = settings
def __contains__(self, key):
if (key in self.opts or
key in self.config or
key in self.settings):
@inirudebwoy
inirudebwoy / setup.py
Created February 2, 2016 15:45
Retrievinng version number in setup.py
def get_version():
local_vars = {}
try:
execfile('src/imagination/objectid_manager/__init__.py',
{},
local_vars)
except NameError:
# python3.x does not provide execfile
with open('src/imagination/objectid_manager/__init__.py') as f:
exec(f.read(), {}, local_vars)
def kwargs_default(params):
"""Decorator for setting default keyword parameters
@kwargs_default((('number_of_chickens', 3),))
will add param 'number_of_chickens' with value of 3 into kwargs.
:param params: tuple of tuples consiting of name of parameter and value
:type params: tuple of tuples with str and any ((str, any), (str, any), ...)
"""
@inirudebwoy
inirudebwoy / retry.py
Last active July 22, 2016 14:25
Decorator retrying connection with the callback on failure
def retry(retries=3, callback_on_failure=None):
"""Retry requests method and run callback on failure
Decorator will retry the decorated function for specified number of times,
default is 3. If there is a callback passed, it will be called before
calling the decorated function again. Callback allows to perform cleanups,
clear the credentials, etc.
Decorator will only work with functions that return requests.Request
object, if decorated method returns other object result is returned with
out retrying.
@inirudebwoy
inirudebwoy / 0_reuse_code.js
Created September 10, 2016 15:45
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
alias halt_all_vagrants="vagrant global-status | awk '/running/{print $1}' | xargs -r -d '\n' -n 1 -- vagrant halt"