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
sum = 0 | |
i = 1 | |
while i < 5 | |
sum += i | |
i += 1 | |
end | |
p sum |
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
character = '' | |
case character | |
when "^" | |
puts 'It is a caret' | |
when ">" | |
puts 'It is a greater than' | |
else | |
puts "You can't even use a computer!" | |
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
loop do | |
p 'This will print forever' | |
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
#!/usr/bin/env bash | |
echo "Setting $1 bounds to 720p" | |
# 720p is 1280x720. | |
# Bounds is startX, startY, endX, endY. Adjust size from starting position to account for this | |
osascript -e "tell application \"$1\" to set the bounds of the first window to {250, 220, 1530, 940}" | |
# activate the app, to bring it to the front | |
osascript -e "tell application \"$1\" to activate" |
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
require 'aws-sdk' | |
s3 = Aws::S3::Resource.new( | |
region: 'us-east-1', | |
credentials: Aws::InstanceProfileCredentials.new() | |
) | |
bucket = s3.bucket('my-daily-backups') | |
file = (DateTime.now).strftime("%Y.%m.%d-backup") | |
if bucket.object(file).exists? |
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
#!/bin/sh | |
# Set up Rails app. Run this script immediately after cloning the codebase. | |
# Exit if any subcommand fails | |
set -e | |
# Copy over configs | |
if ! [ -f .env ]; then | |
cp .sample.env .env |
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
require 'net/http' | |
# Handling Network Connection Failure | |
begin | |
http = Net::HTTP.new('localhost', '3000') | |
http.open_timeout = 3 | |
http.read_timeout = 3 | |
http.get('/') | |
rescue Errno::ECONNREFUSED => e |
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 quick_sort(array, first, last) | |
if first < last | |
q = partition(array, first, last) | |
quick_sort(array, first, q) | |
quick_sort(array, q+1, last) | |
end | |
array | |
end | |
def partition(array, low_index, high_index) |
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
# nil terminating strings are not used in ruby | |
# however for this question assume you are passed a nil terminated string | |
def string_reverse(string, from, to) | |
if (!string || string.length < 2) | |
return | |
end | |
while (from < to) | |
string[from], string[to] = string[to], string[from] | |
from +=1 |
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
require 'set' | |
def remove_duplicates(string) | |
hashset = Set.new | |
write_index = 0 | |
read_index = 0 | |
while (read_index < string.length) | |
unless hashset.include?(string[read_index]) |