Skip to content

Instantly share code, notes, and snippets.

View JimOKelly's full-sized avatar

Jim OKelly JimOKelly

View GitHub Profile
@JimOKelly
JimOKelly / deck.js
Created April 22, 2016 01:17
card deck example in javascript
Array.prototype.flatMap = function(fn) {
return Array.prototype.concat.apply([], this.map(fn));
};
Array.prototype.shuffle = function() {
var m = this.length, t, i;
// While there remain elements to shuffle…
while (m) {
@JimOKelly
JimOKelly / Euler-1.js
Last active May 9, 2016 20:30
This is how I would solve euler 1 without resulting to passing functions to functions (beginner code)
// If we list all the natural numbers below 10 that are
// multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of
// these multiples is 23.
//
// Find the sum of all the multiples of 3 or 5 below 1000.
if (typeof(Array.prototype.flatMap) != "function") {
// warning, we are mutating the actual base prototype for Array here
Array.prototype.flatMap = function(fn) {
return Array.prototype.concat.apply([], this.map(fn));
@JimOKelly
JimOKelly / dominoes-before-bros.js
Created May 24, 2016 06:28
Javascript based dominoes
var Node = function(a, b) {
this.data = {a: a, b: b };
this.parent = undefined;
this.children = [];
return this;
};
Node.prototype.isSpinner = function() {
return this.data.a === this.data.b;
@JimOKelly
JimOKelly / example.js
Created June 1, 2016 18:35
BEHOLD! I give you JavaScript magic like Ruby haseth!
(function() {
Date.prototype.today = function() {
var date = this;
var beginningOfMonth = function() {
var bom = new Date(date.getFullYear(), date.getMonth(), 1);
var beginningOfWeek = function() {
var day = bom.getDay();
@JimOKelly
JimOKelly / gist:6387a73e1740784b84f01689eaa0fb85
Created June 23, 2016 06:48 — forked from mattetti/gist:1015948
some excel formulas in Ruby
module Excel
module Formulas
def pmt(rate, nper, pv, fv=0, type=0)
((-pv * pvif(rate, nper) - fv ) / ((1.0 + rate * type) * fvifa(rate, nper)))
end
def ipmt(rate, per, nper, pv, fv=0, type=0)
p = pmt(rate, nper, pv, fv, 0);
ip = -(pv * pow1p(rate, per - 1) * rate + p * pow1pm1(rate, per - 1))
(type == 0) ? ip : ip / (1 + rate)
@JimOKelly
JimOKelly / decorating-objects.js
Created July 24, 2016 16:04
A way to 'decorate' your objects in JavaScript
var Adventurer = function(options) {
this.name = options.name;
this.gender = options.gender;
this.class = options.class;
this.race = options.race;
this.position = options.position || 'standing';
this.effects = [];
this.hits = [];
var prompt = require('prompt');
var util = require('util');
var Player = function(options) {
this.name = options.name;
this.attributes = options.attributes || {
str: 10,
int: 10,
wis: 10,
dex: 10,