This file contains hidden or 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
# INCLUDES <- "web/graphics" | |
# FILETYPE <- "html" | |
# Upper case first letter of string | |
# This comes from the examples of some R function. | |
# | |
# @keyword internal | |
firstUpper <- function(s) { | |
paste(toupper(substring(s, 1,1)), substring(s, 2), sep="") | |
} |
This file contains hidden or 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 quicksort(array, from=0, to=nil) | |
# Sort the whole array, by default | |
to = array.count - 1 if to == nil | |
# Done sorting | |
return if from >= to | |
# Take a pivot value, at the far left | |
pivot = array[from] |
This file contains hidden or 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 'net/http' | |
require 'uri' | |
################################################### | |
# EDIT YOUR REQUEST HERE # | |
################################################### | |
# for phrases wirte like that: word = "my+phrase" | |
word = "New+Year" | |
month = 1 |
This file contains hidden or 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
Hi, everyone! | |
During the last month I've been working hard to roll out HighlandDB, lightweight | |
NoSQL database for Ruby applications. It gets installed in the application | |
folder and provides user with a clear API. | |
Here are the links: | |
- http://mac-r.github.com/highland/ (official website) | |
- https://github.com/mac-r/highland (Github repo) |
This file contains hidden or 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
n = 220 | |
k = 1 | |
Benchmark.bm do |x| | |
n.times do | |
x.report("Heaps_#{k*1000}x#{k*100}:") { heap_extractor(k*1000, k*100) } | |
x.report("Sort_#{k*1000}x#{k*100}:") { sorted_array_shifter(k*1000, k*100) } | |
k += 1 | |
end | |
end |
This file contains hidden or 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
module HeapModule | |
def self.sort(keys) | |
sort!(keys.clone) | |
end | |
def self.sort!(keys) | |
build_max_heap(keys) | |
(keys.size-1).downto(1) do |i| | |
keys[0], keys[i] = keys[i], keys[0] | |
max_heapify(keys, i, 0) |
This file contains hidden or 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 heap_extractor(length, n) | |
random_array = (1..length).to_a.inject(Array.new) {|arr, el| el = rand(1..el); arr << el;} | |
array = HeapModule.build_max_heap(random_array) | |
n.times do | |
HeapModule.extract_maximum(array) | |
end | |
end |
This file contains hidden or 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 sorted_array_shifter(length, n) | |
random_array = (1..length).to_a.inject(Array.new) do |arr, el| | |
el = rand(1..el); arr << el; | |
end | |
array = random_array.sort {|x,y| y<=>x } | |
n.times do | |
array.shift | |
end | |
end |
This file contains hidden or 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
test |
This file contains hidden or 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
restart; | |
with(Statistics): | |
STDNORM:=proc( ) local ij,U1,U2,S,B,X1;global i,X2; | |
if type(i,boolean)then | |
if (i) then | |
i:=not(i);X2; | |
else | |
for ij from 1 to infinity do | |
U1:=evalf(2.0*rand()/10^12)-1.0; | |
U2:=evalf(2.0*rand()/10^12)-1.0; |
NewerOlder