Skip to content

Instantly share code, notes, and snippets.

@solnic
solnic / require_measure.rb
Last active August 29, 2015 14:14
A hack to measure how long it takes to require bundled gems in a rails app
REQUIRE_DATA = {}
BUNDLED_GEMS = `bundle show | grep "*" | awk '{print $2}'`.split("\n").sort
require 'bigdecimal'
def require(name)
start = Time.now
ret = super
stop = Time.now
total = BigDecimal(stop-start, 6)
REQUIRE_DATA[name] = total if BUNDLED_GEMS.include?(name)
@claptimes5
claptimes5 / best_in_place.noty.js
Last active December 21, 2017 14:57
Best in place with Noty
// Noty - http://ned.im/noty/#/about
// Best in place - https://github.com/bernat/best_in_place
$(document).on('best_in_place:error', function (event, request, error) {
'use strict';
// Display all error messages from server side validation
$.each(jQuery.parseJSON(request.responseText), function (index, value) {
if (typeof value === "object") {
value = index + " " + value.toString();
}

TIL attr_* methods are optomized.

class Whatever
  def foo
    @foo
  end

  attr_reader :bar
end
class CreateUserForm
include ActiveModel::Model
attr_accessor :email
attr_accessor :name
def initialize
@user = User.new
end
module Publisher
extend self
# delegate to ActiveSupport::Notifications.instrument
def broadcast_event(event_name, payload={})
if block_given?
ActiveSupport::Notifications.instrument(event_name, payload) do
yield
end
else
@somebox
somebox / presenters.md
Last active March 26, 2022 02:12
Thoughts About Rails Presenters

Thoughts about Rails Presenters

This is a collection of links, examples and rants about Presenters/Decorators in Rails.


The "Decorator" pattern slowly started gaining popularity in Rails several years ago. It is not part of core Rails, and there's many different interpretations about how it should work in practice.

Jay Fields wrote about it in 2007 (before he switched back to Java and then Clojure): http://blog.jayfields.com/2007/03/rails-presenter-pattern.html

@jashkenas
jashkenas / semantic-pedantic.md
Last active May 7, 2025 01:36
Why Semantic Versioning Isn't

Spurred by recent events (https://news.ycombinator.com/item?id=8244700), this is a quick set of jotted-down thoughts about the state of "Semantic" Versioning, and why we should be fighting the good fight against it.

For a long time in the history of software, version numbers indicated the relative progress and change in a given piece of software. A major release (1.x.x) was major, a minor release (x.1.x) was minor, and a patch release was just a small patch. You could evaluate a given piece of software by name + version, and get a feeling for how far away version 2.0.1 was from version 2.8.0.

But Semantic Versioning (henceforth, SemVer), as specified at http://semver.org/, changes this to prioritize a mechanistic understanding of a codebase over a human one. Any "breaking" change to the software must be accompanied with a new major version number. It's alright for robots, but bad for us.

SemVer tries to compress a huge amount of information — the nature of the change, the percentage of users that wil

@staltz
staltz / introrx.md
Last active May 15, 2025 10:37
The introduction to Reactive Programming you've been missing
@steveklabnik
steveklabnik / rust.md
Created June 8, 2014 02:03
Rust changes through versions

Originally taken from here, cached as a gist so I can find it later. "Angolmois" is a music video game, that plays real BeatMania files, so it's a pretty full-featured game. At least, as full as you're gonna find in Rust from as long ago as it was started.

Angolmois Rust edition went through six different Rust releases without almost no change on the features, and the changes are as follows:

@chrisb
chrisb / gist:4d6a09c6cc1ca2e1b14e
Last active November 25, 2022 04:15
Homebrew, Ruby, and Rails on OS X 10.10

OS X 10.10 Guide

Here's what I did to get things working.

1. Install Xcode 6

Yep, over at: https://developer.apple.com

2. Install the Command Line Tools (CLT)