Skip to content

Instantly share code, notes, and snippets.

View joelhooks's full-sized avatar
🍄

Joel Hooks joelhooks

🍄
View GitHub Profile
@joelhooks
joelhooks / Class.js
Created July 24, 2012 22:59
Simple Javascript Inheritance
/* Simple JavaScript Inheritance
* By John Resig http://ejohn.org/blog/simple-javascript-inheritance/
* MIT Licensed.
*/
// Inspired by base2 and Prototype
(function(){
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
this.Class = function(){};
[
{
"slug": "react-redux-the-single-immutable-state-tree",
"question": "What is the *entire* state of the application represented as?",
"answer": "A single Javascript object."
},
{
"slug": "react-redux-describing-state-changes-with-actions",
"question": "What is an action?",
"answer": "A minimally represented change of the state"
aasm :column => :state do
state :proposed, :initial => true
state :cancelled
state :accepted
state :claimed
state :submitted
state :rejected
state :updated
state :approved
state :published
import hype.*;
import hype.extended.colorist.HPixelColorist;
int myStageW = 1920;
int myStageH = 1080;
color clrBG = #FFFFFF;
// ********************************************************************************************************************
@joelhooks
joelhooks / BaseActor.as
Created December 30, 2011 01:39
Robotlegs 2: Flickr Image Gallery Snippets
package robotlegs.bender.demos.imagegallery.base
{
import flash.events.Event;
import flash.events.IEventDispatcher;
/**
* Provides some common functionality for basic application classes (models and services)
*/
public class BaseActor
{
@joelhooks
joelhooks / LOG.js
Created January 24, 2014 21:52
Enhanced Logging
.run(function ($rootScope, $log, $window) {
var prepareLogFn = function (logFn) {
var enhancedLogFn = function () {
var modifiedArguments = Array.prototype.slice.call(arguments);
modifiedArguments[0] = [moment().format() + ' '] + modifiedArguments[0];
logFn.apply(null, modifiedArguments);
};
enhancedLogFn.logs = [ ];
$scope.subscriptions = _.map(_.sortBy(_.filter(subscriptions, function(sub) {
return sub.transactions && sub.transactions.length;
}), function(sub) {
return _.last(sub.transactions).created_at;
}), function(sub) {
var last_transaction = _.last(sub.transactions),
totals = _.reduce(sub.transactions, function (memo, t) {
return memo + t.amount/100.0;
}, 0);
Run options: exclude {:org=>true}
......FFFF.FF.F
Failures:
1) Quarto::Build stripping source code should eq "puts \"hello, world\nif true\n puts \"goodbye, world\nend\n"
Failure/Error: expect(build.strip_listing(code)).to eq(<<END)
expected: "puts \"hello, world\nif true\n puts \"goodbye, world\nend\n"
got: "puts \"hello, world\n if true\n puts \"goodbye, world\n end"
@joelhooks
joelhooks / angularServices.js
Last active December 21, 2015 04:39
Short example of how to declare services in AngularJS.
//from most to least verbose, but it is all the same in the end.
(function() {
var module = angular.module("myApp.myModel", []);
var MyModel = function MyModel() {
this.asyncService = null;
this.someApi = function() {
module.directive('validatePhone', function () {
return {
require: 'ngModel',
link: function (scope, elem, attr, ngModel) {
function validatePhone(field) {
//regex squirreled from here: http://blog.stevenlevithan.com/archives/validate-phone-number
var regexObj = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/;
return regexObj.test(field);