Skip to content

Instantly share code, notes, and snippets.

View jdevera's full-sized avatar

Jacobo de Vera jdevera

View GitHub Profile
@jdevera
jdevera / VundleWeb
Created April 5, 2015 21:35
Visit the github page of a Vundle managed plugin
function! VundleVisitPluginPage(plugin_name)
if !exists('g:vundle#bundles')
echomsg 'Could not find Vundle plugins'
return
endif
if !exists('g:web_browser')
echomsg 'Set your web browser executable to g:web_browser'
return
endif
let uri = ''
@jdevera
jdevera / tmux.terminfo
Last active November 16, 2015 11:37 — forked from tarruda/tmux.terminfo
tmux terminfo for italics
# Custom terminfo for better using tmux with urxvt, 256colors and italics
# Compile/install with `tic tmux.terminfo`, then set $TERM to "tmux"
# (it requires a program that uses `tgetent` to obtain terminal
# information)
tmux|tmux with rxvt-unicode-256color client,
use=rxvt-unicode-256color,
use=screen,
@jdevera
jdevera / ssh-agent-start.sh
Created October 13, 2016 10:03
Function to start an ssh agent or load a running one into the current environment
function ssh-agent-start()
{
local agentfile=~/.ssh/agent
if [[ -f $agentfile ]]
then
source $agentfile > /dev/null
if ps -p "$SSH_AGENT_PID" > /dev/null
then
echo "Agent running with PID $SSH_AGENT_PID"
return
@jdevera
jdevera / invalid_swagger_model.py
Created November 3, 2017 10:34
Create a model object without validation (useful for testing) in a generated Python Swagger Client
def make_invalid_model(model_class, **kwargs):
"""
create a model object bypassing all member validation
:param model_class: the class of the generated model that needs to be instantiated
:param kwargs: all the model parameters, as they would be passed to the constructor
:return: an instance of model_class
"""
def get_default_values(model_class, attributes):
signature = inspect.signature(model_class.__init__)
@jdevera
jdevera / tmuxp.sh
Created February 20, 2018 17:02 — forked from mlgill/tmuxp.sh
Execute parallel processes in arbitrary number of tmux panes
#!/bin/bash
# The "tmuxifier"
# Execute parallel processes in an arbitrary number of tmux panes
# This script requires the path to an existing script to
# execute in parallel. Optionally, the number of threads to
# and the name of the tmux session can be input. If threads
# and session name are not entered, threads are determined
# automatically and session names is set to a default.
@jdevera
jdevera / test_asyncio.py
Created October 25, 2018 10:00
Sync vs Async comparison in Python
import asyncio
import argparse
counter = 0
def next():
global counter
counter += 1
return counter
@jdevera
jdevera / test_chicken.py
Created October 30, 2018 14:30
Example of Pytest parameterization of tests
import re
import pytest
def camel_to_snake(string):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', string)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
CASES = [
@jdevera
jdevera / unnecessary_select.py
Created May 31, 2019 20:17
SqlAchemy spurious select
import uuid
from sqlalchemy import Column, String, create_engine, CHAR
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///:memory:', echo=True)
Base = declarative_base()
@jdevera
jdevera / python_path_fix.ps1
Created June 29, 2019 12:17
Make sure Python 2 is before Python 3 in the Windows PATH
$oldPath = (Get-ItemProperty -Path `
'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' `
-Name PATH).path
$pathParts = $oldPath.split(";")
$python = @()
$other = @()
foreach ($part in $pathParts) {
if ($part -like "*Python*") {
$python += ,$part
}
@jdevera
jdevera / die.py
Last active January 19, 2020 23:05
My most rewritten function: die
import sys
def die(*messages, rc=1):
"""
Print the arguments in stderr and exit with a given return code
"""
print(*messages, file=sys.stderr)
sys.exit(rc)