Skip to content

Instantly share code, notes, and snippets.

View justsml's full-sized avatar
🔥
#BLM

Dan Levy justsml

🔥
#BLM
View GitHub Profile
@justsml
justsml / object-watch.js
Created April 1, 2012 22:48 — forked from eligrey/object-watch.js
object.watch polyfill
// Cross-browser object.watch and object.unwatch
// object.watch
if (!Object.prototype.watch) {
Object.prototype.watch = function (prop, handler) {
var oldval = this[prop], newval = oldval,
getter = function () {
return newval;
},
setter = function (val) {
var car_options = 0x5; // binary 0101
var LEATHER_SEATS = 0x1; // 0001
var TURBO = 0x2; // 0010
var HID_LIGHTS = 0x4; // 0100
var SPORT_KIT = 0x8; // 1000
var daves_car = LEATHER_SEATS | HID_LIGHTS | SPORT_KIT; // 0001 | 0100 | 1000 => 1011 // 1 + 4 + 8 = 13
# INSTRUCTIONS: save in ~/.profile or some other profile-based load script for your distro
# Credit: http://gitimmersion.com/lab_11.html
alias gs='git status '
alias ga='git add '
alias gb='git branch '
alias gc='git commit'
alias gd='git diff'
alias go='git checkout '
alias gk='gitk --all&'
alias gx='gitx --all'
@justsml
justsml / gist:6419674
Created September 3, 2013 04:15
Array indexOf IE Enable Snippet
Array.prototype.indexOf = function(obj, start) {
for (var i = (start || 0), j = this.length; i < j; i++) {
if (this[i] === obj) { return i; }
}
return -1;
}
_ = require "lodash"
rest = (opts) ->
# simple prefix, ie http://localhost:1337/api/:collection/:id?
@prefix = '/api'
@path = null
@key = 'collection'
@justsml
justsml / edit.tmpl.jade
Created September 2, 2014 05:45
Commitment Viewer & Edit Page w/ Jade, AngularJS, angular-route
div.well.commitment-modal
div.panel.panel-success
div.panel-heading
h2.panel-title Commitment Overview
div.panel-body
@justsml
justsml / .gitconfig
Last active February 22, 2016 21:08
.gitconfig
[core]
autocrlf = false
[push]
default = upstream
[i18n]
filesEncoding = utf-8
[color]
branch = auto
diff = auto
status = auto
@justsml
justsml / regex.js
Created January 20, 2015 05:53
Handy RegEx Validation Snippit
/*
Credit and Source: https://www.owasp.org/index.php/OWASP_Validation_Regex_Repository
*/
'use strict';
module.exports = {
url: /^((((https?|ftps?|gopher|telnet|nntp):\/\/)|(mailto:|news:))(%[0-9A-Fa-f]{2}|[-()_.!~*';\/?:@&=+$,A-Za-z0-9])+)([).!';\/?:,][[:blank:]])?$/,
ip: /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
email: /^[a-zA-Z0-9+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/,
safeText: /^[a-zA-Z0-9 .-]+$/,
date: /^(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/,
@justsml
justsml / roleCheck.js
Last active August 29, 2015 14:14
Functional BitWise Role Checking
var roles = {'admin': 8, 'user': 1, 'powerUser': 4 },
user = {role: 12}; // 4 + 8
function hasRoleName(chkRole) {
chkRole = typeof(chkRole) === 'string' ? [chkRole] : chkRole;
var roleSum = chkRole.reduce(function(last, curr, idx, list) { return last + (roles[list[idx]] || 0); }, 0);
return hasAnyRolesBit(roleSum);
}
function hasAllRolesBit(roleSum) {
return (roleSum & user.role) >= roleSum; // must match all bits!
}
@justsml
justsml / 0_reuse_code.js
Last active August 29, 2015 14:16
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console