Skip to content

Instantly share code, notes, and snippets.

Avatar

Alejandro AR kinduff

View GitHub Profile
View linked_list.rb
class LinkedList
def initialize
@head = @tail = nil
end
def add(value)
node = Node.new(value)
@head = node if @head.nil?
@tail.next = node unless @tail.nil?
View hash_table.rb
class HashTable
def initialize(size)
@size = size
@buckets = Array.new(@size)
end
def add(value)
index = hash(value)
@buckets[index] = value
end
View linear_search.rb
def findIndex(values, target)
values.each_with_index do |value, i|
return i if value == target
end
end
findIndex([4, 8, 15, 16, 23, 42], 15)
# => 2
@kinduff
kinduff / win_guessing.rb
Last active Jan 13, 2016
How to Win a Guessing Game
View win_guessing.rb
# How to Win a Guessing Game - Numberphile
# Based on https://www.youtube.com/watch?v=ud_frfkt1t0
class WinGuessing
def initialize(total_iterations, max_random_num)
@total_times = total_iterations
@max_random_num = max_random_num
@max_length = @max_random_num.to_s.length
@total_result = 0
end
@kinduff
kinduff / mexican_states_and_cities.rb
Last active Mar 25, 2016
Mexican States and Cities Hash Generator - Hash Base de Datos para Estados y Ciudades de México
View mexican_states_and_cities.rb
# encoding: UTF-8
require 'httparty'
require 'json'
states_and_cities = {}
32.times do |i|
next if i == 0 # skip cus first is trash
url = "http://inegifacil.com/cities/#{i}"
@kinduff
kinduff / magic_trick.rb
Created Apr 2, 2015
Mathematical Magic Trick
View magic_trick.rb
# 52-Card Perfect Shuffles - Numberphile
# https://www.youtube.com/watch?v=Y2lXsxmBx7E
module Magic
class Sys
class << self
def ask
print "I choose: "
gets.chomp
end
@kinduff
kinduff / 4chan_webm_downloader.rb
Last active Apr 24, 2021
[4chan WebM Downloader] #4chan
View 4chan_webm_downloader.rb
#
# 4chan Webm Downloader
# Fetches all webms from a thread
# filters out all the .webm files
# and downloads to a custom path
# using wget
#
# Requires
# nokogiri: gem install nokogiri
#