Ruby - Post form data
uri = URI.parse(url) req = Net::HTTP::Post.new(url) req.set_form_data({ \'field\' => \'value\' }) res = Net::HTTP.new(uri.host, uri.port).start { |http| http.request(req ...
View ArticleRuby - peset
def mayorDeEdad(anios) if anios >= 18 puts"¡eres un viejo fosil!" else puts"¡eres un estupido enano!" end end puts"¿cuantos añ ...
View ArticleRuby - Ruby: Search Spotify API
=begin http://developer.spotify.com/en/metadata-api/overview/ Requests: http://ws.spotify.com/service/version/method[.format]?parameters http://ws.spotify.com/search/1/track.json?q=kaizers+ ...
View ArticleRuby - Use helpers in controllers or models
# create a new file inside lib/ and call it helpers.rb # paste the following: def help Helper.instance end class Helper include Singleton # look inside ActionView::Helpers to include ...
View ArticleRuby - Parse an XML document with REXML and print some of the text nodes
require "rexml/document" file = File.new( "MY_FILE.xml" ) doc = REXML::Document.new file doc.elements.each("document/record/upload_list"){ |element| puts element.text if element.text ...
View ArticleRuby - preguntas
puntos = 0 puts "¿que es lo que quiero ser de mayor?" respuesta = gets.chomp respuesta_correcta = "astrofisica" if respuesta == respuesta_correcta puts"has acertado!!!" puntos +=1 ...
View ArticleRuby - Get from Pastie - Textmate Command
#!/usr/bin/env ruby ##Licence # ger_from_pastie.rb - A TextMate command for getting file from http://pastie.caboo.se #Copyright (C) 2006 Alessio Caiazza - abisso.org # #This program is free ...
View ArticleRuby - Play a file using ruby
require 'rubygems' class Player @@sound_path = '' @@sound_app = 'mpg321' @@process_devnull = '> /dev/null 2>&1' @@process_bg = '&' def self.sound_path=(value) @@sound_path ...
View ArticleRuby - Varidate email address
validates_format_of(:email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :on => :create, :message=>"has an invalid format") # AND A LOGIN VALIDATION EXAMPLE MIGHT BE...
View ArticleRuby - Ruby: Parse Delicious RSS Feeds
require 'rss' require 'open-uri' open('http://del.icio.us/rss/chrisaiv') do |http| response = http.read result = RSS::Parser.parse(response, false) items = result.items items.each do |item ...
View ArticleRuby - bibout
#!/usr/bin/ruby # bibout 0.1 by David Sanson # # This is a ruby script that tries to parse bibtex files # and spit out either citekeys or markdown formatted # references. Try bibout -h for ...
View ArticleRuby - Add class methods for ruby classes
# Extend class methods for any ruby class class NameofClass class ...
View ArticleRuby - Panopticon
#!/usr/bin/env ruby require "rubygems" require "appscript" include Appscript require "active_support" require 'rss/1.0' require 'rss/2.0' require 'open-uri' @mail = app("Mail") @things = app("Things ...
View ArticleRuby - auto_drop_migration.rb
module AutoDropMigration module Migration # Drop all tables and indexes created by the migration # class AddUser < ActiveRecord::Migration # def self.up ...
View ArticleRuby - factory girl example
#### spec_factory.rb require 'factory_girl' Factory.sequence :login do |n| "bob#{n}" end Factory.sequence :email do |n| "person#{n}@example.com" end Factory.sequence :subdomain ...
View ArticleRuby - install mysql gem on mac os 10.5 with MANP
sudo gem install mysql -- --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config ...
View ArticleRuby - Regenerate paperclip thumbnails
# Given Asset has_attached_file Asset.find(:all).each { |a| a.asset.reprocess!; a.save ...
View ArticleRuby - How to iterate through an array in Ruby
#A. Create an array names = %w[chris sandy josie billy suzie] #B. Find the length of the array and iterate through it names.length.times do |i| puts i.to_s + " " + names[i] end ...
View ArticleRuby - ruby array chop
# for creating sets of data for tables generally. it enables you to # take an array and create sections with it. # # a = [1,2,3,4,5,6,7,8,9,10] # b = array_chop(a,3) # b.inspect # "[[1, 2, 3], [ ...
View Article