Skip to content

Instantly share code, notes, and snippets.

@michikono
michikono / decide.coffee
Last active August 29, 2015 14:08
Hubot Script for Making Hard Decisions
# Description:
# Decides between two or more options at random. Now Spanish compatible!
#
# Commands:
# decide|choose|pick( between)(:) <option 1> and|or <option 2> (and|or <option #> ...)
# escoger|elegir|seleccionar|decidir( entre)(:) <opción 1> y|o <opción 2> (y|o <opción #> ...)
#
# Author:
# Michi Kono
# Description:
# A script to translate laughter to Argentina's native language
#
# Notes:
# :)
#
# Author:
# Michi Kono
module.exports = (robot) ->
# centralized global_dispatcher object added to all Backbone Collection, Model, View, and Router classes
(->
return if this.isExtended
# attaching the Events object to the dispatcher variable
dispatcher = _.extend({}, Backbone.Events, cid: "dispatcher")
_.each [ Backbone.Collection::, Backbone.Model::, Backbone.View::, Backbone.Router:: ], (proto) ->
# attaching a global dispatcher instance
_.extend proto, global_dispatcher: dispatcher
)()
@michikono
michikono / jquery.bump.js
Created January 21, 2012 02:20
jQuery Bump Animation Fixed
// taken from http://daveymorris.co.uk/web-development/bump-jquery-plugin-bounce
// improved with additional options
(function($){
$.bump = function(el, options){
// Some object and DOM instansiation to make traversing the DOM less expensive
var base = this;
base.$el = $(el);
base.el = el;
@michikono
michikono / yyyy-mm-dd hh:ii:ss.js
Last active December 12, 2015 09:28
yyyy-mm-dd hh:ii:ss formatter
get_time = function() {
var date_part, local_time, now, time_part;
local_time = new Date();
now = new Date(local_time.getTime() + (local_time.getTimezoneOffset() * 60000));
date_part = "" + (this.zero_pad(now.getFullYear(), 2)) + "-" + (this.zero_pad(now.getMonth() + 1, 2)) + "-" + (this.zero_pad(now.getDate(), 2));
time_part = "" + (this.zero_pad(now.getHours(), 2)) + ":" + (this.zero_pad(now.getMinutes(), 2)) + ":" + (this.zero_pad(now.getSeconds(), 2));
return "" + date_part + " " + time_part;
}
zero_pad = function(number, length) {
var str;
@michikono
michikono / kue.js
Last active December 20, 2015 21:59
module.exports = function (app, config, passport, express) {
var kue = require("kue");
var auth = express.basicAuth(function(user, pass, callback) {
var result = (user === 'username' && pass === 'password');
callback(null /* error */, result);
});
// any kue related settings can go here
kue.app.set('title', 'Jobs');
// create a wrapper to add auth on since without it we can't globally wrap kue's paths
var subApp = express()
# demo of brain functionality (persisting data)
# https://github.com/github/hubot/blob/master/docs/scripting.md#persistence
# counts every time somebody says "up"
# prints out the count when somebody says "are we up?"
# /STUFF/ means match things between the slashes. the stuff between the slashes =
# regular expression.
# \b is a word boundary, and basically putting it on each side of a phrase ensures
# we are matching against the word "up" instead of a partial text match such as in "sup"
robot.hear /\bup\b/, (msg) ->
# note that this variable is *GLOBAL TO ALL SCRIPTS* so choose a unique name