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 get_perm str | |
return [str] if str.size == 1 | |
perms = [] | |
first_char = str.slice!(0) | |
words = get_perm(str) | |
words.each do |word| | |
perms += insert_each(first_char, word) | |
end | |
perms |
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 mergesort(ary) | |
return ary if ary.count <= 1 | |
size = ary.count | |
m = size / 2 | |
merge mergesort(ary[0..m-1]), mergesort(ary[m..size-1]) | |
end | |
def merge(a, b) | |
return a if b.count <= 0 | |
return b if a.count <= 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 quicksort(ary) | |
size = ary.count | |
return ary if size <= 1 | |
i, j = 0, size - 1 | |
pivot = ary[(size / 2)] | |
while i < j | |
i += 1 while ary[i] < pivot | |
j -= 1 while ary[j] > pivot | |
ary[i], ary[j] = ary[j], ary[i] |
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
Server: | |
iMac | |
Mac10,1 | |
Intel Core 2 Duo | |
3,06 GHz | |
Cache L2: 3 MB | |
RAM: 8 GB | |
bus: 1,07 GHz |
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 show | |
@pet = Pet.find(params[:id]) | |
tempfile = Tempfile.new(@pet.id.to_s) | |
render_file = Tempfile.new(@pet.id.to_s + '.html') | |
buffer = render 'show.pdf.erb', layout: false | |
render_file.write(buffer.first) | |
html = "#{render_file.path}.html" | |
system "mv #{render_file.path} #{html} && wkhtmltopdf #{html} #{tempfile.path}" | |
send_file tempfile.path, type: 'application/pdf' |