Skip to content

Instantly share code, notes, and snippets.

View samvk's full-sized avatar
🗣️
“Ok Google, talk to Sam's portfolio”

Sam Kauffman samvk

🗣️
“Ok Google, talk to Sam's portfolio”
View GitHub Profile
@samvk
samvk / escapeXml.js
Created February 26, 2019 20:15
Another escapeXml example - with object notation shorthand and with no repeating loops
const escapeXml = (str) => (
str.replace(/[<>&'"]/g, (char) => ({
'<': '&lt;',
'>': '&gt;',
'&': '&amp;',
"'": '&apos;',
'"': '&quot;',
}[char]))
);
@samvk
samvk / .inputrc
Created December 24, 2018 04:39
Better git bash
# mappings to have up and down arrow searching through history:
"\e[A": history-search-backward
"\e[B": history-search-forward
# mappings to have left and right arrow go left and right:
"\e[C": forward-char
"\e[D": backward-char
# mapping to have [Tab] and [Shift]+[Tab] to cycle through all the possible completions:
"\t": menu-complete
"\e[Z": menu-complete-backward
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@samvk
samvk / .bashrc
Last active April 1, 2019 20:31
Bash functions
# add to your home directory (https://coderwall.com/p/_-ypzq/git-bash-fixing-it-with-alias-and-functions)
function gitbranch() {
~/Projects/market;git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset);(%(color:green)%(committerdate:relative)%(color:reset))' | column -t -s ';'
}
function gitgui() {
cd ~/Projects/market; git gui;
}
@samvk
samvk / strongpassword.js
Created February 24, 2017 21:47
StrongPassword class
/* global $ */
/**
* Set the rules for a strong password.
* @param {Object} rules
* @param {(number|{value:number,message:string})} [rules.min=8] minimum character length (optional custom error message)
* @param {(boolean|{value:boolean,message:string})} [rules.number=false] must have number? (optional custom error message)
* @param {(boolean|{value:boolean,message:string})} [rules.uppercase=false] must have uppercase? (optional custom error message)
* @param {(boolean|{value:boolean,message:string})} [rules.special=false] must have special char? (optional custom error message)
* @param {(RegExp[]|{value:RegExp[],message:string})} [rules.blacklist=RegExp[]] array of banned password patterns (optional custom error message)
@samvk
samvk / ContextCmder-Disable.reg
Last active January 18, 2017 14:21 — forked from jojobyte/ContextCmder-Disable.reg
Cmder Context (Right-Click) Menu for Windows 7/8
Windows Registry Editor Version 5.00
[-HKEY_CLASSES_ROOT\Directory\Background\shell\Cmder]
[-HKEY_CLASSES_ROOT\Directory\shell\Cmder]
@samvk
samvk / simple-pubsub.js
Last active October 27, 2016 02:48
A simple, chainable, static PubSub class for Javascript
const eventStore = {};
export default class Events {
static on(eventName, handler) {
eventStore[eventName] = eventStore[eventName] || [];
eventStore[eventName].push(handler);
return this;
}
static trigger(eventName, data) {