Skip to content

Instantly share code, notes, and snippets.

var Arch; if (!Arch) Arch = {}; // set up custom namespace 'Arch'
Arch.AjaxPagination = function(paginationContainer, storiesContainer, filtersContainer) {
// Only html5 browsers can use ajax pagination. We don't want no stinkin' hashbang URLs.
if (!history.pushState) {
return;
}
this.$paginationContainer = $(paginationContainer);
@arches
arches / Procfile
Last active February 16, 2021 10:44
A little hack to restart Heroku web dynos when they hit 1000MB of memory
monitor: bundle exec ruby monitor.rb

Keybase proof

I hereby claim:

  • I am arches on github.
  • I am arches (https://keybase.io/arches) on keybase.
  • I have a public key whose fingerprint is 1362 D442 CE1B 48CC B351 EB24 07EE E79C E2D8 8D2C

To claim this, I am signing this object:

@arches
arches / public-javascripts-base-flash.js
Created March 5, 2012 05:05
Javascript for Flash Messages
var Arch; if (!Arch) Arch = {}; // set up custom namespace 'arch'
Arch.Flash = {
showError: function(message) {
if (message == "") return;
$('#flash-msg .user-msg-detail').removeClass('notice');
$('#flash-msg .user-msg-detail').addClass('error');
$('#flash-msg .user-msg-detail span').html(message);
$('#flash-msg').show();
},
@arches
arches / squirt
Last active October 13, 2016 15:22 — forked from foozmeat/squirt
squirt: upload a file to a slack channel from the cli
#!/usr/bin/env ruby
require 'json'
require 'shellwords'
if ARGV.length < 3 then
puts "Usage: squirt <filename> <channel> <comment>"
exit
end
@arches
arches / instance_block.rb
Last active February 17, 2016 17:56
Syntactic sugar for simple filtering. A halfway point between posts.select(&:published) and posts.select{|post| post.comments.any?}
# before - each object in the enumerable is passed to the block
posts.select { |post| post.comments.any? }
class Array
def select(&blk)
if blk.arity == 0
super { |obj| obj.instance_exec &blk }
else
super
end
@arches
arches / bob.rb
Created December 9, 2013 16:32
bob
require 'forwardable'
class Bob
def hey(message)
message = Message.new(message)
case
when message.shouting?
"Woah, chill out!"
when message.question?
@arches
arches / cart.rb
Last active December 29, 2015 10:59
hash-backed shopping cart w session default
require 'active_support/hash_with_indifferent_access'
class Cart
include Enumerable
attr_writer :storage
def each(&blk)
deal_ids.each(&blk)
end
@arches
arches / example.rb
Last active December 25, 2015 03:09
table_print for pure ruby objects
> my_array = [{server: "localhost", ip: "192.168.0.1"}, {server: "google dns", ip: "8.8.8.8"}]
> tp my_array
SERVER | IP
-----------|------------
localhost | 192.168.0.1
google dns | 8.8.8.8
# or with objects
> class ServerInfo
@arches
arches / kaboom.rb
Created October 4, 2013 15:08
so SOMETIMES you can return from inside a block...?
def foobar(&blk)
yield "bar" if blk
"foo"
end
> foobar
=> "foo"
> foobar {|x| puts x}
bar
=> "foo"