Skip to content

Instantly share code, notes, and snippets.

@th3james
th3james / gist:976444
Created May 17, 2011 13:17
Active link style helper
#returns 'active' if current page == uri
#depth specifies how much of the URL is compared, either [:controller, :action, :complete]
def class_for_link(uri, depth=:action)
path_hash = ActionController::Routing::Routes.recognize_path(uri, { :method => :get })
match = case depth
when :controller
path_hash[:controller] == controller.controller_name
when :complete
uri == request.path
@th3james
th3james / gist:976484
Created May 17, 2011 13:42
Active link example
<%= link_to "COUNTRIES", entities_path(:countries), :class => class_for_link(model_path(4), :complete) %>
$(function(){
// Activate PJAX on ul.menu links
// Response will be loaded into #main element on the page
$('ul.menu a').pjax('#main')
})
// from
if (some_var == null
// to
if (some_var === null)
var some_var;
some_var === null; // false
some_var == null; // true
some_var; // undefined
if (some_var === undefined)
undefined = "don't ever do this";
typeof(some_var) // returns 'undefined'
//Therefore, the correct way in javascript to check if a variable has a value is:
typeof some_var === 'undefined'
@th3james
th3james / gist:2558102
Created April 30, 2012 12:57
Postgres != slowness
# Crazy Slow
UPDATE protected_areas SET criteria = 'Not Applicable' WHERE designation_id != 5;
# Near instant
UPDATE protected_areas SET criteria = 'Not Applicable'
FROM protected_areas AS pa
LEFT OUTER JOIN designations ON pa.designation_id = designations.id
WHERE designations.id = 5 AND pa.designation_id = NULL;
@th3james
th3james / gist:2952921
Created June 19, 2012 08:08
vim_rc 06/12
" Somewhat copied from https://github.com/spf13/spf13-vim/blob/master/.vimrc
set nocompatible " We're running Vim, not Vi!
call pathogen#runtime_append_all_bundles() " add pathogen
" UI stuff
syntax on " Enable syntax highlighting
set background=dark " Assume a dark background
color ir_black
set backspace=indent,eol,start " backspace for dummys