Skip to content

Instantly share code, notes, and snippets.

@ryansch
ryansch / hooks_controller.rb
Created September 28, 2010 15:03
Rails Controller for Chargify Webhooks
require 'md5'
class Chargify::HooksController < ApplicationController
protect_from_forgery :except => :dispatch
before_filter :verify, :only => :dispatch
EVENTS = %w[ test signup_success signup_failure renewal_success renewal_failure payment_success payment_failure billing_date_change subscription_state_change subscription_product_change ].freeze
def dispatch
event = params[:event]
@garyharan
garyharan / _mixins.scss
Created May 5, 2011 15:46
Useful scss mixins (rounded corners, gradients, text-field, button)
@mixin box-shadow($top, $left, $blur, $color, $inset: false) {
@if $inset {
-webkit-box-shadow:inset $top $left $blur $color;
-moz-box-shadow:inset $top $left $blur $color;
box-shadow:inset $top $left $blur $color;
} @else {
-webkit-box-shadow: $top $left $blur $color;
-moz-box-shadow: $top $left $blur $color;
box-shadow: $top $left $blur $color;
}
@manast
manast / interval.js
Last active November 15, 2023 22:08
Accurate Javascript setInterval replacement
function interval(duration, fn){
var _this = this
this.baseline = undefined
this.run = function(){
if(_this.baseline === undefined){
_this.baseline = new Date().getTime()
}
fn()
var end = new Date().getTime()
@jwo
jwo / registrations_controller.rb
Created September 30, 2011 23:11
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@dsamarin
dsamarin / Complex.js
Created October 3, 2011 03:11
Complex numbers in JavaScript
var Complex = function(real, imag) {
if (!(this instanceof Complex)) {
return new Complex (real, imag);
}
if (typeof real === "string" && imag == null) {
return Complex.parse (real);
}
this.real = Number(real) || 0;
@canton7
canton7 / gist:1268587
Last active October 18, 2016 19:40
git merge -s theirs

How to do a git merge -s theirs

One way of many...

This is one way which keeps the history looking like you'd expect.

Command is equivalent to git checkout MINE; git merge -s theirs HERS.

@methodin
methodin / prims.js
Created January 8, 2012 06:33
Prim's Algorithm
// Represents an edge from source to sink with capacity
var Edge = function(source, sink, capacity) {
this.source = source;
this.sink = sink;
this.capacity = capacity;
};
// Main class to manage the network
var Graph = function() {
this.edges = {};
@jonathantneal
jonathantneal / Demo
Created April 18, 2012 17:13
addEventListener for IE8
http://jsfiddle.net/GuQaV/show/
@masak
masak / explanation.md
Last active April 11, 2024 02:50
How is git commit sha1 formed

Ok, I geeked out, and this is probably more information than you need. But it completely answers the question. Sorry. ☺

Locally, I'm at this commit:

$ git show
commit d6cd1e2bd19e03a81132a23b2025920577f84e37
Author: jnthn <jnthn@jnthn.net>
Date:   Sun Apr 15 16:35:03 2012 +0200

When I added FIRST/NEXT/LAST, it was idiomatic but not quite so fast. This makes it faster. Another little bit of masak++'s program.

@mbostock
mbostock / .block
Last active November 30, 2017 00:51 — forked from mbostock/.block
Pie Chart
license: gpl-3.0
redirect: https://beta.observablehq.com/@mbostock/d3-pie-chart