This file contains hidden or 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
#!/bin/bash | |
INPUT=$1 | |
sed -n 's/.* src="\(https:\/\/.*\)".*/\1/p' $INPUT | xargs -I{} curl -O {} |
This file contains hidden or 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 RPNCalculator | |
def cleaner(idx) | |
@data_array.delete_at(idx) | |
@data_array.delete_at(idx-1) | |
end | |
def add(val,idx) | |
@data_array[idx-2] = (@data_array[idx-2].to_i).+((@data_array[idx-1].to_i)) | |
cleaner(idx) |
This file contains hidden or 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 times_table(rows) | |
(1..rows).each {|i| ((1..rows).each { |j| print "#{i*j}\t"}) && (print "\n")} | |
end | |
# Example output with "times_table(5)": | |
# 1 2 3 4 5 | |
# 2 4 6 8 10 | |
# 3 6 9 12 15 | |
# 4 8 12 16 20 |
This file contains hidden or 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
# beautifully short and unreadable | |
def fizzbuzz(n) | |
(1..n).each {|i| (i%3 == 0) ? ((i%5 == 0) ? (puts "FizzBuzz") : (puts "Fizz")) : ((i%5 == 0) ? (puts "Buzz") : (puts i))} | |
end | |
# disgustingly long and readable | |
def fizzbuzz(n) |
This file contains hidden or 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
#recursive | |
def fibonacci(n) | |
n <= 1 ? n : fibonacci(n-1)+fibonacci(n-2) | |
end | |
# iterative | |
def fibonacci(n) |
This file contains hidden or 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
# Factorial Recursive # | |
####################### | |
# Long Version: | |
def factorial(n) | |
if n == 0 | |
return 1 | |
else | |
return n*factorial(n-1) |
This file contains hidden or 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
# Validate that the price contains a maximum of two decimal places | |
# Validate the image url is a proper URL and ends with a image file type | |
# Validate that the size is only one of the following: "small", "medium", "large" | |
validates :price, :format => { :with => /^\d+??(?:\.\d{0,2})?$/ } | |
validates :imageurl, :format => { :with => /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\.(png|jpg|gif)?$/ } | |
validates :size, :inclusion => { :in => %w(small medium large) } |
This file contains hidden or 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
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
class Grouphug_scraper | |
attr_accessor :confessions, :ids, :title | |
def initialize(url) |
This file contains hidden or 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
require 'sqlite3' | |
require 'faker' | |
$db =SQLite3::Database.new( "test.db" ) | |
$db.execute <<-SQL | |
create table dummy ( | |
id INTEGER PRIMARY KEY, | |
first_name varchar(30), | |
last_name varchar(30), |
This file contains hidden or 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
require 'sqlite3' | |
class Database | |
$db ||= SQLite3::Database.new('/Users/apprentice/Desktop/FTW/lib/connect4_dev.db', :results_as_hash => true) | |
def self.instance | |
$db | |
end | |
def self.load_schema |
NewerOlder