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
CHARS64 = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a + ["-", "_"] | |
# Return a 22 byte URL-safe string, encoded six bits at a time using 64 characters | |
def to_s22 | |
integer = self.to_i # UUID as a raw integer | |
rval = "" | |
22.times do | |
c = (integer & 0x3F) | |
rval += CHARS64[c] | |
integer = integer >> 6 | |
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
#Time limit exceeded | |
class Palindrome | |
def compute(value) | |
@input_array = value | |
@size = @input_array.size | |
@even = @size % 2 == 0 | |
if @even | |
@pos1 = (@size/2)-1 | |
@pos2 = @pos1+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
#Time limit exceeded | |
class Palindrome | |
def compute(value) | |
@input_array = value | |
@size = @input_array.size | |
@even = @size % 2 == 0 | |
if @even | |
@pos1 = (@size/2)-1 | |
@pos2 = @pos1+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
class Array | |
def <=(value) | |
@self_size = self.size | |
@value_size= value.size | |
return false if @self_size > @value_size | |
tmp = true | |
for iterator in @self_size-1..0 | |
tmp = false if self[iterator] > value[iterator] | |
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
#SIGABRT | |
class Palindrome | |
def compute(value) | |
@size = value.size | |
@even = @size % 2 == 0 | |
if @even | |
@pos1 = (@size/2)-1 | |
@pos2 = @pos1+1 | |
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 String | |
def compute | |
@size = self.size | |
@even = @size % 2 == 0 | |
if @even | |
@pos1 = (@size/2)-1 | |
@pos2 = @pos1+1 | |
else | |
@pos1 = (((@size+1)/2)-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
class String | |
def compute | |
@size = self.size | |
@even = @size % 2 == 0 | |
if @even | |
@pos1 = (@size/2)-1 | |
@pos2 = @pos1+1 | |
else | |
@pos1 = (((@size+1)/2)-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
desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.' | |
task :routes => :environment do | |
all_routes = ENV['CONTROLLER'] ? ActionController::Routing::Routes.routes.select { |route| route.defaults[:controller] == ENV['CONTROLLER'] } : ActionController::Routing::Routes.routes | |
routes = all_routes.collect do |route| | |
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s | |
verb = route.conditions[:method].to_s.upcase | |
segs = route.segments.inject("") { |str,s| str << s.to_s } | |
segs.chop! if segs.length > 1 | |
reqs = route.requirements.empty? ? "" : route.requirements.inspect | |
{:name => name, :verb => verb, :segs => segs, :reqs => reqs} |
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
desc 'Print out all unused routes' | |
task :unused => :environment do | |
all_routes = ActionController::Routing::Routes.routes | |
routes = all_routes.collect do |route| | |
name = ActionController::Routing::Routes.named_routes.routes.index(route).to_s | |
verb = route.conditions[:method].to_s.upcase | |
segs = route.segments.inject("") { |str,s| str << s.to_s } | |
segs.chop! if segs.length > 1 | |
reqs = route.requirements.empty? ? "" : route.requirements.inspect | |
{:name => name, :verb => verb, :segs => segs, :reqs => reqs} |
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 Array | |
def <=(value) | |
size_self = self.size | |
size_value = value.size | |
return false if self.size > value.size | |
return true if self.size < value.size | |
value.each_with_index do |value, i| | |
return false if value < self[i] | |
end | |
return true |
OlderNewer