Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Color Escape sequence to use in bash scripts
RCol='\e[0m' # Text Reset
# Regular Bold Underline High Intensity BoldHigh Intens Background High Intensity Backgrounds
Bla='\e[0;30m'; BBla='\e[1;30m'; UBla='\e[4;30m'; IBla='\e[0;90m'; BIBla='\e[1;90m'; On_Bla='\e[40m'; On_IBla='\e[0;100m';
Red='\e[0;31m'; BRed='\e[1;31m'; URed='\e[4;31m'; IRed='\e[0;91m'; BIRed='\e[1;91m'; On_Red='\e[41m'; On_IRed='\e[0;101m';
Gre='\e[0;32m'; BGre='\e[1;32m'; UGre='\e[4;32m'; IGre='\e[0;92m'; BIGre='\e[1;92m'; On_Gre='\e[42m'; On_IGre='\e[0;102m';
Yel='\e[0;33m'; BYel='\e[1;33m'; UYel='\e[4;33m'; IYel='\e[0;93m'; BIYel='\e[1;93m'; On_Yel='\e[43m'; On_IYel='\e[0;103m';
Blu='\e[0;34m'; BBlu='\e[1;34m'; UBlu='\e[4;34m'; IBlu='\e[0;94m'; BIBlu='\e[1;94m'; On_Blu='\e[44m'; On_IBlu='\e[0;104m';
@nestoralonso
nestoralonso / memoize-multiple-arguments.js
Created January 20, 2020 23:48
Memoize High Order Function that can handle multiple and nested arguments
function equals(a, b) {
if (a === b) return true;
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
if (!a || !b || (typeof a !== 'object' && typeof b !== 'object')) return a === b;
if (a.prototype !== b.prototype) return false;
const keys = Object.keys(a);
if (keys.length !== Object.keys(b).length) return false;
return keys.every(k => equals(a[k], b[k]));
};
@nestoralonso
nestoralonso / react-recursive-render-tree-state.html
Created January 13, 2020 01:18
Renders a Tree with state (a node renders children nodes that render children nodes...)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Recursive Component in React</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.11.0/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.11.0/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.21.1/babel.min.js"></script>
</head>
@nestoralonso
nestoralonso / pattern-match.rs
Last active October 13, 2018 02:07
Rust Pattern matching Sample
#[derive(Debug)]
struct Action {
_type: String,
amount: u32
}
fn update_counter(state:u32, action: Action) -> u32 {
let Action {_type, amount} = action;
println!("{} {} {}", _type, amount, state);
@nestoralonso
nestoralonso / prepare-commit-msg.py
Created August 7, 2018 15:34
prepare the commit log message using the JIRA Ticket code
#!/usr/bin/env python3
#
# prepare the commit log message using the JIRA Ticket code.
#
# Given that the your branch is called something like bugfix/PROJETO-21012
# Then your commit message will look like
#
# [PROJETO-21012] Fixes the bug
#
@nestoralonso
nestoralonso / getReactComponentInstance.js
Last active July 15, 2018 00:45
get react object from the DOM
getReactElement = (dom) => {
for (var key in dom) {
if (!key.startsWith("__reactInternalInstance$")) continue;
var compInternals = dom[key]._currentElement;
var compWrapper = compInternals._owner;
var comp = compWrapper._instance;
return comp;
}
@nestoralonso
nestoralonso / .tmux.conf
Created January 26, 2018 22:26
Minimal tmux conf
# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# Start window numbering at 1
set -g base-index 1
@nestoralonso
nestoralonso / simple_snippets.js
Created January 8, 2018 04:37
Useful snippets
// HOF to do an automatic catch over functions that return promises
const handleErrors = fn => (...args) => fn(...args).catch(err => console.error(`Ohh the horror ${err}`))
// A buggy sleep
const riskySleep = (ms) =>
new Promise((resolve, reject) => {
if (Math.random() < 0.7) { reject(ms) }
setTimeout(() => resolve(ms), ms)
});
@nestoralonso
nestoralonso / note.bash
Created October 2, 2017 21:48
Take notes on bash (add to .bashrc)
#Taken from https://dev.to/ricardomol/note-taking-from-the-command-line-156
note() {
if [ ! -z "$1" ]; then
echo $(date +"%Y%m%d-%H%M%S") $@ >> $HOME/notes/TempNotes.wiki
else
echo $(date +"%Y%m%d-%H%M%S") "$(cat)" >> $HOME/notes/TempNotes.wiki
fi
}
var webdriverio = require("webdriverio");
var options = {
desiredCapabilities: {
browserName: "chrome"
}
};
var client = webdriverio.remote(options);