Skip to content

Instantly share code, notes, and snippets.

View barelyknown's full-sized avatar

Sean Devine barelyknown

View GitHub Profile
@barelyknown
barelyknown / stats.rake
Created August 28, 2015 13:30
Setup for `bundle exec rake stats`
task :stats => "app:stats_setup"
# insert additional types into the statistics table and sort the list
namespace :app do
task :stats_setup do
require 'rails/code_statistics'
app_entries, spec_entries = [], []
until ::STATS_DIRECTORIES.empty?
entry = STATS_DIRECTORIES.shift
@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
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 |
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
// 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
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: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),
@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 / 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:ed18b2b7b4f258b691e3
Created July 11, 2015 15:29
login with valid credentials by pressing enter from password input
// login.hbs
// {{input value=identification name='identification'}}
// {{input value=password name='password' enter='authenticate'}}
// <button name='login' {{action 'authenticate'}}>Login</button>
// this test passes
test('login with valid credentials', function(assert) {
visit('/login');
andThen(function() {