This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'prime' | |
def divisors_count(n) | |
Prime.prime_division(n).reduce(1) do |mem, prime_factor| | |
mem * (prime_factor[1] + 1) | |
end | |
end | |
def triangle_number(n) | |
(n)*(n+1)/2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Influent.find(349).outcomes(1) | |
=> "{ \"outcome\" : { \"rank\" : 1, \"satisfaction\" : 1, \"options\" : [ { \"id\" : \"214\" }, { \"id\" : \"216\" }, { \"id\" : \"223\" }, { \"id\" : \"225\" }, { \"id\" : \"226\" }, { \"id\" : \"227\" } ] } }" | |
Influent.find(349).outcomes(1) | |
=> "{ \"outcome\" : { \"rank\" : 1, \"satisfaction\" : 1, \"options\" : [ { \"id\" : \"223\" } ] } }" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def stub_sign_in(user) | |
request.env['warden'].stub :authenticate! => user | |
controller.stub(:current_user){ user } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select positions from teacher_profiles limit 1; | |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |
| positions | | |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Random | |
include Enumerable | |
def initialize(limit) | |
@limit = limit | |
end | |
def each(counter = 10) | |
i = 0 | |
while i < counter | |
yield rand(@limit) | |
i += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Feedback from "El gran pregunton" !!!! | |
c = 0 | |
d = 0 | |
5001.times do | |
c += 1 | |
d = d + c | |
end |
NewerOlder