Quantcast
Channel: EmotiCODE - Snippets and Source Code Search Engine
Browsing all 146 articles
Browse latest View live

Ruby - http sniffing Ruby

#!/usr/local/bin/ruby require 'pcaplet' httpdump = Pcaplet.new('-s 1500 -i eth0') HTTP_REQUEST = Pcap::Filter.new('tcp and dst port 80', httpdump.capture) HTTP_RESPONSE = Pcap::Filter.new('tcp ...

View Article


Ruby - usuario, clave y calculadora

usuario_correcto= "clober" clave_correcta= "clobero" puts "Introduce tu nombre de usuario" usuario = gets.chomp while (usuario != usuario_correcto) do puts "El usuario no es correcto ...

View Article


Ruby - Object#tap

# encoding: utf-8 'one two three' .split .tap { |x| p x } .collect(&:upcase) .tap { |x| p x } .join(' ') .tap { |x| p x } #=> ["one", "two", "three"] # ["ONE", " ...

View Article

Ruby - Ruby: File Path Basics

#Platform independant way of showing a File path. Empty String ('') means the root puts File.join('', 'Users', 'chrisaiv', 'Desktop') #Provide the RELATIVE path of THIS file puts __FILE__ # ...

View Article

Ruby - tribial

preguntas = ["¿Quien levanto la copa del mundo en 2010?", "¿Qien fue el primer pais que hizo mapas de todo el mundo?", "¿Cuando nacio Michael Jackson ...

View Article


Ruby - Howto set up a Rake task to run Cucumber features and generate reports

require 'cucumber' require 'cucumber/rake/task' desc 'Run Cucumber features and generate an HTML summary, JUnit XML and a plain text log' Cucumber::Rake::Task.new(:features) do |t| t. ...

View Article

Ruby - stupid hash update experiments in ruby

h1 = {'1'=>'a', '2'=>'b', '3'=>'c', '4'=>'z'} h2 = {'4'=>'e'} puts h1.inspect # => {"1"=>"a", "2"=>"b", "3"=>"c", "4"=>"z"} h1.update(h2) puts h1.inspect # =>...

View Article

Ruby - Filter base64 encoded Textmate snippet back into text

ruby -e "require 'base64'; print Base64.decode64( STDIN.read ...

View Article


Ruby - Format strings like PRINT USING

require 'strscan' class String # Returns the string formatted according to a pattern. # # The pattern consists of placeholders and literals. The string is placed in # the placeholders ...

View Article


Ruby - Rollup Count of Events

if ARGV[0] == nil then puts "SYNTAX: smtp_errors.rb " exit end log = ARGV[0] offenders = Hash.new(0) File.open(log,"r").each do |line| if line =~ /SMTP error/ then addy = line ...

View Article

Ruby - uTorrent WebUI API Ruby Class

#!/usr/bin/env ruby # uTorrent WebUI API Class for Ruby # Copyright (C) 2012 Keiran "Affix" Smith # http://affix.me # # This program is free software: you can redistribute it and/or ...

View Article

Ruby - facebook chat

require 'mechanize' require 'json' require 'ostruct' require 'pp' class FacebookChat def initialize(email, pass); @email, @pass = email, pass; end def login @agent = WWW::Mechanize. ...

View Article

Ruby - Juego aleatorio

puts "Bienvenido al juego del numero que nunca adivinaras wajajajaja" puts "Es un numero entre 1 y 20 que nunca adivinaras!! Te dare 5 oportunidades" puts "Escribe un numero!" numero_secreto = rand ...

View Article


Ruby - Simple Authentication Checker

def check_authentication unless session[:admin] session[:intended_action] = action_name session[:intended_controller] = controller_name redirect_to :action => "signin" end ...

View Article

Ruby - Regular Expression to Parse Ruby Log Messages

# parse ruby log message # customize as needed LOG_EXPRESSION = /([\w]+),\s+\[([^\]\s]+)\s+#([^\]]+)]\s+(\w+)\s+--\s+(\w+)?:\s+(.+)/ # sample log output from this call: # logger.info("Ubiquitously ...

View Article


Ruby - Create a Todo in Things

require "rubygems" require "appscript" include Appscript @things = app("Things") @todos = @things.to_dos def create_to_do(name,source,link) unless @todos[its.name.eq(name)].get.length > 0 ...

View Article

Ruby - Putting data on the clipboard in OS X

IO.popen('pbcopy', 'w').print "Text to go on clipboard ...

View Article


Ruby - preguntas para mejorar tu calidad de vida

puts "escribe tu nombre aquí:" nombre = gets.chomp puts "tu nombre es #{nombre}" puts "escribe si eres mayor o menor de edad aqui:" edad = gets.chomp puts "eres #{edad}" puts " ...

View Article

Ruby - Problem 5

#!/usr/bin/ruby require 'mathn' i = 2520 q = i j = Prime.new flag = 0 while(flag == 0) do for k in 1..20 if(q % k == 0) flag = 1 else j = j.next q = i*j ...

View Article

Ruby - read id3 v1 information from mp3

#!/usr/bin/env ruby #This script retrive i3V1 information from an mp3 file #it's a proof of concept so don't use it in productions #let's read the file f = File.open(ARGV.first, 'rb'); #we need ...

View Article
Browsing all 146 articles
Browse latest View live