Skip to content

Instantly share code, notes, and snippets.

View universal's full-sized avatar

Johannes / universa1 universal

View GitHub Profile
@universal
universal / error.rb
Last active August 29, 2015 14:19 — forked from valleybay/error.rb
Failures:
1) UserSessionsController#create with correct credentials with device_id and device_type set someone else is logged in with the same devic
e_id adds AddDeviceToken to the queue
Failure/Error: expect{
expected result to have changed by 1, but was changed by 0
# ./spec/controllers/user_sessions_controller_spec.rb:91:in `block (6 levels) in <top (required)>'
Finished in 1.45 seconds (files took 2.33 seconds to load)
13 examples, 1 failure
Schemas
An update_call of the item_classification
Processing ItemClassificationsController#update (for 127.0.0.1 at 2015-03-23 11:15:54) [PUT]
@universal
universal / sample.rb
Last active August 29, 2015 14:16 — forked from selvait90/sample.rb
params = {:id=>"5", :jurisdiction=>{:place_attributes=>{:name=>"Allen County15", :short_name=>"Allen County15", :id=>"5"}}}
@jurisdiction = PlaceEntity.jurisdictions.excluding_unassigned.find(params[:id])
@jurisdiction.place
@jurisdiction.update_attributes(params[:jurisdiction])
@jurisdiction.place.valid?
class AddIndexToLineItems < ActiveRecord::Migration
def change
add_index :line_items, [:user_id, :product_id], unique: true
end
end
@universal
universal / bm.rb
Created February 6, 2015 11:57 — forked from workmad3/bm.rb
require 'benchmark'
hsh = {}
1000.times {|i| hsh[i.to_s] = i.succ.to_s}
Benchmark.bm do |x|
x.report("Hash[]") {1000.times{Hash[hsh.values.zip(hsh.keys)]}}
x.report("invert") {1000.times{hsh.invert}}
x.report("each_with_object") {1000.times{hsh.each_with_object({}){|(k,v),h| h[v] = k}}}
end
<% content_for :title do %>
<%= @game.SportsLeagueName %>: <%= team_logo @game.away_team %> <%= @game.away_team %> at <%= @game.home_team %>"
<% end %>
<%= team_logo @game.away_team %>
<div>
<% if @game.SportsLeagueName == 'NFL' %>
<%= image_tag "http://151986650d2f98828025-63e4acfff05fd55acad2fbee57a1d69b.r75.cf2.rackcdn.com/#{@game.AwayTeamID}.png" %>
AT
<%= image_tag "http://151986650d2f98828025-63e4acfff05fd55acad2fbee57a1d69b.r75.cf2.rackcdn.com/#{@game.HomeTeamID}.png" %>
module ApplicationHelper
def title(*parts)
unless parts.empty?
parts << t(:website)
content_for(:title) do
parts.join(' - ')
end
end
end
end
class FollowUpVisitGardensController < ApplicationController
def new
#1st you retrieve the group thanks to params[:group_id]
#2nd you build a new comment
@group = Group.find(params[:group_id])
@gardener= Gardener.find(params[:gardener_id])
@follow_up_visit_garden= FollowUpVisitGarden.new
if @gardener.valid?
render "new"
def add_emojify_and_kramdown(text)
markdowned = Kramdown::Document.new(text).to_html
raw(emojify(markdowned))
end
def emojify(text)
text.to_str.gsub(/:([a-z0-9\+\-_]+):/) do |match|
if emoji = Emoji.find_by_alias($1)
%Q{<img alt="$1" class="emoji" src="#{ image_path(emoji.image_filename) }">}
@universal
universal / example.rb
Last active August 29, 2015 14:04 — forked from anonymous/example.rb
task :postcode_import => :environment do
puts "\n\n Importing PostCodes"
lat_long_res = []
CSV.foreach "lib/data/example.csv" do |row|
if row[0].include? " "
postcode = row[0]
else
postcode = row[0][0..3] + " " + row[4..-1]
end
easting = row[1].to_i