Skip to content

Instantly share code, notes, and snippets.

@AJFaraday
AJFaraday / Twitter setup
Created March 28, 2011 10:20
Twitter setup
# with twitter gem
# In my /app/models/event.rb
require 'twitter'
def tweet_about
@message = "\##{project.short_name} http://ideas-factory.co.uk/e/#{id} #{name} #{time.strftime("%a %d %b-%I:%M%P")}-#{desc}"
twit_init
@AJFaraday
AJFaraday / Bieber wedding proposals
Created March 28, 2011 10:23
Bieber wedding proposals
require 'rubygems'
require 'twitter'
search = Twitter::Search.new
i = 0
search.containing("marry me").to("justinbieber").each do |r|
puts "#{r.from_user}: #{r.text}"
i += 1
end
puts i
@AJFaraday
AJFaraday / :( ?!?
Created April 18, 2011 14:48
Unknown errir
This error
wrong number of arguments (1 for 0)
Rails.root: /home/andrew/Documents/GRUB
Application Trace | Framework Trace | Full Trace
app/models/subscription.rb:23:in `extend_deliveries'
app/models/subscription.rb:15:in `times'
app/models/subscription.rb:15:in `extend_deliveries'
@AJFaraday
AJFaraday / Troublesome validation
Created April 26, 2011 15:30
troublesome validation
class Pledge < ActiveRecord::Base
validates_presence_of :amount
def validate_positivity_of(*attr_names)
configuration = { :message => "Cannot be negative" }
configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash)
validates_each attr_names do |m, a, v| m.errors.add(a, configuration[:message]) if v<=0 end
end
@AJFaraday
AJFaraday / gist:964212
Created May 10, 2011 10:04
distraction
task :hello_and_beep do
puts 'Hello'
16.times do |i|
if i % 4 == 0
sh "beep -f #{rand(4000) + 4000}"
sleep 0.04
else
sh "beep -f #{rand(4000)}"
sleep 0.04
end
@AJFaraday
AJFaraday / gist:964529
Created May 10, 2011 14:06
beeps of evil
i = 0
loop do
i += 1
system "beep -f #{rand(i * 100) + 100}"
sleep rand((i+1)/100)
end
@AJFaraday
AJFaraday / gist:978354
Created May 18, 2011 10:49
baffling error
Showing /home/andrew/Documents/FestivePage/app/views/mailouts/_form.html.haml where line #3 raised:
wrong number of arguments (1 for 0)
Extracted source (around line #3):
1: .group
2: = f.label :subject, t("activerecord.attributes.mailout.subject", :default => "Subject"), :class => :label
3: = f.text_field :subject, :class => 'text_field'
4: %span.description Ex: a simple text
# in config/routes.rb
FestivePage::Application.routes.draw do
resources :vouchers
resources :mailouts do
member do
get 'distribute'
end
@AJFaraday
AJFaraday / gist:1080516
Created July 13, 2011 15:25
Jquery, first attempt issues
var title = ['M','A','R','M','I','T','E','J','U','N','C','T','I','O','N']
var index = 0
$(document).ready(function(){
$("body").click(function(){
$("div.jq_test2").html(title[(index%title.length)]);
$("div.jq_test2").fadeIn(1);
$("div.jq_test2").fadeOut(1000);
index=++index
});
@AJFaraday
AJFaraday / gist:1121153
Created August 2, 2011 20:33
jquery hiding/showing feild
# my jquery specifics (jq_actions.js)
var $j = jQuery.noConflict();
var $extra_kinds = 'of <input id="indicator_number_name" name="indicator[number_name]" size="15" type="text" />'
$j(document).ready(function(){
$j("#kinds").change(function(){
var $value = $j('#indicator_kind').val();
if ($value == "number")