Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View plusjade's full-sized avatar
🐵
🚀 🤖

Jade Dominguez plusjade

🐵
🚀 🤖
View GitHub Profile
@defunkt
defunkt / range.rb
Created November 24, 2009 21:17
Mustache method_missing hack
require 'mustache'
class Ranger < Mustache
self.template = <<-template
{{#range_0_to_10}}
<option value="{{i}}">{{i}}</option>
{{/range_0_to_10}}
template
def range(first, last)
@mikeyk
mikeyk / gist:1329319
Created October 31, 2011 22:56
Testing storage of millions of keys in Redis
#! /usr/bin/env python
import redis
import random
import pylibmc
import sys
r = redis.Redis(host = 'localhost', port = 6389)
mc = pylibmc.Client(['localhost:11222'])
@thijsc
thijsc / gist:1391107
Created November 24, 2011 11:08
Select item from chosen js select with Capybara and Selenium
def select_from_chosen(item_text, options)
field = find_field(options[:from])
option_value = page.evaluate_script("$(\"##{field[:id]} option:contains('#{item_text}')\").val()")
page.execute_script("$('##{field[:id]}').val('#{option_value}')")
end
@douo
douo / wp_to_ruhoh.rb
Created August 21, 2012 13:07
wordpress export xml to ruhoh post
# coding: utf-8
# chcp 65001
require 'rubygems'
require 'hpricot'
require 'nokogiri'
require 'fileutils'
require 'yaml'
require 'time'
require 'pandoc-ruby'
@clintongormley
clintongormley / gist:4095280
Created November 17, 2012 12:00
Using synonyms in Elasticsearch

We create an index with:

  • two filters: synonyms_expand and synonyms_contract
  • two analyzers: synonyms_expand and synonyms_contract
  • three text fields:
    • text_1 uses the synonyms_expand analyzer at index and search time
    • text_2 uses the synonyms_expand analyzer at index time, but the standard analyzer at search time
    • text_3 uses the synonyms_contract analyzer at index and search time

.

@michael-harrison
michael-harrison / test_multi_select.rb
Created November 18, 2012 00:37
jQuery Chosen Testing with Capybara
=begin
Notes
=====
Labels: On the label you should put a "for" attribute if you're not using something like simple_form
This helps capybara to find your field
e.g. <label for="my_field_id">Some label</label>
=end
field = "Label on my field"
value = "existing option in list"
@mudasobwa
mudasobwa / plugins-views-helpers-paginator.rb
Last active December 29, 2015 19:39
Paginator helper for ruhoh, collapsing page links when there are a lot of posts.
module Ruhoh::Views::Helpers
module Paginator
# current_page is set via a compiler or previewer
# in which it can discern what current_page to serve
def paginator
per_page = config["paginator"]["per_page"] rescue 5
current_page = master.page_data['current_page'].to_i
current_page = current_page.zero? ? 1 : current_page
offset = (current_page-1)*per_page
@indolent-gnathostome
indolent-gnathostome / pagination.rb
Last active December 31, 2015 10:38
Independent, sortable pagination for ruhoh.rb (plugin)
module SortablePaginator
# provides helpful metrics for the paginator and mustache templates
def paginator_data
per_page = config["paginator"]["per_page"] rescue 5
paginator_sort = config["paginator"]["sort"] rescue 'desc'
current_page = master.page_data['current_page'].to_i
post_count = all.length
page_count = (post_count.to_f/per_page).ceil
if paginator_sort == 'asc'
@razor-x
razor-x / README.md
Last active February 19, 2020 10:26
Load GitHub Gists asynchronously and optionally specify which file to show.

Load GitHub Gists asynchronously

This is now a Bower package: [gist-async]. [gist-async]: https://github.com/razor-x/gist-async

Requires jQuery.

Jekyll plugin included that modifies the gist markup added by its gist Liquid tag.

Load GitHub Gists asynchronously and optionally specify which file to show.

@traviskaufman
traviskaufman / jasmine-this-vars.md
Last active September 19, 2022 14:35
Better Jasmine Tests With `this`

Better Jasmine Tests With this

On the Refinery29 Mobile Web Team, codenamed "Bicycle", all of our unit tests are written using Jasmine, an awesome BDD library written by Pivotal Labs. We recently switched how we set up data for tests from declaring and assigning to closures, to assigning properties to each test case's this object, and we've seen some awesome benefits from doing such.

The old way

Up until recently, a typical unit test for us looked something like this:

describe('views.Card', function() {