Skip to content

Instantly share code, notes, and snippets.

@mahemoff
mahemoff / application_helper.rb
Created December 23, 2011 09:54
Default data-remote='true' and data-type='html' for HIJAX style apps
def remote_link_to(name, path, options={})
options['remote'] = 'true'
options['data-type'] = 'html'
link_to(name, path, options)
end
@mahemoff
mahemoff / createStackScript.rb
Created January 3, 2012 14:26
Ruby Linode API
# See https://github.com/rick/linode
### CREATE STACKSCRIPT
require 'linode'
s = Linode::Stackscript.new :api_key => 'linode-key-which-you-can-request-from-your-account'
s.create :label => 'amazingbox', :distributionIDList => '64', :script => '#!/bin/bash\nls -latr'
# '64' happens to be the distro for Ubuntu 10.04 LTS.
# Find distribution IDs with Linode.new.avail.distributions.
@mahemoff
mahemoff / gist:1560593
Created January 4, 2012 15:38
control freak script: archive most recent 10 instapaper articles
$('<button>Archive Ten</button>')
.click(function() {
$('#bookmark_list a.archiveButton').slice(0,9).click();
})
.insertBefore($('body').children().first())
# include jQuery in the libraries tab and apply this script in http://instapaper.com/u
@mahemoff
mahemoff / fixhistory.coffee
Created January 10, 2012 22:09
"Prevent" popstate firing on hash change
currentPathname = null
window.onpopstate = (ev) ->
return if document.location.pathname == currentPathname
currentPathname = document.location.pathname
#... (now handle a real back-button or page load event)
@mahemoff
mahemoff / gist:1626362
Created January 17, 2012 11:40
Response from Google Plus Activities API (PHP)
stdClass Object
(
[kind] => plus#activityFeed
[etag] => "ZwWl8AwTPaXkrMWBfKc2FkKQ8tw/1E7E4zLv-EPrvXkeslyavUfGMj0"
[nextPageToken] => eJyNkzFIw0AUht-FlEZczuJayKKTdq6CkNEOKs4ujRAKUktNTSkOEh1U0E2dXAR16ySCoCCu4uriJm4KgpOuJne5u5fkAv6Fy-Xee__3-rgMv6DU82Fsze27tbbbadUanU2v5fmV9_PL3539ugGkAaW-2w68gQ9U5S0G66uevzc8rY6evB0aAIMuwETY24BtiFWWu_HAB2OlsXDXnOx_Xl8lqVC-t2-aL6_L9bnj562zme7DxfTTz1L1e_boo3sbxMUlADIFKYVstaOflCM2hK0m5EVwWiwjFaZhrsJKAJbGzcIRqoAU90FRwUGWSviLARKc78DWoZmzBKoMqslzdK5FpkymWCOEboxKfNShsuTd5nk4XSg9fLsoJDsoco19Tdzno9hY6iHQu9iTOJC5FESh5FlynGpQEsKkJjcn-RdMfBMoOkUu_BETLKqJo86YnGwQdQNQYRjODwsyEfUfsjVnht5EB3TiJXM1DU1ekixodp5tskLBTF8nkZBonvC4rR-XI9349xeidyYBoZiY6kxpBBfEu2j_BzL3RsU
[selfLink] => https://www.googleapis.com/plus/v1/people/106413090159067280619/activities/public?
[nextLink] => https://www.googleapis.com/plus/v1/people/106413090159067280619/activities/public?maxResults=20&pageToken=eJyNkzFIw0AUht-FlEZczuJayKKTdq6CkNEOKs4ujRAKUktNTSkOEh1U0E2dXAR16ySCoCCu4uriJm4KgpOuJne5u5fkAv6Fy-Xee_
@mahemoff
mahemoff / application_helper.rb
Created January 23, 2012 17:56
Smart date formatting - e.g. "27 minutes" "4 hours" "3 days, 15h" "4 months, 9d"
def duration(from, to=Time.now)
if to - from < 1.day
distance_of_time_in_words(from,to,false,:precision=>1)
else
return distance_of_time_in_words(from,to,false,:precision=>2, :two_words_connector=>'@')
.gsub(/@(\d+)\sseconds?/, ', \\1s')
.gsub(/@(\d+)\sminutes?/, ', \\1m')
.gsub(/@(\d+)\shours?/, ', \\1h')
.gsub(/@(\d+)\sdays?/, ', \\1d')
.gsub(/@(\d+)\sweeks?/, ', \\1w')
If you get this weird error from rake assets:precompile:
Invalid CSS after "...rder-radius: 0/": expected expression (e.g. 1px, bold), was ";"
Go find a line in bootstrap.css:
border-radius: 0 \0/;
and remove or change it to just 0. (Good enough anyway.)
@mahemoff
mahemoff / 999_add_indexes.rb
Created February 9, 2012 00:52
Rails mass migration to add indexes
class AddIndexes < ActiveRecord::Migration
INDEXES = {
:blogs => %w/title author_id/,
:comments => %w/blog_id subject poster_id/,
:events => %w/name place when/
}
def up
INDEXES.each { |table, cols |
@mahemoff
mahemoff / MOVED
Created February 10, 2012 17:05
JSON cities lat-lon (moved)
Made this a proper GitHub Repo:
https://github.com/mahemoff/geodata
@mahemoff
mahemoff / bootstrap-padding.css
Created March 25, 2012 03:55
SASS child selector can be used hierarchically
article
> .row:first-child
>
.span1,.span2,.span3,.span4,.span5,.span6,.span7,.span8,.span9,.span10,.span11,.span12
padding-top: 20px
> .row:last-child
>
.span1,.span2,.span3,.span4,.span5,.span6,.span7,.span8,.span9,.span10,.span11,.span12
padding-bottom: 20px