Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@prodoxx
prodoxx / short_string_packer.rb
Created March 8, 2018 12:59
Packs a short string into a Fixnum and vise-versa
class ShortStringPacker
## Packs a short string into a Fixnum
# Arguments:
# str - String object
# Returns: a Fixnum object
def self.pack(str)
abc = [*'a'..'z']
arr = str.chars.map { |x| abc.find_index(x) + 1 }
arr.reduce { |item, key| (item << 5.0) | key }
end
@prodoxx
prodoxx / fizzbuzz.rb
Created September 24, 2017 08:01
Fizz buzz is a simple children’s game where everyone sits in a circle, and each person takes a turn saying numbers in increasing order. More here: http://en.wikipedia.org/wiki/Fizz_buzz
## write your fizzbuzz method in this file
# see http://en.wikipedia.org/wiki/Fizz_buzz for details on FizzBuzz game
def get_fb(number)
return 'FizzBuzz' if (number % 5).zero? && (number % 3).zero?
return 'Fizz' if (number % 3).zero?
return 'Buzz' if (number % 5).zero?
number
end
@prodoxx
prodoxx / yml_to_tsv.rb
Last active September 24, 2017 07:47
A script that converts a YAML skills file into a TSV file. Take two parameters from command line: the name of input and output file(optional). Prints the output in the command-line if output filename is not provided.
require 'yaml'
data_filename = ARGV[0]
output_filename = ARGV[1]
def yml_to_tsv(data)
headers = data[0].keys
header_line = ''
new_data = []
@prodoxx
prodoxx / tsv_to_yml.rb
Last active September 24, 2017 07:47
A script that converts a TSV file into a YAML file. Take two parameters from command line: the name of input and output file(optional). Prints the output in the command-line if output filename is not provided.
require 'yaml'
data_filename = ARGV[0]
output_filename = ARGV[1]
new_data = []
header = ''
def create_record(headers, line)
values = line.split("\t").map!(&:chomp)
headers = headers.split("\t").map!(&:chomp)