Skip to content

Instantly share code, notes, and snippets.

@amogower
amogower / example.js
Last active January 29, 2017 18:56
PubSub Module
function PubSub() {
this.object = $(this);
}
PubSub.prototype.subscribe = function(callback) {
this.object.on.call(this.object, 'event', callback);
};
PubSub.prototype.unsubscribe = function(callback) {
this.object.off.call(this.object, 'event', callback);
@amogower
amogower / pre-commit
Created February 3, 2017 07:38
Simple pre-commit test runner
#!/bin/sh
#
# Hook: pre-commit
# Desc: run tests on master branch
branch=`git rev-parse --abbrev-ref HEAD`
if [ "$branch" = "master" ]; then
make test
fi
@amogower
amogower / consoleLog.js
Created February 3, 2017 09:19
Crazy console log styling
var css = "text-shadow: -1px -1px hsl(0,100%,50%), 1px 1px hsl(5.4, 100%, 50%), 3px 2px hsl(10.8, 100%, 50%), 5px 3px hsl(16.2, 100%, 50%), 7px 4px hsl(21.6, 100%, 50%), 9px 5px hsl(27, 100%, 50%), 11px 6px hsl(32.4, 100%, 50%), 13px 7px hsl(37.8, 100%, 50%), 14px 8px hsl(43.2, 100%, 50%), 16px 9px hsl(48.6, 100%, 50%), 18px 10px hsl(54, 100%, 50%), 20px 11px hsl(59.4, 100%, 50%), 22px 12px hsl(64.8, 100%, 50%), 23px 13px hsl(70.2, 100%, 50%), 25px 14px hsl(75.6, 100%, 50%), 27px 15px hsl(81, 100%, 50%), 28px 16px hsl(86.4, 100%, 50%), 30px 17px hsl(91.8, 100%, 50%), 32px 18px hsl(97.2, 100%, 50%), 33px 19px hsl(102.6, 100%, 50%), 35px 20px hsl(108, 100%, 50%), 36px 21px hsl(113.4, 100%, 50%), 38px 22px hsl(118.8, 100%, 50%), 39px 23px hsl(124.2, 100%, 50%), 41px 24px hsl(129.6, 100%, 50%), 42px 25px hsl(135, 100%, 50%), 43px 26px hsl(140.4, 100%, 50%), 45px 27px hsl(145.8, 100%, 50%), 46px 28px hsl(151.2, 100%, 50%), 47px 29px hsl(156.6, 100%, 50%), 48px 30px hsl(162, 100%, 50%), 49px 31px hsl(167.4, 100%, 5
@amogower
amogower / user.js
Created May 28, 2017 20:30 — forked from EtienneR/user.js
XMLHttpRequest RESTful (GET, POST, PUT, DELETE)
// Get all users
var url = "http://localhost:8080/api/v1/users";
var xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.onload = function () {
var users = JSON.parse(xhr.responseText);
if (xhr.readyState == 4 && xhr.status == "200") {
console.table(users);
} else {
console.error(users);
@amogower
amogower / callbackFormOfSetState.js
Created June 16, 2017 19:54 — forked from coryhouse/callbackFormOfSetState.js
Callback setState example
updateState({target}) {
this.setState(prevState => {
const updatedUser = {...prevState.user, [target.name]: target.value}; // use previous value in state to build new state...
doSomething(updatedUser); // Now I can safely utilize the new state I've created to call other funcs...
return { user: updatedUser }; // And what I return here will be set as the new state
});
}
function buildReduxContainer(ChildComponentClass, mapStateToProps) {
return class Container extends Component {
render() {
const { state } = this.context.store.getState();
const props = mapStateToProps(state);
return <ChildComponentClass {...this.props} {...props} />;
}
}
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _assign = require('babel-runtime/core-js/object/assign');
var _assign2 = _interopRequireDefault(_assign);
@amogower
amogower / pubsub.js
Created November 30, 2017 22:56
Javascript Pub/Sub
var events = (function(){
var topics = {};
var hOP = topics.hasOwnProperty;
return {
subscribe: function(topic, listener) {
// Create the topic's object if not yet created
if(!hOP.call(topics, topic)) topics[topic] = [];
// Add the listener to queue
@amogower
amogower / updating_fork.md
Created December 27, 2017 15:44 — forked from CristinaSolana/gist:1885435
Keeping a fork up to date

1. Clone your fork:

git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@amogower
amogower / private_object_properties_with_proxies.js
Last active January 18, 2018 19:43
Private object propertiesPrivate object properties with ES2015 Proxies // source https://jsbin.com/puxezu
'use strict';
function privateProps(obj, filterFunc) {
var handler = {
get: function get(obj, prop) {
if (!filterFunc(prop)) {
var value = Reflect.get(obj, prop);
// auto-bind the methods to the original object, so they will have unrestricted access to it via 'this'.
if (typeof value === 'function') {
value = value.bind(obj);