Skip to content

Instantly share code, notes, and snippets.

View damncabbage's full-sized avatar
🙅‍♀️
permanent omnishambles

Robin Howard damncabbage

🙅‍♀️
permanent omnishambles
View GitHub Profile
@mipearson
mipearson / i_heart_asset_pipeline.md
Created April 16, 2012 02:11
I <3 the Asset Pipeline

I <3 the Asset Pipeline

People talk shit on Sprockets and the Asset Pipeline all the time. I get it. It's pretty confusing and when it breaks it can break in really undesirable ways. I was originally very sceptical, and I strongly considered upgrading to Rails 3.2 with sprockets disabled.

I didn't, and I'm glad I've stuck with the pipeline. Here's why:

  1. If you're using digested assets (by default you are), asset expiry just works. No cache clearing during dev, no "wait a few minutes for the CSS to expire", no expiring every asset on every deploy, no deployment issues where people get new HTML and old CSS or JS. Sprocket's digest strategy has so far been excellent and I'm glad it's there.

  2. SASS and CoffeeScript just work. No running guard or compass to watch and auto-compile your shit, relatively seamless integration into Rails, and effective separation of vendored code from application code.

@jfirebaugh
jfirebaugh / example_spec.js.coffee
Created April 25, 2012 18:19
Auto-restoring sinon fakes with Konacha
# require spec_helper
Test =
fn: -> 'result'
it 'auto-resets sinon fakes', ->
@stub(Test, 'fn')
Test.fn()
Test.fn.should.have.been.called
@fryguy1013
fryguy1013 / realtime.html
Created April 30, 2012 22:32
Realtime simplegraph
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://jquery-json.googlecode.com/files/jquery.json-2.2.min.js"></script>
<script type="text/javascript" src="http://jquery-websocket.googlecode.com/files/jquery.websocket-0.0.1.js"></script>
@cjheath
cjheath / datol.cxx
Created July 19, 2012 06:52
Conversion of year/month/day to day since epoch, and back (with weekday)
#define OFFS -306 /* Offset to epoch-day (Day 1 is 1/1/0001) */
#define WD 0L /* Day of week offset */
/*
* datol: takes a YMD date, and returns the number of days since some base
* date (in the very distant past).
*
* Handy for getting date of x number of days before/after a given date.
* A date is valid if ltodate() yields the same YMD you started with.
*
@pda
pda / query_spy.rb
Created September 3, 2012 04:05
QuerySpy for counting ActiveRecord queries, asserting against n+1 regressions.
# An SQL query spy derived from the perhaps deprecated SQLCounter
# in ActiveRecord::TestCase and/or activerecord/test/cases/helper.rb
class QuerySpy
# Returns the number of queries executed by yielding the given block.
# Examples:
#
# QuerySpy.count { get "/things" }.should == 1
#
# create_a_thing
@tommeier
tommeier / Rakefile
Created September 20, 2012 05:25
Rake Timer
require 'rake_timer'
@dnagir
dnagir / credit_card.rb
Created November 11, 2012 22:10
CreditCard class
class CreditCard
include ActiveAttr::Model
attribute :number
attribute :expiry
attribute :cvn
attribute :name
validate :must_be_valid
validates :number, :expiry, :cvn, :name, presence: true
@travisbrown
travisbrown / needle-in-haystack.scala
Created November 13, 2012 22:57
Digging through arbitrarily nested case classes, tuples, and lists
/**
* Digging through arbitrarily nested case classes, tuples, and lists
* by Travis Brown
*
* In response to this question by Channing Walton on the Shapeless dev list:
*
* https://groups.google.com/d/msg/shapeless-dev/hn7_U21tupI/Zm9h3uNb51gJ
*
* Tested with Scala 2.9.2 and Shapeless 1.2.3. Should work on 1.2.2 with minor edits.
*/
@sam
sam / gist:4113718
Created November 19, 2012 20:36
QBE example
module Query
class Expression
attr_reader :field, :operator, :target
def initialize(field, operator, target)
@field, @operator, @target = field, operator, target
end
end
@juliocesar
juliocesar / gist:4263855
Created December 12, 2012 00:49
Using Backbone.View with regular (read: not all rendered in JS) HTML pages.

The idea is you can still use Backbone.View to structure components in the screen. Run the code below with each page render.

In CoffeeScript:

$ ->
  for el in $('[data-view]')
    $el = $ el
    viewName = $el.data 'view'
    view = window[viewName]

new view(el: el) if view?