Skip to content

Instantly share code, notes, and snippets.

def get_triangle_number(divisors)
puts Time.now
number = 1
found = false
until found
first_number_primes = get_primes(number)
second_number_primes = get_primes(number + 1)
primes = first_number_primes | second_number_primes
triangle_number = ( number * (number + 1) ) / 2
prime_times = times_each_prime(triangle_number, primes)
http://rubytu.be/
http://teachmetocode.com/screencasts/page/3/
#Feedback from "El gran pregunton" !!!!
c = 0
d = 0
5001.times do
c += 1
d = d + c
end
@daniel-g
daniel-g / common.thor
Created December 6, 2010 18:14
Common tasks in my linux
class Common < Thor
desc "passgen [LENGTH]", "generates passwords with a given length (defaults to 8)"
method_options :numeric => :boolean, :downcase => :boolean, :upcase => :boolean, :alphanumeric => :boolean
def passgen(len = 8)
chars = []
if (options.empty?)
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
else
if options[:alphanumeric]
chars += ("a".."z").to_a + ("A".."Z").to_a
@daniel-g
daniel-g / blocks.rb
Created January 27, 2011 09:35
Blocks
def fibonacci_up_to(number)
i1, i2 = 1, 1
while i1 <= number
yield i1
i1, i2 = i2, i1+i2
end
end
fibonacci_up_to(40){|fib| puts fib}
@daniel-g
daniel-g / random_enumerable.rb
Created January 27, 2011 17:31
Random Enumerable
class Random
include Enumerable
def initialize(limit)
@limit = limit
end
def each(counter = 10)
i = 0
while i < counter
yield rand(@limit)
i += 1
@daniel-g
daniel-g / solr-dev
Created September 20, 2011 06:18
Commands to run solr in my local env
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: $ solr path/to/config/dir path/to/data/dir port"
else
if [ -z "$2" ]; then
echo "Usage: $ solr path/to/config/dir path/to/data/dir port"
else
if [ -z "$3" ]; then
echo "Usage: $ solr path/to/config/dir path/to/data/dir port"
else
@daniel-g
daniel-g / tweet_stream_sample.rb
Created May 28, 2012 22:18
TweetStream example
TweetStream::Client.new.track('google') do |status|
# The status object is a special Hash with
# method access to its keys.
File.open('tweets.txt', 'a') do |f|
f.puts "#{status.text[0, 30]}"
end
end
@daniel-g
daniel-g / db_serialized_obj.sql
Created June 13, 2012 00:26
Example of DB serialized object in Rails
select positions from teacher_profiles limit 1;
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| positions |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@daniel-g
daniel-g / devise_spec_helpers.rb
Created August 17, 2012 16:57
Stub sign in for warden
def stub_sign_in(user)
request.env['warden'].stub :authenticate! => user
controller.stub(:current_user){ user }
end