Skip to content

Instantly share code, notes, and snippets.

@micho
micho / gist:3658172
Created September 6, 2012 16:28
Cohort analysis for First Steps
date = Time.parse("2012-08-15")
(8+15).times do
users = User.where("created_at > ? AND created_at < ?", date, date + 1.day); 0
puts [
date.to_date.to_s,
users.count,
users.select {|u| Array(u.settings["steps"]).length === 0 }.count,
@micho
micho / gist:855b272d2f408f04729e
Last active October 9, 2015 14:08
Github PRs: Collapse/expand file
// Add a button to Collapse or Expand files in a Github PR
//
// See it in action: http://cl.ly/image/1r3q3d0d3b0p
//
// Install Tampermonkey and add this as a script
// ==UserScript==
// @name Github PRs: Collapse/expand file
// @namespace https://gist.github.com/micho/855b272d2f408f04729e
// @version 0.1
@micho
micho / gist:3341189
Created August 13, 2012 14:20
posted_at relative time
/*global I18n*/
(function ($) {
var PostedAt = {}
, moment = this.moment;
// Format dates in a human way. Read the code.
moment.fn.humanFormat = function () {
// ensure that we are on utc
var utc = this.clone().utc()
Resource Cache mechanism, for projects and people
Resource Cache is a key-value auto-expiring cache, where we pass
the path for a base model + a resource owned by it + modifiers.
Structure
---------
Each cacheable entry is called with two or three parameters:
@micho
micho / gist:2354772
Created April 10, 2012 21:39
Teambox for Box
// Run this in your JS console while on box.com
$("#files_tab").after(
'<li id="teambox_tab" class="current">' +
'<a id="teambox_tab_link" href="https://teambox.com?embedded=1" onmousedown="return false;">Teambox</a></li>'
);
$(".body .main").html(
'<iframe src="https://teambox.com?embedded=1" style="border: none; width: 720px; height: 100000px"></iframe>'
);
@micho
micho / wysihtml5-resize.js
Created March 29, 2012 20:30
wysihtml5 resize plugin. Depends on jQuery and Underscore
(function () {
var setupRegularResize, setupIframeResize, e;
function bind(a, b) {
return function () {
return a.apply(b, arguments);
};
}
setupRegularResize = (function () {
alert(1)
@micho
micho / debug.js
Created February 9, 2012 10:50
debug times for js
/**
* Create a debugger with the given `name`.
*
* @param {String} name
* @return {Type}
* @api public
*/
function debug(name) {
var now = Date.now();
@micho
micho / gist:1120193
Created August 2, 2011 13:37
Prompt branch for bash
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
}
function precmd() {
PROMPT="%n@%m %~$(parse_git_branch)%# "
}
export PATH="/usr/local/mysql/bin:${PATH}:/usr/local/git/bin"
function proml {
@micho
micho / gist:872697
Created March 16, 2011 15:46
Cloudapp plugin for Talkerapp
plugin.onMessageSend = function (event) {
var match, url, content;
if (match = event.content.match(/(https?:\/\/cl.ly\/[^\/]+)(\/[^\/]+)*/)) {
url = match[1] || false;
content = match[2] || false;
if (!content || content.indexOf('/content') != -1) {
event.content = event.content.replace(url, url+'/content#.png');
Talker.sendMessage(event, "");
Talker.getMessageBox().val('');
return false;