Skip to content

Instantly share code, notes, and snippets.

@rbeene
rbeene / order.rb
Created August 16, 2014 23:49 — forked from pcreux/order.rb
ActiveAdmin.register Order do
# Export the current collection of items with filtering and sorting
# List the current collection ids
collection_action :export_txt do
render :text => collection.map { |order| order.id }.join(', ')
end
# Add a button to index page to export current collection as txt
require 'factory_girl_rails'
require 'rspec'
require 'rspec-rails'
require 'rspec/mocks/standalone' # => if factories need stubs (for remote services for example)
include FactoryGirl::Syntax::Methods # make FG methods available at top level, so you can do `> create :user`
def reload_factories!
FactoryGirl.instance_variable_set(:@factories, nil) # => clear loaded factories/sequences
# FactoryGirl.instance_variable_set(:@sequences, nil)
@rbeene
rbeene / Guardfile
Created March 26, 2013 14:42 — forked from thbar/Guardfile
require 'childprocess'
guard 'shell' do
watch %r{^app/(.+)\.rb$} do |m|
`killall rake`
# Why this:
# - spawn a child process to avoid locking Guard
# - make sure that the child process has stdout and stdin otherwise it crashes
# - bonus point: get REPL access in the simulator!
# sample query right before results are output
"#<Tire::Search::Search:0x007fe12432be20 @indices=[\"members\"], @types=[], @options={}, @path=\"/members/_search\", @query=#<Tire::Search::Query:0x007fe12432b358 @value={:bool=>{:must=>[{:term=>{:phone_number=>{:term=>\"555-555-1212\"}}}]}}, @boolean=#<Tire::Search::BooleanQuery:0x007fe12432b178 @options={}, @value={:must=>[{:term=>{:phone_number=>{:term=>\"555-555-1212\"}}}]}>>>"
mapping do
indexes :member_id, type: 'integer'
indexes :first_nm, boost: 20
indexes :last_nm, boost: 20
indexes :middle_nm, boost: 5
indexes :dob, type: 'date'
REMOVE_WORDS_ARRAY = ["llc", "co", "corp", "inc"]
businesses_array = [["the bakery", "10012"],["law office inc", "10014"]]
businesses_hashes = []
businesses_array.each do |business|
our_hash = {}
our_hash['BusinessName'] = business[0].strip unless business[0].nil?
our_hash['BusinessZipCode'] = business[1].strip unless business[1].nil?
@rbeene
rbeene / es.sh
Created September 28, 2012 19:09 — forked from rajraj/es.sh
Install ElasticSearch on CentOS 6
cd ~
sudo yum update
sudo yum install java-1.7.0-openjdk.i686 -y
wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.9.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share
class ActiveRecord::Base
def self.inherited(klass)
callbacks = [:before_validation, :before_save, :before_create, :before_update]
callbacks.each do |callback|
klass.send(callback) do
return unless respond_to?(:updated_by) || updated_by.nil?
self.updated_by = Thread.current[:current_user]
end
end
new Highcharts.Chart({
chart: {
renderTo: "market_share_scatter_by_companies"
},
title: {
text: "Market Share Analysis"
},
xAxis: {
type: "integer"
},
if root.Meteor.is_client
window.Messages = Messages
window.Rooms = Rooms
window.Participants = Participants
window.Users = Users
$(window).bind 'unload', () ->
alert("i'm out!")
#controller
def new
@ad = Ads::Ad.new
@ad.build_our_location
3.times {@ad.channel_groups.build}
end
#form section
<% form.fields_for :channel_groups do |f| %>
<%= f.select :channel_group_id, ChannelGroup.main_channel_groups.collect {|c| [c.name, c.id]}, {:include_blank => true }, :label => "Genre"%>