Skip to content

Instantly share code, notes, and snippets.

View ryanve's full-sized avatar
📶
stay free

deepskyblue ryanve

📶
stay free
View GitHub Profile
@ryanve
ryanve / .gitconfig
Last active May 11, 2022 09:17
git aliases
[alias]
co = checkout
ci = commit
ca = commit --amend
cia = commit -a
can = commit --amend --no-edit
com = checkout master
st = status
s = status --short
b = branch
@ryanve
ryanve / blacklist.js
Created May 9, 2017 02:11
JavaScript regex to blacklist words
/^(?!(corn|bread)$).+/.test('corn') // false (blacklisted)
/^(?!(corn|bread)$).+/.test('bread') // false (blacklisted)
/^(?!(corn|bread)$).+/.test('cornbread') // true (not blacklisted)
/^(?!(corn|bread)$).+/.test('corndog') // true (not blacklisted)
/^(?!(corn|bread)$).+/.test('read') // true (not blacklisted)
@ryanve
ryanve / .gitignore
Created May 22, 2020 20:45
ignore image file formats with .gitignore
.DS_Store
*.[gtGT][iI][fF]
*.[jJ][pP][gG]
*.[jJ][pP][eE][gG]
*.[hH][eE][iI][cfCF]
*.[pP][nN][gG]
*.[wW][eE][bB][pP]
@ryanve
ryanve / pure.js
Created April 19, 2020 05:17
Create fresh pure new array from the indexes of an array or object based on the length
function pure(like) {
var fresh = []
var i = ~~like.length
while (i-->0) fresh[i] = like[i]
return fresh
}
@ryanve
ryanve / breakpoint.js
Last active January 17, 2020 17:20
JavaScript: Get the current media query breakpoint for a CSS feature.
(function(root, name, make) {
if (typeof module != 'undefined' && module['exports']) module['exports'] = make();
else root[name] = make();
}(this, 'breakpoint', function() {
/**
* @link http://gist.github.com/ryanve/7924792
* @param {string} feature range feature name e.g. "width"
* @param {string=} unit CSS unit for feature e.g. "em"
* @param {number=} init initial guess
@ryanve
ryanve / log-tab-focus.js
Last active May 24, 2019 21:50
Log :focus element each time tab key is pressed
document.addEventListener('keyup', function(e) {
9 != e.keyCode || e.metaKey || e.ctrlKey || console.log(document.activeElement)
}, false)
@ryanve
ryanve / IIFE.md
Last active February 2, 2019 00:30
JavaScript closure patterns

IIFE (Immediately Invoked Function Expression)

!function() {
  // Code in here is encapsulated
}();

Note that ! or + is safer than () because () could invoke preceding code.

@ryanve
ryanve / observer.js
Created February 16, 2017 04:01
Mutation observer example listening to any attribute changes
!function() {
var emitter = {
emit: console.dir.bind(console)
}
function emit(mutation) {
var target = mutation.target
var name = mutation.attributeName
var value = target.getAttribute(name)
@ryanve
ryanve / log-focus.js
Created March 3, 2017 21:57
Log :focus element whenever focus changes
document.addEventListener('focusin', function() {
console.log(document.activeElement)
}, false)