Skip to content

Instantly share code, notes, and snippets.

View blairanderson's full-sized avatar

Blair Anderson blairanderson

View GitHub Profile
@blairanderson
blairanderson / will_paginate-custom_renderer.3.0.7.rb
Last active March 22, 2017 23:08
will_paginate (3.0.7) custom renderer. The commented out code is the default code for this version of the gem. Using `super` as written below will return the default values. This lets you over-ride and test separately.
# will_paginate(collection, renderer: PaginationCustomLinkRenderer)
class PaginationCustomLinkRenderer < WillPaginate::ActionView::LinkRenderer
def prepare(collection, options, template)
options[:params] ||= {}
options[:params]['_'] = nil
options[:page_links] ||= false
options[:class] ||= "pagination"
super(collection, options, template)
end
@blairanderson
blairanderson / radio-html.md
Created March 11, 2017 23:32
5 star rating system HTML using radio buttons. credit to https://jsfiddle.net/leaverou/CGP87/
<fieldset class="rating">
    <legend>Please rate:</legend>
    <input type="radio" id="star5" name="rating" value="5" /><label for="star5" title="Rocks!">5 stars</label>
    <input type="radio" id="star4" name="rating" value="4" /><label for="star4" title="Pretty good">4 stars</label>
    <input type="radio" id="star3" name="rating" value="3" /><label for="star3" title="Meh">3 stars</label>
    <input type="radio" id="star2" name="rating" value="2" /><label for="star2" title="Kinda bad">2 stars</label>
    <input type="radio" id="star1" name="rating" value="1" /><label for="star1" title="Sucks big time">1 star</label>
</fieldset>
@blairanderson
blairanderson / typeahead-search.md
Created March 11, 2017 00:15
How to keep twitter typeahead search results OPEN to debug styling

after initializing typeahead:

var el = $('#your-input-element')
el.typeahead({...})

find the element and mess it with

var tt = el.data("ttTypeahead")
@blairanderson
blairanderson / download-images-from-urls.md
Created March 10, 2017 00:58
Download images from a bunch of CSVs
  1. Paste them into a images.csv

  2. open a new file called download.rb

require 'open-uri'
require 'csv'
require 'pry'

links_to_images = CSV.read('images.csv').flatten
@blairanderson
blairanderson / algolia-searchbox-debounce.md
Last active November 17, 2023 02:55
Algolia Search Debounce Example (using debounce with the algolia instant search.)

queryHook is a hook function that provides the query, and the search callback. You can do your own debouncing or special logic here.

default debounce example:

var timeout = 500;

var queryHook = _.debounce(function(query, search){
  search(query)
},timeout);
- data ||= {}
%table{:border => "0", :cellpadding => "5", :cellspacing => "5"}
- if data.is_a?(Hash)
%tbody
- data.each do |name, value|
%tr
%td
%strong= name
%td= value
@blairanderson
blairanderson / benchmark rollbar.md
Last active January 27, 2017 17:39
benchmarking methods
new_result = old_result = new_ms = old_ms = nil
old_ms = Benchmark.ms do
  old_result = Conversation.slow_method_thing(person_id) 
end

    # 5% of requests
if rand(20) == 1
  # [safely](https://github.com/ankane/safely) is shorthand for begin/rescue
 safely do