Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View theinventor's full-sized avatar

Troy Anderson theinventor

View GitHub Profile
def unsubscribe
token = Base64.decode64(params[:token]) #using base64 encoding in the url to prevent unsubscribe abuse
@user = User.find_by_access_token(token) #find the user from the ID in url
@user.opt_out = true #change them to not get email
@user.save #save the changes
redirect_to "/", :notice => "We won't bug you with emails!" #give them a little notice that it worked
end
@theinventor
theinventor / en-GB.yaml
Created July 24, 2012 04:13
Yaml-Example
en-GB:
date:
abbr_day_names:
- Sun
- Mon
- Tue
- Wed
- Thu
- Fri
- Sat
2012-07-28T17:05:43+00:00 app[web.1]: [2012-07-28 10:05:43] INFO WEBrick 1.3.1
2012-07-28T17:05:43+00:00 app[web.1]: [2012-07-28 10:05:43] INFO ruby 1.9.2 (2011-07-09) [x86_64-linux]
2012-07-28T17:05:43+00:00 app[web.1]: [2012-07-28 10:05:43] INFO WEBrick::HTTPServer#start: pid=2 port=49545
2012-07-28T17:05:44+00:00 heroku[web.1]: State changed from starting to up
2012-07-28T17:05:46+00:00 app[web.1]: => Booting WEBrick
2012-07-28T17:05:46+00:00 app[web.1]: => Rails 3.2.6 application starting in production on http://0.0.0.0:49545
2012-07-28T17:05:46+00:00 app[web.1]: => Call with -d to detach
2012-07-28T17:05:46+00:00 app[web.1]: => Ctrl-C to shutdown server
2012-07-28T17:05:46+00:00 app[web.1]:
2012-07-28T17:05:46+00:00 app[web.1]:
Troys-MacBook-Pro:BackOffice troy$ b rake assets:precompile --trace
/Users/troy/.rvm/gems/ruby-1.9.3-p0@threetwo/gems/prawn-core-0.8.4/lib/prawn/core.rb:34: warning: already initialized constant VERSION
/Users/troy/.rvm/gems/ruby-1.9.3-p0@threetwo/gems/cloudprint-0.1.2/lib/cloudprint/connection.rb:5: warning: already initialized constant VERIFY_PEER
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/Users/troy/.rvm/rubies/ruby-1.9.3-p0/bin/ruby /Users/troy/.rvm/gems/ruby-1.9.3-p0@threetwo/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
/Users/troy/.rvm/gems/ruby-1.9.3-p0@threetwo/gems/prawn-core-0.8.4/lib/prawn/core.rb:34: warning: already initialized constant VERSION
/Users/troy/.rvm/gems/ruby-1.9.3-p0@threetwo/gems/cloudprint-0.1.2/lib/cloudprint/connection.rb:5: warning: already initialized constant VERIFY_PEER
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
@theinventor
theinventor / rake_task_template.rake
Created October 1, 2012 23:03
Rake Task Template
namespace :some_thingy do
task :my_big_fixer, [:production_run] => :environment do |t, args|
production_run = args[:production_run] == "true"
ap "doing a dry run" unless production_run
my_logger = Logger.new("#{Rails.root}/log/my_thingy.log")
require 'progress_bar'
bar = ProgressBar.new(User.all.count) # pass the total for the progress bar
my_logger.info "Starting at #{Time.now}"
@theinventor
theinventor / processing.rb
Created October 25, 2012 18:32
asset precompile timing per file
require 'sprockets/engines'
require 'sprockets/mime'
require 'sprockets/processor'
require 'sprockets/utils'
module Sprockets
# `Processing` is an internal mixin whose public methods are exposed on
# the `Environment` and `Index` classes.
module Processing
include Engines, Mime
if ad_records.count == 1
ad_record = ad_records.first
ad = Ad.new(
:tagline => ad_record['tag_line'],
:service => service,
:image_url => ad_record['image_external_url'],
:citygrid_ad_id => ad_record['ad_id']
)
ad.image = Image.new(:name => ad_record['image_external_url'], :role => "AD_IMAGE", :url => ad_record['image_external_url'], :format => ad_record['image_external_url'].to_s.split('.').last )
@theinventor
theinventor / simple_form_stuff.rb
Created November 28, 2012 19:18
simple_form_stuff
####TO CREATE A BOOLEAN VIRTUAL ATTRIBUTE WITH VALIDATION:
##In the model:
class Person < ActiveRecord::Base
validates_acceptance_of :terms_of_service
#if using attr_accessible
attr_accessible :name, :etc, :terms_of_service
end
@theinventor
theinventor / photos_uploaded_per_day.json.jsonify.rb
Last active December 18, 2015 19:29
Example jsonify builder view for making a nice blob to drive a highcarts widget on geckoboard :)
#we populated some @markets sort of like this;
# @results << OpenStruct.new(name: group[1].first.city.title, color: colors[index], data: [], city_id: group[0])
# later.... each result.data << photos_that_day.to_i
json.chart do
json.type 'column'
json.backgroundColor 'rgba(255, 255, 255, 0.1)'
json.style do
json.fontFamily 'monospace'
json.color "#000"
en-NG:
date:
abbr_day_names:
- Sun
- Mon
- Tue
- Wed
- Thu
- Fri
- Sat