I hereby claim:
- I am bil-bas on github.
- I am bilbas (https://keybase.io/bilbas) on keybase.
- I have a public key ASDBnuzkXv-AF1XWz46fwPGADqxjcqc0ktfZCFWUTMhdcQo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
# GodotLogger by Spooner | |
# ====================== | |
# | |
# logger.gd is a simple logging system. It allows for more formatted logging, | |
# logging levels and logging to a file. | |
# | |
# Installation | |
# ------------ | |
# | |
# Place this file somewhere (for example, 'res://root/logger.gd') |
module Enumerable | |
def quicksort() | |
if size <= 1 | |
self | |
else | |
pivot = shift | |
lower, greater = partition {|x| x < pivot }.map(&:quicksort) | |
lower.push(pivot).concat(greater) | |
end | |
end |
puts 'What is the name and path of the file?' | |
filename = gets.chomp | |
text = File.read(filename) | |
freqs = text.scan(/[a-zA-Z]+/).each.with_object(Hash.new(0)) { |word, freqs| freqs[word] += 1 } | |
freqs = freqs.sort_by {|x,y| -y } | |
freqs.each {|word, freq| puts "#{word} #{freq}" } |
module Collatz | |
class << self | |
attr_reader :lengths | |
def length_recursive(current, counter=0) | |
counter += 1 | |
if current == 1 | |
counter | |
elsif @lengths.key? current | |
@lengths[current] + counter # Take advantage of already working out the length from this number. |
module Enumerable | |
def map_find(default=nil) | |
return enum_for(:map_find, default) unless block_given? | |
each do |e| | |
mapped = yield e | |
return mapped if mapped | |
end | |
default |
def __getattr__(self, name): | |
# _children is a list of strings referring to properties in the wrapper object. | |
for child in self._children: | |
child = getattr(self, child) | |
if hasattr(child, name): | |
return getattr(child, name) | |
return AttributeError("No attribute '%s' in any children of %s" % (name, self)) |
def foo1 obj | |
obj.bar(1) | |
obj.bar(2) | |
end | |
def foo2 obj | |
obj.bar(2) | |
end | |
describe "foo1" do |
# Using insertion | |
class Array | |
# Insert into the array. | |
def insert_every!(skip, str) | |
(skip...size).step(skip).with_index {|n, i| insert(n + i, str) } | |
self | |
end | |
# Create a new array and insert into it. | |
def insert_every(skip, str) |