Skip to content

Instantly share code, notes, and snippets.

@mahemoff
mahemoff / elasticsearch.rake
Created September 19, 2012 19:36 — forked from jarosan/elasticsearch.rake
Elasticsearch reindex task
# Run with: rake environment elasticsearch:reindex
# Begins by creating the index using tire:import command. This will create the "official" index name, e.g. "person" each time.
# Then we rename it to, e.g. "person20121001" and alias "person" to it.
namespace :elasticsearch do
desc "re-index elasticsearch"
task :reindex => :environment do
klasses = [Place, Person, Caption]
@mahemoff
mahemoff / gist:3824340
Created October 3, 2012 01:17
devise navigational
# ==> Navigation configuration # Lists the formats that should be treated as navigational. Formats like
# :html, should redirect to the sign in page when the user does not have # access, but formats like :xml or :json, should return 401.
# # If you have any extra navigational formats, like :iphone or :mobile, you
# should add them to the navigational formats lists. #
# The :"*/*" and "*/*" formats below is required to match Internet # Explorer requests.
# config.navigational_formats = [:"*/*", "*/*", :html] config.navigational_formats = [:"*/*", "*/*", :html, :json]
@mahemoff
mahemoff / gist:3911431
Created October 18, 2012 12:16
HNpod tips for guests
Hello Everyone:
To ensure that we have a smooth recording session and good audio quality we have prepared a few recording tips.
Tips for improving your Audio Quality.
Please check the following:
* The Killer App: Most important thing is to turn off Skype, MSN, Spotify, any other peer-to-peer/file-sharing apps, online games and video downloads ... basically anything that could suck giant wads of bandwidth.
@mahemoff
mahemoff / gist:3931897
Created October 22, 2012 15:00
canonicalize feed urls
def test_feedburner_aliased
series = Series.create title: 'foo', url: 'http://feeds.feedburner.com/InTheBleachersPodcast'
assert_not_nil Series.find_by_url('http://feeds.feedburner.com/inthebleacherspodcast')
assert_not_nil Series.find_by_url('http://feeds.feedburner.com/inthebleacherspodcast/')
assert_not_nil Series.find_by_url('http://feeds.feedburner.com/inthebleacherspodcast.xml')
assert_not_nil Series.find_by_url('http://feeds.feedburner.com/inthebleacherspodcast?format=rss')
assert_not_nil Series.find_by_url('http://feeds2.feedburner.com/inthebleacherspodcast?format=rss')
assert_not_nil (series = Series.find_by_url('http://feeds.feedburner.com/InTheBleachersPodcast'))
assert_equal 'http://feeds.feedburner.com/inthebleacherspodcast', series.url
@mahemoff
mahemoff / mousetrap-bind.js
Created November 6, 2012 00:42 — forked from ccampbell/mousetrap-bind.js
Extends mousetrap.js to support passing a dictionary into bind method. Just include this js after you include mousetrap.
/**
* Overwrites default Mousetrap.bind method to optionally accept
* an object to bind multiple key events in a single call
*
* You can pass it in like:
*
* Mousetrap.bind({
* 'a': function() { console.log('a'); },
* 'b': function() { console.log('b'); }
* });
@mahemoff
mahemoff / staptrap.coffee
Created November 6, 2012 04:18
Mousetrap.js support for Bootstrap with help dialog
# Monkey-patch stopCallback so that Mousetrap will ignore any keyboard action during modal
((originalStopCallback) -> Mousetrap.stopCallback = ->
return true if $('body.modal-open').length
originalStopCallback.apply(Mousetrap, arguments)
)(Mousetrap.stopCallback)
# "?" key will produce keyboard shortcuts dialog (as on Twitter and GitHub)
# It fetches the dialog content on demand for performance reasons
Mousetrap.bind '?', ->
$.get '/docs/keyboard_shortcuts', (html) ->
@mahemoff
mahemoff / gist:4089463
Created November 16, 2012 18:03
jquery.touchcarousel-1.1.js.patch
index 3a9730c..d3f1a17 100755
--- a/vendor/assets/javascripts/jquery.touchcarousel-1.1.js
+++ b/vendor/assets/javascripts/jquery.touchcarousel-1.1.js
@@ -981,6 +981,9 @@
if(this.settings.scrollbarAutoHide) {
this._hideScrollbar();
}
+ if(this.settings.onClick !== null) {
+ this.settings.onClick.call(this, e);
+ }
@mahemoff
mahemoff / gist:4136057
Created November 23, 2012 15:09
Smart capitalize for Ruby/Rails
Class String
def titleize
self.split(/\s+/).map{|word| word.slice(0,1).capitalize + word.slice(1..-1)}.join(' ')
end
end
@mahemoff
mahemoff / deleted question
Created January 8, 2013 12:09
Deleted SO question as I realised an intermediate cache probably shouldn't work this way. Cloudflare doesn't know if ETag has changed, so it is probably correct to pass it to the server. I'm actually looking for some kind of declared version concept which may not be in HTTP (but could be hacked by adding a version/ETAG to the path).
Does CloudFlare Honor If-None-Match Header (ETags passed in the request)?
I've observed that a basic call (with no ETag or timestamp) will yield a 304 from my server to Cloudflare, but then Cloudflare passes it back to the client as a 200 with no ETag field.
And if the client does include an ETag in the request (using If-None-Match header), Cloudflare simply doesn't honor it AFAICT. It still passes the call through to my server, which yields 304, and then responds with a 200 response.
I may have the wrong expectation from a CDN, but I thought it would be able to issue 304 and not access my server if the correct ETag is passed in.
@mahemoff
mahemoff / record.rb
Created January 22, 2013 03:53
Privacy in Tire/ElasticSearch
class Channel < ActiveRecord::Base
include Tire::Model::Search
# Let's *NOT* include Tire's default callbacks ...
### include Tire::Model::Callbacks
# ... and instead handle them ourselves
after_save :search_index
after_destroy :search_index