Skip to content

Instantly share code, notes, and snippets.

View lfarroco's full-sized avatar
🌱

Leonardo Farroco lfarroco

🌱
View GitHub Profile
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
set-window-option -g mode-keys vi
bind-key -n C-h if-shell "$is_vim" "send-keys C-h" "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j" "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k" "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l" "select-pane -R"
bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
//Copy and paste in your console
/** Calls a reducing function recursively in each item of the array.
If the item is an array, it gets reduced - otherwise, the item is returned.
*/
function flatten(maybeArray){
if(Array.isArray(maybeArray)){
const initialValue = []
return maybeArray.reduce(
(accumulator,current) => accumulator.concat( flatten(current) ),
@lfarroco
lfarroco / .vimrc
Last active March 22, 2024 23:10
my .vimrc
let mapleader = "\<Space>"
" Some servers have issues with backup files, see #649
set nobackup
set nowritebackup
" Having longer updatetime (default is 4000 ms = 4s) leads to noticeable
" delays and poor user experience
set updatetime=300
@lfarroco
lfarroco / .bashrc
Created April 6, 2018 23:14
Functions added to my .bashrc
#svim: searches for an expression in a git repo and edits each result in a tab
function svim() {
RES="$(git grep -l "$1" | wc -l)"
CONF_MSG="Do you wish to edit these ${RES} results? (y/n)"
read -p "${CONF_MSG}" choice;
case "$choice" in
y|Y ) vim -p `git grep -l "$1"`;;
n|N ) echo "exiting";;
* ) echo "exiting";
esac
@lfarroco
lfarroco / multiList.elm
Last active October 24, 2017 16:53
Elm - creating a list with multiple value Types
type MultiValue
= StringValue String
| IntegerValue Int
--... add other possibilities here
myList : List MultiValue
myList =
[ StringValue "a"
@lfarroco
lfarroco / oneHotEncoding.py
Last active May 21, 2017 14:23
One-hot Encoding using Pandas DataFrames
import pandas as pd
data = pd.DataFrame([
["Team A",1,0],
["Team B",0,1]],
columns=["Team","Attribute A","Attribute B"])
pd.get_dummies(data)
#Output will be:
# Attribute A Attribute B Team_Team A Team_Team B
//Extract SVG: three lines of JavaScript that allow you to extract the contents
//of a SVG <object> tag into your DOM
//After the extraction you are able to select the inner elements of the SVG with CSS and JS
//It replaces the original <object> tag with its raw SVG
//el: a DOM element
//eg. el = document.querySelector('#elementId')
//extractSvg(el)
//You might also place an onload attribute in your object to force its extraction when possible