Skip to content

Instantly share code, notes, and snippets.

View barelyknown's full-sized avatar

Sean Devine barelyknown

View GitHub Profile
@barelyknown
barelyknown / route.js
Created June 3, 2015 17:31
Basic paginating route.
// using ember-jsonapi-resources as its store
import Ember from 'ember';
export default Ember.Route.extend({
defaultOffset: 0,
offset: null,
@barelyknown
barelyknown / gist:8f71f61cc2392e7cf847
Created May 26, 2015 02:06
Programming challenge: merging overlapping intervals
class IntervalMerger
def initialize(*intervals)
@intervals = intervals
end
def merge
@intervals.reduce([]) do |merged, i|
is_merged = false
merged.each_with_index do |m, index|
@barelyknown
barelyknown / gist:0f7906cbd70906020a1b
Last active August 29, 2015 14:19
Updating Ember Relationship Example
// When I have a route that provides a model through a relationship...
// app/routes/organization/buyer/loads.js
export default Ember.Route.extend(AuthenticatedRouteMixin, {
model: function() {
return this.modelFor('organization/buyer').get('loads');
}
});
// And I receive new records via the server (via push or poll),
When Charley awoke one morning, he looked from the window and saw the ground deeply covered with snow. On the side of the house nearest the kitchen, the snow was piled higher than Charley’s head.
“We must have a path through this snow,” said his father. “I would make one if I had time, but I must be at the office early this morning. “Do you think you could make the path, Son?” he asked little Charley.
“I? The snow is higher than my head! How could I ever cut a path through that snow?”
“How? By doing it little by little. Suppose you try,” said his father as he left for his office.
So Charley got the snow shovel and set to work. He threw up first one shovelful and then another; but it was slow work.
“I don’t think I can do it, Mother,” he said. “A shovelful is so little, and there is such a heap of snow.”
“Little by little, Charley,” said his mother. “That snow fell in tiny bits, flake by flake, but you see what a great pile it has made.”
“Yes, Mother, I see,” said Charley. “If I throw it away little by little,
@barelyknown
barelyknown / gist:153e94c0d847e15251a8
Last active January 23, 2018 11:28
Testing after_commit :do_something, on: :create
describe "#after_commit" do
context "on: :create" do
before do
expect(subject).to receive(:transaction_record_state).with(:new_record).and_return(true)
end
it "calls initiate_async" do
expect(subject).to receive(:initiate_async)
subject.run_callbacks(:commit)
end
end
// ActiveTable - a bookmarklet to make tables sortable and editable
function init() {
var aHrows = getHrows();
var numHrows = aHrows.length;
var aHidden = getHiddenColumns();
ATpopup = document.createElement("div");
ATpopup.style.cssText = "position: absolute; visibility: hidden; padding: 0; font-family: Arial; background-color: rgba(255, 255, 255, 0.9); border-radius: .5em; text-align: center; box-shadow: .05em .05em .5em #00C;";
ATpopup.innerHTML = "<a href='sort' title='sort' onclick='sortColumn(); return false'><img border=0 src='http://stevesouders.com/images/sort_up_down.png' style='padding-top: 0.2em;'></a><br><a href='hide' style='color: #C00; font-family: monospace; font-size: 1.5em; text-decoration: none;' title='hide' onclick='hideColumn(); return false'>x</a>"; // TODO - use protocol-less URL for img
HTTP/1.1 200 OK
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Type: text/javascript; charset=utf-8
X-Request-Id: 04d52807-e2f7-4aba-b593-76990947c8c6
X-Runtime: 0.074197
Transfer-Encoding: chunked
b1c
BEFORE
------
Switched to branch 'master'
Seans-MacBook-Pro:regions seandevine$ bin/rake stats
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 73 | 59 | 3 | 9 | 3 | 4 |
| Helpers | 2 | 2 | 0 | 0 | 0 | 0 |
@barelyknown
barelyknown / rspec_context_private.rb
Last active August 29, 2015 14:01
Use shared context to keep private methods private, even if you're testing them. Now a gem --> https://github.com/barelyknown/rspec-context-private
# This is now a gem: https://github.com/barelyknown/rspec-context-private
# /spec/support/with_private_instance_methods_public.rb
RSpec.shared_context 'private', private: true do
before :all do
described_class.class_eval do
@saved_private_instance_methods = private_instance_methods
public *@saved_private_instance_methods
end
end
@barelyknown
barelyknown / simple_heroku_follower_solution.markdown
Last active February 18, 2019 23:21
Simple solution to use a follower database for some ActiveRecord reads.

Heroku recommends using Octopus to connect to followers.

But, Octopus doesn't work yet with Rails 4.1.

Here's a super simple solution to use a follower for some reads for an ActiveRecord class:

config/database.yml

follower_development:
  <<: *default