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 / slack_post.js
Created March 2, 2015 08:14
Simple Slack Incoming Webhook script for hubot to post useful messages (in pretty format) on channels/rooms. Also works without having hubot invited on the channel.
/**
* # Post messages using Slack's Webhook
*
* Use this in combination with node-cron to Schedule messages.
* No need to have the hubot invited on the actual channel to post.
*
* ## Dependencies
*
* superagent
* lodash
@spoike
spoike / is_it_friday.coffee
Last active August 29, 2015 14:16
"Is it friday?" hubot script that displays media from /r/holdmybeer if the current day is a friday
# Description:
# Hubot delivers a pic from Reddit's /r/holdmybeer frontpage if it is a friday
# based on the aww script.
#
# Dependencies:
# moment
#
# Configuration:
# None
#
@spoike
spoike / hubot-make-me-a-sandwich.coffee
Created February 20, 2015 09:26
Hubot make me a sandwich!
# Description:
# Hubot make me a sandwich
#
# Dependencies:
# google-images
#
# Configuration:
# None
#
# Commands:
@spoike
spoike / hubot-fika.coffee
Created February 20, 2015 07:50
Script for celebrating the Swedish past time of "Fika"
# Description:
# Hubot delivers a fika related pic
#
# Dependencies:
# cron
# google-images
#
# Configuration:
# None
#
var Errors = Reflux.createActions(['error1', 'error2' /*, 'error3' */]);
var ErrorNotificationStore = Reflux.createStore({
init: function() {
_.each(Errors, function(action) {
this.listenTo(action, this.onError);
}, this);
},
onError: function(errorMessage) {
/* whatever you want to do with errorMessage and this.trigger(...) */
/** @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 / 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 / normalRandom.js
Created August 19, 2014 10:55
Generate uniform (normal distributed) random numbers. Taken from http://www.protonfish.com/random.shtml
/**
* Generates normally distributed random numbers
*/
function normalRandom(mean, stdDev) {
// Generate a "close enough" uniform random
// number w. mean = 0 and std.dev = 1
var uniformRandom = (Math.random()*2-1)+(Math.random()*2-1)+(Math.random()*2-1);
return Math.round(uniformRandom * stdDev + mean);
}
@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 / reflux.js
Created June 29, 2014 22:23
A simpler implementation of React.JS's Flux
var EventEmitter = require('events').EventEmitter,
_ = require('lodash');
/**
* Creates an action functor object
*/
exports.createAction = function() {
var action = new EventEmitter(),
eventLabel = "action",