Skip to content

Instantly share code, notes, and snippets.

View nlitwin's full-sized avatar

Nick Litwin nlitwin

View GitHub Profile
@nlitwin
nlitwin / findNodes.js
Last active September 22, 2019 19:20
Search and Filter DOM nodes using createTreeWalker
function findNodes(options = {}) {
let node
const arr = []
const el = options.el || document.body
const filter = options.filter ? { acceptNode: options.filter } : null
const walk = document.createTreeWalker(el, NodeFilter.SHOW_ELEMENT, filter, false)
while(node = walk.nextNode()) {
arr.push(node)
@nlitwin
nlitwin / currency-formatter.js
Created November 29, 2018 17:14
Format currency "abc12000.33.33" => "12,000,33"
/*
Convert a string to formatted currency.
Example: "abc12000.33.33" => "12,000.33"
*/
export function currencyFormatter(value) {
value = value.toString();
// Clear left side zeros
while (value.charAt(0) === "0") {
value = value.substr(1);
}
@nlitwin
nlitwin / regex.sh
Created August 7, 2018 06:44
Regex from Bash, VIM & Regex from Frontend Masters
# regular expressions
# system tools with regex: grep, sed, perl, vim, less
``` js
'1 two three \n'.replace(/1/, 'one')
```
similar to:
``` sh
@nlitwin
nlitwin / asyncAwaitWithGenerators.js
Last active September 11, 2019 19:43
Implementing async / await with generators
function doWhenDataReceived(value) {
returnNextElement.next(value)
}
function* createFlow() {
const data = yield fetch('http://twitter.com/...')
console.log(data)
}
const returnNextElement = createFlow() // Does not start executing function yet
@nlitwin
nlitwin / ui-state-debugging.js
Created March 2, 2017 22:03
Angular UI $state debugging
$rootScope.$on('$stateChangeStart',function(event, toState, toParams, fromState, fromParams){
console.log('$stateChangeStart to '+toState.to+'- fired when the transition begins. toState,toParams : \n',toState, toParams);
});
$rootScope.$on('$stateChangeError',function(event, toState, toParams, fromState, fromParams){
console.log('$stateChangeError - fired when an error occurs during transition.');
console.log(arguments);
});
$rootScope.$on('$stateChangeSuccess',function(event, toState, toParams, fromState, fromParams){
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
[alias]
# Show verbose output about tags, branches or remotes
tags = tag -l
brs = branch -a
br = branch
remotes = remote -v
# Pretty log output
hist = log --graph --pretty=format:'%Cred%h%Creset %s%C(yellow)%d%Creset %Cgreen(%cr)%Creset [%an]' --abbrev-commit --date=relative
st = status
ci = commit
@nlitwin
nlitwin / git.sh
Last active September 3, 2019 17:19
Useful Git Commands
# Revert to a previous commit
git reset --hard commit_sha
# Create a local branch which tracks from an already created remote branch
git co --track -b branch_name origin/branch_name
# Push local branch to a remote branch with a different name
git push origin local-name:remote-name
# If you want to rename a branch while pointed to any branch