Skip to content

Instantly share code, notes, and snippets.

View ktopping's full-sized avatar

Kieran Topping ktopping

  • Unbound, and self
  • Dublin, Ireland
View GitHub Profile
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter < AbstractAdapter
class StatementPool < ConnectionAdapters::StatementPool
def connection_active?
@connection.query 'SELECT 1'
true
rescue PGError
false
end
@ktopping
ktopping / fake-s3-config.rb
Last active December 1, 2016 14:55
fake s3 config
# Add the following to /etc/hosts:
127.0.0.1 local.s3.endpoint local-bucket.local.s3.endpoint
# Run the following in your rails console, in order to create a bucket:
s3=AWS::S3.new(
:access_key_id => 'anything',
:secret_access_key => 'anything',
:s3_endpoint => 'local.s3.endpoint',
:s3_port => 4567,
:use_ssl => false
@ktopping
ktopping / ignore_depreciations.rb
Created October 23, 2012 15:55 — forked from timruffles/ignore_depreciations.rb
how to selectively ignore rails / activesupport::depreciation messages
if Rails.env.production?
# silence the deprecation warnings on Heroku
# Thanks to: https://gist.github.com/2237443
ActiveSupport::Deprecation.behavior = lambda do |msg, stack|
unless /vendor\/plugins/ =~ msg
ActiveSupport::Deprecation::DEFAULT_BEHAVIORS[:stderr].call(msg,stack) # whichever handlers you want - this is the default
end
end
end
@ktopping
ktopping / gist:2775936
Created May 23, 2012 15:35
cache headers
def images
... authenticate
... get @images from somewhere
... get user_id and brochure_id from somewhere
if stale?(:etag => Image.images_key(@images, "#{user_id},#{brochure_id}"))
respond_to do |format|
format.json {
response.headers['Cache-Control'] = 'public, max-age=2592000' # 1 month
@ktopping
ktopping / gist:2775902
Created May 23, 2012 15:28
gen md5 hash
# note the caller ensures that "prefix" consists of something
# uniquely identifying the user/brochure combination
def images_key(images, prefix = "")
key = "#{prefix} "
images.each do |im|
key += "#{im.file.size} #{im.file_updated_at}"
end
Digest::MD5.new.hexdigest(key)
end
@ktopping
ktopping / gist:2775401
Created May 23, 2012 14:03
is standalone?
// Thanks to http://cubiq.org/add-to-home-screen
var isSafari = navigator.appVersion.match(/Safari/gi);
var isStandalone = navigator.standalone;
// Earlier I had been labouring with:
var isStandalone = navigator.userAgent.match(/WebKit.*Mobile/) && !navigator.userAgent.match(/Safari/);
--- a/jquery.flips.js
+++ b/jquery.flips.js
@@ -140,7 +140,7 @@
if( this.History.getState().url.queryStringToJSON().page !== page ) {
- this.History.pushState( null, null, '?page=' + page );
+ // this.History.pushState( null, null, '?page=' + page );
@ktopping
ktopping / gist:2768450
Created May 22, 2012 11:23
dynamic flip
<div id="flip" class="container">
<div class="loading" style="position: absolute; left: 100px; top: 200px; font-size: 15px;">
<div id="loading">loading...</div>
</div>
</div>
...
<script type="text/javascript">
$(function () {
class Event < ActiveRecord::Base
...
has_many :options, :class_name => "EventOption", ...
accepts_nested_attributes_for :options
...
end
<%= form_for @event, :url => (@event.new_record? ? events_path : event_path(@event)) do |f| %>
...
<%= f.fields_for :options, @event.options do |f2| %>
...
<%= f2.text_field :name %>
...
<$ end %>
...
<% end %>