Skip to content

Instantly share code, notes, and snippets.

View barelyknown's full-sized avatar

Sean Devine barelyknown

View GitHub Profile
@barelyknown
barelyknown / unobtrusive_poller.js.coffee
Last active April 25, 2019 21:01
Unobtrusive JavaScript solution for polling in a Rails application
###
Unobtrusive JavaScript solution for polling in a Rails application
Introduction:
Add a polling-placeholder wrapper div to any partial and add a data attribute
named poll that should be equal to "true" until you want to stop polling.
The default polling frequency will be used unless you provide an "interval" data
attribute which should be the number of milliseconds to use for the interval.
@barelyknown
barelyknown / gist:7815117
Created December 5, 2013 22:24
out of band garbage collection results
{"RUBY_GC_MALLOC_LIMIT"=>100000000, "RUBY_HEAP_MIN_SLOTS"=>1632000}
starting memory
---
:count: 38
:heap_used: 4183
:heap_length: 4183
:heap_increment: 0
:heap_live_num: 687279
:heap_free_num: 1014369
@barelyknown
barelyknown / histogram_by_letter.txt
Created December 12, 2013 22:13
Histogram of word count by letter.
a .............
b .............
c ....................
d ............
e ........
f .........
g .......
h .........
i ........
j ..
@barelyknown
barelyknown / the_talk_show_64_google_transcription.txt
Last active December 31, 2015 09:09
Google speech-to-text transcription of Episode 64 (One Star) of The Talk Show with John Gruber and Daniel Jalkut. Transcribed in 5 second chunks.
how much does my mouth almost lost my fingertips I yesterday because I
decided to run with I
glove wear post literally thinking
how about a mile and a half for my home I should have gotten
computer programmer fingertip insurance b****
idle problems riding my dick finger injury 2 years ago just one
finger is martyr think you're going to poster
become an expert in the speech recognition systems
free pad thai
never really thought about it but its gotta be the worst of the worst use case for
@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
@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
@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