Skip to content

Instantly share code, notes, and snippets.

View DiegoSalazar's full-sized avatar

Diego E. Salazar DiegoSalazar

View GitHub Profile
@DiegoSalazar
DiegoSalazar / sleepy_threads.rb
Created November 19, 2013 15:56
Seeing threads sleep
trials = 10
seconds = 1
threads = []
start_time = Time.now.to_f
trials.times do |i|
threads << Thread.new { sleep seconds }
end
threads.each &:join
@DiegoSalazar
DiegoSalazar / addhost
Last active December 28, 2015 19:19
Quickly add a host to the hosts file.
#!/bin/bash
# quickly add a host to the hosts file
hostname="$1"
ipaddress="$2"
hostsfile="$3"
if [ -z "$ipaddress" ]; then
ipaddress="127.0.0.1"
fi
@DiegoSalazar
DiegoSalazar / name_likeness.rb
Last active January 2, 2016 03:39
string likeness test using Levenshtein distance
# install the levenshtein gem first with:
# sudo gem install levenshtein-ffi
require 'levenshtein'
def names_are_close?(s1, s2, tolerance = 1)
Levenshtein.distance(s1, s2) == tolerance
end
name_pairs = [

Carshow App Tasks

  • Back button - Should say "Admin" when logged in.
  • Admin > Show Settings > Location Address should allow to enter physical address and location (venue) name.
  • Admin > Show Settings > Date & Time is for duration of actual show (day of show).
  • Admin > Show Settings > Below "Location Address" add section (not just a field, add a heading for it too) to enter show website address.
  • Admin > Show Settings > Judging - when selecting "Closed Judging" it should disable the participant voting options on Participant accounts.
  • Admin > Show Settings > Upload Show Logo - should allow to upload image. Most likely for flyer, not logo.
  • Admin > Car Classes > Add a Subclass - Does not work.
  • Admin > Car Classes > Add a Subclass - Add a description text field for each sub class.
@DiegoSalazar
DiegoSalazar / add_sftp_user.sh
Created January 21, 2014 22:29
Add an SFTP user, assuming an sftpusers group and the user's home folder already exists.
add_sftp_user() {
sudo useradd -d /home/$1 $1
sudo passwd $1
sudo usermod -g sftpusers $1
sudo usermod -s /bin/false $1
sudo chown $1:sftpusers -R /home/$1
sudo chown root:root /home/$1
}
@DiegoSalazar
DiegoSalazar / var_thread_test.rb
Created February 12, 2014 18:43
test variables are shared between threads
# testing out class variables are shared between instances
require 'thread'
class A
@m = Mutex.new
@@m = Mutex.new
M = Mutex.new
def self.m; @m end
def self.mm; @@m end
@DiegoSalazar
DiegoSalazar / hw0-part1.rb
Created May 15, 2014 21:46
ESAAS HW0 Part 1
# I iterate over ints using inject and pass in an accumulator
# which for the purposes of summing will have to be 0
# each number is added to the accumulator and the final result
# is returned
def sum(ints)
ints.inject(0) { |sum, i| sum += i }
end
# this was fun, I sort and mutate the ints array to maintain its
# newly sorted state, pop off the last value which will now be
@DiegoSalazar
DiegoSalazar / hw0-part1.rb
Created May 15, 2014 22:16
ESAAS HW0 Part 2
# using string interpolation
def hello(name)
"Hello, #{name}"
end
# I first check if the first letter is alphabetical
# then see if the first lower case letter is a vowel
# and return the opposite of that boolean
def starts_with_consonant?(s)
return false unless s[/^[a-z]/i]
@DiegoSalazar
DiegoSalazar / hw0-part3.rb
Created May 15, 2014 22:23
ESAAS HW0 Part 3
class BookInStock
# declare setters and getters
attr_accessor :isbn, :price
def initialize(isbn, price)
# checking for empty string or price is greater 0, raises exception
raise ArgumentError if isbn.strip.empty? || price <= 0
@isbn, @price = isbn, price
end
@DiegoSalazar
DiegoSalazar / each-with-else.rb
Created October 15, 2014 15:16
Ruby each with else
def for_each(items, do_this, options = { else: -> {} })
unless items.empty?
items.each &do_this
else
options[:else].call
end
end
items = [1,2,3]
for_each items, ->(i) {