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 / 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 / framerateThrottle.js
Last active August 13, 2017 21:35
Throttling using windows.requestAnimationFrame with fallback to lodash throttle. See more here: http://spoike.ghost.io/user-input-framerate-throttling-in-the-browser/
(function() {
var defaultFrameRate = 20, // fps lock for old browsers
// This is the default fallback throttle function
framerateThrottle = function(callback) {
return _.throttle(callback, 1 / (defaultFrameRate * 1000));
};
// Feature detection - should have requestAnimationFrame
if (window.requestAnimationFrame) {
framerateThrottle = function(callback) {
@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 / webapi_example.js
Last active May 12, 2017 13:37
Simple WebAPI example
var PostsApi = require('webapi/posts'),
// assuming the api object from the jsbin snippet
Reflux = require('reflux');
var PostActions = createActions(["load", "loadError"]);
// load action is invoked either from:
// * top most component's componentDidMount
// function in your application, or
// * window.onLoad
// I prefer the first strategy because that'll
@spoike
spoike / git-smart-checkout.sh
Created December 7, 2016 14:06
Git Checkout that remembers previous branch and lets you quickly switch between previous and current branches.
function gch() {
local currentBranch=$(git rev-parse --abbrev-ref HEAD)
local previousFile="$(git rev-parse --show-toplevel)/.git/PREVIOUS_HEAD"
if [ -n "$1" ]; then
echo "$currentBranch" >> $previousFile
git checkout "$@"
else
if [ ! -f "$previousFile" ]; then echo >&2 "ERROR: Missing PREVIOUS_HEAD. Please run gch with 1 argument first."
else
git checkout "$(cat $previousFile | tail --lines=1)"
@spoike
spoike / prompt-emoji-setup
Last active October 28, 2016 13:52 — forked from oshybystyi/random-emoji.zsh-theme
Random emoji theme for zpresto
#
# A minimal emoji theme.
#
# Authors:
# Mikael Brassman
#
# Features:
# - Displays a random emoji as prompt
#
# Usage:
/** @jsx React.DOM */
var React = require('react'),
Reflux = require('reflux'),
toggle = Reflux.createAction(),
userStore = Reflux.createStore({
init: function() {
this.notify = false;
this.listenTo(toggle, this.onToggle);
},
onToggle: function(flag) {
@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]]