Skip to content

Instantly share code, notes, and snippets.

View MiracleBlue's full-sized avatar

Nicholas Kircher MiracleBlue

  • Founder & CEO, Zircat - @zircat-dev
  • Melbourne, Australia
View GitHub Profile
@MiracleBlue
MiracleBlue / types.ts
Last active September 1, 2018 05:53
A kind of "get last item" function at the type level
export type Next<T extends number> = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64][T];
export type Prev<T extends number> = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62][T];
type GetLast<original extends any[]> = original extends { length: infer L } ? (
L extends number ? original[Prev<L>] : never
) : never
type Stuff = [number, boolean, string]
type OtherStuff = [string, number, object, boolean]
@MiracleBlue
MiracleBlue / maybe.js
Created March 31, 2018 22:31
My own implementation of a Maybe monad :)
import {
reduce,
complement,
isNil
} from 'ramda';
const isDefined = complement(isNil);
const Maybe = do {
const __maybe = Symbol('Maybe');
// So this is fking incredible. Its actually possible to
// do totally immutable state inside a generator.
// No mutations. No 'let's. No shame!
function* range(start, end, step = 1, current = start) {
yield current;
if (current < end) yield* range(start, end, step, current + step);
}
// In the name of the Turing, and of the Crockford, and of the holy Atwood, Amen.
console.log(...range(5, 15));
@MiracleBlue
MiracleBlue / time-format-test.js
Last active December 16, 2015 01:28
Simple fuzzing unit testing example with Ember CLI and Ember Mocha
/* jshint expr:true */
import { expect } from 'chai';
import {
describe,
it
} from 'mocha';
import {
convertTimeTo12
} from 'digital-court-results/helpers/time-format';
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
model: [
{name: 'billy', age: 20},
{name: 'george', age: 30},
{name: 'william', age: 50}
]
});
import Ember from 'ember';
const PositionalParams = {positionalParams: ["thing"]};
export default Ember.Component.extend(PositionalParams, {
thing: "meow"
});
import DS from 'ember-data';
export default DS.Model.extend({
timeline: DS.belongsTo("timeline"),
type: DS.attr("string")
});
`import Ember from 'ember'`
IndexController = Ember.ObjectController.extend
needs: ['application']
actions:
hasProjects: (->
@get('model.length') > 0
).property('model.length')
`export default IndexController`