Skip to content

Instantly share code, notes, and snippets.

View spoike's full-sized avatar
👓
I may be slow to respond.

Mikael Brassman spoike

👓
I may be slow to respond.
View GitHub Profile
@spoike
spoike / requireBefore.js
Created June 26, 2014 13:27
Utility method for your Mocha tests that loads in your modules with RequireJS.
// Needs RequireJS's `require` and mocha's `before`
/**
* Works like mocha's `before` function but enables you to load in dependencies
* as well.
*
* @param deps [Array] the dependencies passed on to RequireJS
* @param callback [Function] the callback with loaded dependencies as arguments
*/
requireBefore = function(deps, callback) {
@spoike
spoike / chai_assert.md
Created June 26, 2014 07:02
Chai Assert Cheatsheet

Chai assert Cheatsheet

Note that the assert object is not chainable. Link to assert docs.

  • assert(expression, message)

  • assert.fail(actual, expected, [message], [operator])

  • assert.ok(object, [message])

@spoike
spoike / functor.js
Created June 25, 2014 12:20
Super Simple Tutorial on How to Create a Functor in JavaScript
// Here is a quick tutorial on how to create a functor, an object that acts
// both as function and an object of functions (e.g. much like jQuery's globally
// available $ object)
// This is a factory method that creates the functor for us:
function createFunctor() {
// Declared variables are scoped within the createFunctor function
// so they are practically private:
var name = 'World';
@spoike
spoike / keyframesteps.scss
Created May 19, 2014 07:59
Sass mixin that emulates a CSS3 `steps()` animation function that works in earlier IE.CSS3 `steps()` function only works with >IE10 http://caniuse.com/css-animation
@mixin keyframesteps($name, $steps, $startx, $endx) {
@keyframes #{$name}
{
@for $i from 0 through $steps {
$diff: ($endx - $startx) / $steps;
#{($i/$steps*100)}% {
$x: ($i * $diff) + $startx;
background-position: $x 0;
}
}
@spoike
spoike / reactjs_componentapi_cheatsheet.md
Created May 13, 2014 07:51
React JS Cheatsheets for Component API, Specifications and Lifecycle

ReactJS Component Cheatsheet

To create a ReactComponent:

ReactComponent React.createClass(object proto)

Basic JSX example:

var TitleComponent = React.createClass({

// REQUIRED

@spoike
spoike / pluckRef.js
Created May 6, 2014 14:45
Handling irregular objects in an array, where inspecting chain may lead to TypeErrors due to undefined values. Useful on REST API's that for some reason returns irregular objects in an array.
// Adds pluckRef method to lodash
// Example: _.(array, 'key1.key2.key3');
// Goes through each object of the array and attempts to pluck objects that are
// in the specified object chain path. It filters away undefined values.
_.mixin({
'pluckRef': function(arr, keyPathRef) {
var i, j, keys, key, ref, output = [];
keys = keyPathRef.split('.');
// for each object in the array
@spoike
spoike / flexbox.md
Created April 19, 2014 08:53
Flexbox CSS Cheatsheet

Flexbox Cheatsheet

Flex Container

  • display: flex | inline-flex
  • flex-direction: row | row-reverse | column | column-reverse
  • flex-wrap: nowrap | wrap | wrap-reverse
  • justify-content: flex-start | flex-end | center | space-between | space-around
  • align-items: flex-start | flex-end | center | baseline | stretch
  • align-content: flex-start | flex-end | center | space-between | space-around | stretch
@spoike
spoike / define_amd.xml
Created January 22, 2014 09:36
Sublime Text snippet for creating an RequireJS/AMD define block in javascript files. Create with Tools > New Snippet... and save it as `define_amd.sublime-snippet`.
<snippet>
<content><![CDATA[define([${1}], function(${2}) {
${0}
});]]></content>
<tabTrigger>def</tabTrigger>
<scope>source.js</scope>
<description>Adds an RequireJS/AMD define block</description>
</snippet>
@spoike
spoike / games.json
Last active December 29, 2015 19:19
Games that I've made so far
{
"d": [
{
"name": "Squishy",
"url": "http://spoike.github.io/html5-game/"
},
{
"name": "Minesweeper",
"url": "http://spoike.github.io/minesweeper/"
},
@spoike
spoike / toAsciiIndex.js
Created September 24, 2013 13:43
For determining which character to take from an ascii table using row and column indices.
var toAsciiIndex = function(str) {
var i, carr = [], curr;
for(i = 0; i < str.length; i++) {
curr = str.charCodeAt(i);
carr.push([curr%32, Math.floor(curr/32)]);
}
return carr;
};
toAsciiIndex("Hah"); // -> [[8,2],[1,3],[8,3]]