Skip to content

Instantly share code, notes, and snippets.

View 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
View 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 Apr 18, 2011
Unknown errir
View :( ?!?
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'
View 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
View gist:964212
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
View gist:964529
i = 0
loop do
i += 1
system "beep -f #{rand(i * 100) + 100}"
sleep rand((i+1)/100)
end
View gist:978354
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
View gist:1022872
# in config/routes.rb
FestivePage::Application.routes.draw do
resources :vouchers
resources :mailouts do
member do
get 'distribute'
end
@AJFaraday
AJFaraday / gist:1080516
Created Jul 13, 2011
Jquery, first attempt issues
View gist:1080516
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 Aug 2, 2011
jquery hiding/showing feild
View gist:1121153
# 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")