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 'benchmark' | |
Benchmark.bm do |x| | |
scores = %w{00100300800 32004300X 00(11)34000 0000(15)000X 0000(15)000(13) 10(18)47(11)8(10)3} | |
x.report do | |
1_000.times do | |
games = [] |
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 'benchmark' | |
def extract1(sentences, n) | |
sentences.map(&:reverse).each_with_index | |
.sort_by(&:first).reverse | |
.take(n) | |
.sort_by(&:last) | |
.map { |(_,s),_| s } | |
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
<!-- CONTACT.HTML --> | |
<form method='post' action='mailform.php'> | |
Email: <input name='email' type='text' /><br /> | |
Subject: <input name='subject' type='text' /><br /> | |
Message:<br /> | |
<textarea name='message' rows='15' cols='40'> | |
</textarea><br /> | |
<input type='submit' /> | |
</form> |
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
/* | |
* | |
* Space-filling with circles | |
* | |
* Authors: Kris Van Bael. | |
* Small modifications by Louis Mullie. | |
* | |
* | |
* Usage: | |
* |
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
domain = "www.test.com" | |
email = "[email protected]" | |
password = "test" | |
require 'whois' | |
require 'gmail' | |
client = Whois::Client.new | |
while true |
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 'sinatra' | |
require 'fileutils' | |
require 'cgi' | |
require 'drb' | |
TmpDir = './tmp/' | |
ServiceFile = 'services.txt' | |
def local_get(url) | |
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 hash_to_struct(hash) | |
return hash if hash.keys. | |
select { |k| !k.is_a?(Symbol) }.size > 0 | |
struct = Struct.new( | |
*hash.keys).new(*hash.values) | |
hash.each do |key, value| | |
if value.is_a?(Hash) | |
struct[key] = | |
self.hash_to_struct(value) | |
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
o = 0 # Number of files | |
n = 0 # Number of lines of code | |
m = 0 # Number of lines of comments | |
files = Dir.glob('/path/to/dir/**/*.rb') | |
files.each do |f| | |
next if FileTest.directory?(f) | |
o += 1 | |
i = 0 | |
lines = [] |
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
import random as r | |
import math as m | |
# Number of darts that land inside. | |
inside = 0 | |
# Total number of darts to throw. | |
total = 1000 | |
# Iterate for the number of darts. | |
for i in range(0, total): |
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 'thread' | |
$done = {} | |
$size = 2 | |
$mutex = Mutex.new | |
$resource = ConditionVariable.new | |
def register(thread) | |
id = thread.object_id | |
$mutex.synchronize do |