This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr = [ 1, 2, 3, 2, 4, 5, 3] | |
My favourite way of counting elements is: | |
counts = arr.group_by{|i| i}.map{|k,v| [k, v.count] } | |
# => [[1, 1], [2, 2], [3, 2], [4, 1], [5, 1]] | |
If you need a hash instead of an array: | |
Hash[*counts.flatten] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin | |
search = Clip.search_via_solr(@country, search_options) | |
response = search.instance_eval("@solr_result")["responseHeader"] | |
raise partial_results_flag if response["partialResults"].present? | |
rescue | |
max_search_attempts = 3 | |
@retries ||= 0 | |
if @retries < max_search_attempts | |
@retries += 1 | |
Rails.logger.info "Search Retry \##{@retries}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "spec_helper" | |
describe ExampleController do | |
context "GET #index" do | |
let(:resources) { FactoryGirl.create_list(:resource) } | |
before do | |
get :index | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:javascript | |
var _gaq = _gaq || []; | |
_gaq.push(['_setAccount', YOUR_CODE']); | |
_gaq.push(['_trackPageview']); | |
(function() { | |
var ga = document.createElement('script'); | |
ga.type = 'text/javascript'; ga.async = true; | |
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%form.form-inline#mc-embedded-subscribe-form{ action: "[sign_up_url]", method: "post", name: "mc-embedded-subscribe-form", novalidate: "", target: "_blank"} | |
%input#mce-EMAIL.required.email{ name: "EMAIL", type: "email", value: "", placeholder: "email"}/ | |
%div{ style: "position: absolute; left: -5000px;" } | |
%input{ type: "text", name: "[hex_code]", value:"" } | |
%input#mc-embedded-subscribe{name: "subscribe", type: "submit", value: "Subscribe" }/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.Views.MyView = Backbone.View.extend({ | |
initialize: function() { | |
_.bindAll(this); //Ignore this for now =) | |
this.template = JST['path/to/template']; | |
this.render(); | |
}, | |
render: function() { | |
this.$el.html(this.template({ | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clipbin.update_attribute(:remote_exhibit_image_url, "http://placehold.it/200x240/e0e0e0.png") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
column "Username<br>Password<br>Account Name".html_safe do |combine| | |
safe_join( | |
[ | |
best_in_place(combine, :simulator_username, type: :input, path: "/admin/accounts/#{combine.id}"), | |
best_in_place(combine, :simulator_password, type: :input, path: "/admin/accounts/#{combine.id}"), | |
best_in_place(combine, :account_name, type: :input, path: "/admin/accounts/#{combine.id}") | |
], | |
tag(:br) | |
) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "http://rubygems.org" | |
ruby "2.1.0" | |
gem "rails", "4.0.3" | |
gem "activeadmin", github: "gregbell/active_admin" | |
gem "aws-sdk", "1.34.1" | |
gem "bourbon", "3.1.8" | |
gem "cancan", "1.6.10" | |
gem "carrierwave", "0.9.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "spec_helper" | |
describe ExampleController do | |
context "GET #index" do | |
let(:resources) { FactoryGirl.create_list(:resource) } | |
before do | |
get :index | |
end |
OlderNewer