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 / blackjack-rails-api-spec-documentation-after-TableRuleSet-model-implemented.txt
Last active August 29, 2015 14:26
blackjack-rails-api spec documentation after TableRuleSet model implemented
Seans-MacBook-Pro:blackjack-rails-api seandevine$ bundle exec rspec --format documentation
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
Randomized with seed 31252
V1::CardResource
has no updatable fields
has no creatable fields
@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() {
@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