Skip to content

Instantly share code, notes, and snippets.

Avatar
🔥
#BLM

Dan Levy justsml

🔥
#BLM
View GitHub Profile
@justsml
justsml / object-watch.js
Created Apr 1, 2012 — forked from eligrey/object-watch.js
object.watch polyfill
View object-watch.js
// 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) {
View bitwise-example.js
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
View gist:6034367
# 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 Sep 3, 2013
Array indexOf IE Enable Snippet
View gist:6419674
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;
}
View older-cs.coffee
_ = 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 Sep 2, 2014
Commitment Viewer & Edit Page w/ Jade, AngularJS, angular-route
View edit.tmpl.jade
div.well.commitment-modal
div.panel.panel-success
div.panel-heading
h2.panel-title Commitment Overview
div.panel-body
@justsml
justsml / .gitconfig
Last active Feb 22, 2016
.gitconfig
View .gitconfig
[core]
autocrlf = false
[push]
default = upstream
[i18n]
filesEncoding = utf-8
[color]
branch = auto
diff = auto
status = auto
@justsml
justsml / regex.js
Created Jan 20, 2015
Handy RegEx Validation Snippit
View regex.js
/*
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 Aug 29, 2015
Functional BitWise Role Checking
View roleCheck.js
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 Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
You can’t perform that action at this time.