Skip to content

Instantly share code, notes, and snippets.

@micho
micho / gist:855b272d2f408f04729e
Last active Oct 9, 2015
Github PRs: Collapse/expand file
View gist:855b272d2f408f04729e
// 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 / support_helper
Last active Jun 26, 2016
Support helper for Teambox, so we can query users
View support_helper
$(document).on("click", ".comment a", function(e) {
if ($(this).text().indexOf("@") !== -1) {
e.preventDefault();
var email = $(this).text();
(new Teambox.Views.Dialog({
header: "User " + email + ". <a href='/become/" + email + "'>Become</a>"
, content: "<iframe src='/reports/users/" + email + "' style='width: 100%; height: 800px;'></iframe>"
})).open();
}
});
@micho
micho / gist:6135657
Created Aug 1, 2013
Votes.js, add a voting count to Teambox
View gist:6135657
/**
* Adds a Like button to tasks, so users can like them.
*
* By default there are no votes enabled in the project. To enable:
*
* project.metadata('apps').set({ votes: true });
* project.metadata('apps').save();
*
*/
@micho
micho / Array#occurrences
Last active Dec 17, 2015
Count occurrences
View Array#occurrences
class Array
# Takes %(apple apple strawberry orange orange apple) and returns { apple: 3, orange: 2, strawberry: 1 }
def occurrences
r = {}
group_by {|i| i}.each{|k,v| r[k] = v.count}
sorted = {}
r.sort_by {|k,v| -v}.each {|i| sorted[i[0]] = i[1] }
sorted
end
end
@micho
micho / Organization activity rates and variation.rb
Last active Dec 16, 2015
Describes activity rates by organization with subscription.
View Organization activity rates and variation.rb
# Possible anomaly: If the org was created long ago but only active recently, project_recent will always be low
# Proposed solution: Build a semirecent_activity field and use that for projections, which will track 6-12 months
def days_ago(o); (Time.now - o.created_at) / 1.day; end
def projected_recent(o); (o.total_activities / days_ago(o)).to_i * 14; end
# Get active subscriptions with a chargify id (to exclude cancelations and manual subscriptions)
ss = Subscription.where(state: nil).reject { |s| s.payment_gateway_id.nil? }; 0
# Get orgs. Tweak the filters to restrict your results list
oo = ss.map { |s| Organization.find_by_subscription_id s.id }.compact; 0
View gist:5304891
~/code/rabl[master]: rake test:setup test:full
*** Setting up for padrino_test tests ***
The source :rubygems is deprecated because HTTP requests are insecure.
Please change your source to 'https://rubygems.org' if possible, or 'http://rubygems.org' if not.
Resolving dependencies...
Using rake (10.0.4)
Using i18n (0.6.4)
Using multi_json (1.7.2)
Using activesupport (3.2.12)
@micho
micho / gist:4040725
Created Nov 8, 2012
embed_talker2.js
View gist:4040725
$("#talker2_link").remove()
Teambox.views.sidebar.apps_list.addApp("talker2", "New Group Chat", "#", "key");
$("#talker2_link a").click(function (e) {
e.preventDefault();
if (this.open) {
$(".chat_container").remove();
$(".content_wrap").css("bottom", "0px");
this.open = false;
} else {
var height = 250;
@micho
micho / personal_notes.js
Created Oct 19, 2012
Load personal notes if present
View personal_notes.js
// Load personal notes as a sidebar item
// find personal project
var project = Teambox.collections.projects.detect(function (p) { return p.get('permalink') === 'tb-personal-project-' + Teambox.models.user.id });
if (project) {
Teambox.views.sidebar.apps_list.addApp(
"project_" + project.get('permalink') + "_pages",
"Personal notes",
"#!/projects/" + project.get('permalink') + "/pages",
@micho
micho / gist:3658172
Created Sep 6, 2012
Cohort analysis for First Steps
View gist:3658172
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:3341189
Created Aug 13, 2012
posted_at relative time
View gist:3341189
/*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()