Skip to content

Instantly share code, notes, and snippets.

View DiegoSalazar's full-sized avatar

Diego E. Salazar DiegoSalazar

View GitHub Profile
@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-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 / 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 / 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
}

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 / 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 = [
@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 / 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 / select_has_many_through.rb
Last active December 28, 2015 10:59
Using a drop down to add a relationship between has_many :through models.
# models
class Genotype < ActiveRecord::Base
has_many :genotypes_colors
has_many :colors, through: :genotypes_colors
# to post nested attributes in a form using fields_for
accepts_nested_attributes_for :genotypes_colors
# if you're using Rails 3 attr_accessible
attr_accessible :genotypes_colors_attributes, ...rest of accessible attribs
@DiegoSalazar
DiegoSalazar / .bash_profile
Created October 9, 2013 19:23
bashprofile prompt with git branch
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_NONE="\[\e[0m\]"