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
# | |
# 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 | |
# |
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
# 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 |
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
# 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}" |
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
# 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 |
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
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 |
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 HashTable | |
def initialize(size) | |
@size = size | |
@buckets = Array.new(@size) | |
end | |
def add(value) | |
index = hash(value) | |
@buckets[index] = value | |
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
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? |
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
def removeAt(index) | |
prev = nil | |
node = @head | |
i = 0 | |
loop do | |
prev = node | |
node = node.next | |
i += 1 | |
break unless !node.nil? and i < index | |
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
class LinkedList | |
#... | |
end | |
class Node | |
#... | |
end | |
class HashTable | |
def initialize(size) |
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
def findIndex(values, target) | |
binarySearch(values, target, 0, values.size - 1) | |
end | |
def binarySearch(values, target, start, finish) | |
return -1 if start > finish | |
middle = ((start+finish)/2).floor | |
value = values[middle] |
OlderNewer