Skip to content

Instantly share code, notes, and snippets.

View bparanj's full-sized avatar

Bala Paranj bparanj

View GitHub Profile
@bparanj
bparanj / while.rb
Created March 30, 2017 06:49
Ruby Object Model Exercise #2
sum = 0
i = 1
while i < 5
sum += i
i += 1
end
p sum
@bparanj
bparanj / case.rb
Created March 30, 2017 07:11
Ruby Object Model Exercise #3
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
@bparanj
bparanj / loop.rb
Created March 30, 2017 07:16
Ruby Object Model Exercise #4
loop do
p 'This will print forever'
end
#!/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"
@bparanj
bparanj / verify_s3_file.rb
Created July 19, 2017 23:02 — forked from hartfordfive/verify_s3_file.rb
Check if file exists in S3 bucket with Ruby aws-sdk gem
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?
@bparanj
bparanj / setup.sh
Created November 23, 2017 04:36 — forked from r00k/setup.sh
#!/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
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
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)
# 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
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])