Skip to content

Instantly share code, notes, and snippets.

@renanivo
renanivo / validated.py
Last active August 19, 2019 13:16
Validated Metaclass
import typing
import functools
from dataclasses import dataclass
def validated_set(self, value, field_name, field_type):
if not isinstance(value, field_type):
raise TypeError(
@renanivo
renanivo / import-letsencrypt-java.sh
Created May 20, 2019 19:45 — forked from galan/import-letsencrypt-java.sh
Imports the letsencrypt certificates into the java keystore
#!/bin/bash -e
# JAVA_HOME can be passed as argument if not set
if [ ! -d $JAVA_HOME ]; then
JAVA_HOME=${1}
fi
KEYSTORE=$JAVA_HOME/jre/lib/security/cacerts
if [ ! -f "$KEYSTORE" ]; then
echo "Keystore not found in '$KEYSTORE'"
exit 1
@renanivo
renanivo / asyncio.py
Created January 1, 2016 03:34
First steps with prompt toolkit (Python 3)
import asyncio
from prompt_toolkit.shortcuts import prompt_async
@asyncio.coroutine
def my_coroutine():
while True:
result = yield from prompt_async('Say something: ', patch_stdout=True)
print('You said: %s' % result)
@renanivo
renanivo / json2dict
Last active December 30, 2016 17:32
Reads a JSON from STDIN and prints a python dict
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vi: set ft=python :
"""
Convert a JSON from stdin in a python dict. Ex:
$ echo '{"foo": "bar"}' | ./json2dict
> {u'foo': u'bar'}
Install:
@renanivo
renanivo / ctags.patch
Created October 22, 2013 15:19
ctags dev patch
diff --git a/Library/Formula/ctags.rb b/Library/Formula/ctags.rb
index 87dd0ca..9e44c23 100644
--- a/Library/Formula/ctags.rb
+++ b/Library/Formula/ctags.rb
@@ -6,7 +6,7 @@ class Ctags < Formula
sha1 '482da1ecd182ab39bbdc09f2f02c9fba8cd20030'
head do
- url 'https://ctags.svn.sourceforge.net/svnroot/ctags/trunk'
+ url 'https://svn.code.sf.net/p/ctags/code/trunk'
@renanivo
renanivo / delete-merged.sh
Last active December 13, 2015 23:09
delete local merged branches
#!/bin/bash
#usage:
# ./delete-merged.sh ignored_branch1 ignored_branch2 ignored_branch3 ...
FILTER="master\|integra"
for i in "$@"; do
FILTER+="\|$i"
done
git branch --merged | gsed "/$FILTER/d" | gsed 's/\*//' | gsed 's/^/git branch -D/' | sh
@renanivo
renanivo / .vimrc
Created November 1, 2012 21:36
example of auto test with MakeGreen
let g:makegreen_stay_on_file = 1 " do not jump to the test file on errors
autocmd BufNewFile,BufRead *.py compiler nose
autocmd BufWritePost *.py MakeGreen -c nose.cfg
@renanivo
renanivo / gist:3250346
Created August 3, 2012 18:45
get the hash of the last commit of a <file>
git log --format="%h" -n 1 <file>
@renanivo
renanivo / neocomplcache-keymaps.vim
Created April 17, 2012 15:36
use tabs in vim's neocomplcache plugin
" Recommended key-mappings.
" <CR>: close popup and save indent.
inoremap <expr><CR> neocomplcache#smart_close_popup() . "\<CR>"
" <TAB>: completion.
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
" <C-h>, <BS>: close popup and delete backword char.
inoremap <expr><C-h> neocomplcache#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>"
inoremap <expr><C-y> neocomplcache#close_popup()
inoremap <expr><C-e> neocomplcache#cancel_popup()
PS1='\[\033[38m\]\u@\h\[\033[01;34m\] \w \[\033[31m\]`git branch 2>/dev/null | grep \* | head -1 | sed "s/\* //g" | awk "{ print \"(\"\\\$1 \")\" }"`\n\[\033[29m\]$\[\033[00m\] '