Skip to content

Instantly share code, notes, and snippets.

View wrburgess's full-sized avatar
:shipit:
Shippin'

Randy Burgess wrburgess

:shipit:
Shippin'
View GitHub Profile
@wrburgess
wrburgess / ruby_find_duplicates.rb
Created January 30, 2014 20:30
Finding duplicate items in an array #ruby
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]
@wrburgess
wrburgess / being_retry.rb
Created January 31, 2014 22:15
rails retry method with partial search results issue
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}"
require "spec_helper"
describe ExampleController do
context "GET #index" do
let(:resources) { FactoryGirl.create_list(:resource) }
before do
get :index
end
: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);
})();
@wrburgess
wrburgess / mailchimp.haml
Created February 17, 2014 05:29
Mailchimp Embedded Email Form in Haml
%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" }/
@wrburgess
wrburgess / MyView.js
Created February 17, 2014 22:30 — forked from jhirn/MyView.js
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({
}));
@wrburgess
wrburgess / using_placehold_it_to_seed_images.rb
Created February 21, 2014 23:39
Use placehold.it to seed a carrierwave attribute on Rails model
clipbin.update_attribute(:remote_exhibit_image_url, "http://placehold.it/200x240/e0e0e0.png")
@wrburgess
wrburgess / active_admin_html_column.rb
Created February 27, 2014 22:04
active admin html column
column "Username<br>Password<br>Account&nbsp;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
@wrburgess
wrburgess / gemfile.rb
Created March 5, 2014 20:22
handy stuff
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"
require "spec_helper"
describe ExampleController do
context "GET #index" do
let(:resources) { FactoryGirl.create_list(:resource) }
before do
get :index
end