Skip to content

Instantly share code, notes, and snippets.

View rjhilgefort's full-sized avatar

Rob Hilgefort rjhilgefort

View GitHub Profile
@rjhilgefort
rjhilgefort / app-object.js
Last active August 29, 2015 14:09
Ember Object Property List Strategy
var AppObject = Ember.Object.extend({
/**
* Get a list of all computed properties set on this instance
*
* @method getComputedPropertyList
* @return {Array} List of computed properties (strings)
* @since TODO
*/
getComputedPropertyList: function() {
@rjhilgefort
rjhilgefort / generateNines.php
Created June 1, 2013 03:18
Multiple ways to generate any number of nines (or any digit for that matter) via PHP
<pre>
<?php
//By @pkspencer
function generateNines_One($numNines)
{
$result = 0;
for ($i=0; $i < $numNines; $i++) {
$result += pow(10, $i);
}
@rjhilgefort
rjhilgefort / init.lua
Last active May 19, 2017 03:10 — forked from arbelt/init.lua
Hammerspoon config to send escape on short ctrl press
local sendEscape = true
local ctrlKeyTimer = hs.timer.delayed.new(0.15, function()
sendEscape = false
end)
local lastMods = {}
local flagsChangedHandler = function(event)
local newMods = event:getFlags()
if lastMods.ctrl == newMods.ctrl then return false end
@rjhilgefort
rjhilgefort / personalizeCoupons.js
Created July 17, 2017 22:10
Coding Test: Personalize Coupons
// isCouponInCategories :: Array<Object> => Object -> Boolean
const isCouponInCategories = categories => coupon =>
categories.includes(coupon.category);
// percentDiscount :: Object -> Number
const percentDiscount = coupon =>
((coupon.couponAmount / coupon.itemPrice) * 100);
// TODO: I decided to remove the code after the list was reduced
// to the 10 coupons because of the "So in short" summary of
@rjhilgefort
rjhilgefort / validateCards.js
Created July 17, 2017 22:11
Coding Test: Validate Cards
// --- UTILS ------------------------------------------------
// pipe :: ...Functions => a -> b
const pipe = (...funcs) => data =>
funcs.reduce((acc, func) => func(acc), data);
// toNumber :: String -> Number
const toNumber = data => parseInt(data, 10);
// double :: Number -> Number
// NOTE: Ramda repl
console.clear()
const foo = [
{ id: 'one' },
{ id: 'two' },
{ id: 'three' },
]
// NOTE: Ramda repl
console.clear()
const foo = (a, b) => a + b
const bar = () => 4
const tryYolo = curry((func, params) => {
try {
return apply(func, params)
@rjhilgefort
rjhilgefort / class.js
Last active December 2, 2017 19:48
Class vs Factory
class ConsecutiveFailure {
constructor({
count = 0,
threshold = 10,
logger = console.log,
}) {
this.count = count;
this.threshold = threshold;
this.logger = logger;
}
const { log } = console;
console.clear();
const logHof = fn => (...args) => {
log('logHof')
log(args);
return fn(...args);
};
const incrementHof = fn => (x, y) => {
@rjhilgefort
rjhilgefort / connect-four.js
Last active June 14, 2018 15:28
A quick Connect Four app build with a single class. Has a stupid AI, simulate, and user interaction. In ramda REPL: https://goo.gl/WBd2jL
const { log, clear } = console
const reduceI = addIndex(reduce);
const HUMAN = 'X';
const COMPUTER = 'O';
class Board {
constructor({
rows = 4,