Skip to content

Instantly share code, notes, and snippets.

View domgetter's full-sized avatar

Dominic Muller domgetter

View GitHub Profile
threads = []
threads << Thread.new do
puts "I'm gonna stop"
Thread.stop
puts "I started again!"
end
sleep 3
threads[0].run.join
@domgetter
domgetter / calculadora.rb
Created August 27, 2014 02:41
private keyword
# horas nocturnas SICA
require 'chronic'
class Calculadora
AM4 = Chronic.parse('4 am')
PM9 = Chronic.parse('9 pm')
JORNADA = 31500
H12 = 2592000
#include <stdio>
int check_for_zero(float num1, float num2, float num3, float num4, float num5, float num6) {
int zero_present = 0;
if(num1 == 0 || num2 == 0 || num3 == 0 || num4 == 0 || num5 == 0 || num6 == 0) {
zero_present = 1;
}
return zero_present;
}
discount = case gets.chomp
when "i" then " 6"
when "s" then "35"
when "c" then "20"
end
print "**********************************
** Congratulations! **
** **
** You will get #{discount}% OFF **
#include <stdio>
void user_prompt(){
printf("Please enter \"c\" for College Student, \"s\" for Senior Citizen, or \"i\" for other: ");
}
char gather_input(){
char input;
scanf("%s", &input);
return input;
def random_consonant
([*"b".."z"] - ["e", "i", "o", "u"]).sample
end
> url = "default-ubuntu-1404-i386.load_avg.fifteen"
> url2 = "default-ubuntu-1404-i386.vagrantup.com"
> match_pattern = /default-ubuntu-1404-i386\.(?=vagrantup)/
> url.match match_pattern
#=> nil
> url2.match match_pattern
#=> #<MatchData "default-ubuntu-1404-i386.">
some_number = 3
case some_number
when ->(n) { n == 2 }
puts "the number was 2!"
when ->(n) { n == 3 }
puts "the number was 3!"
else
puts "the number wasn't 2 or 3..."
end
#=> the number was 3!
some_number = 3
case some_number
when lambda {|n| n == 2 }
puts "the number was 2!"
when lambda {|n| n == 3 }
puts "the number was 3!"
else
puts "the number wasn't 2 or 3..."
end
#=> the number was 3!
@domgetter
domgetter / a_soft_list.txt
Created November 6, 2014 04:15
Naming in programming
when naming, you should:
Reveal intention
avoid disinformation
make meaningful distinctions
use pronounceable names
use searchable names
avoid encodings (stick to ascii)
classes should probably be nouns
methods should probably be verbs or verb phrases
don't be cute