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 by_three? number | |
number % 3 == 0 ? true : false | |
end | |
by_three? 5 | |
# => false | |
by_three? 9 | |
# => true |
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 timestamp | |
Time.now.to_i | |
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
def prime_numbers max | |
for i in (2..max) do | |
for j in (2..i) do | |
break if i%j == 0 | |
end | |
p "#{i} is a prime number." if i == j | |
end | |
end | |
require 'prime' |
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 tbl max | |
for y in (1..max) do | |
for x in (1..max) do | |
sol = y*x | |
if sol < 10 | |
print "#{sol} " | |
elsif sol < 100 | |
print "#{sol} " | |
else | |
print "#{sol} " |
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
<!-- JW Player Library --> | |
<script src="http://jwpsrv.com/library/MCK8hplLEeOY0CIACmOLpg.js"></script> | |
<!-- div for the player --> | |
<div id='playerKXSDPIwKERSv'></div> | |
<!-- Script to display video file in the player div --> | |
<script type='text/javascript'> | |
jwplayer('playerKXSDPIwKERSv').setup({ | |
// URL to the video file |
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 alphabetize arr, rev=false | |
if rev | |
arr.sort.reverse | |
else | |
arr.sort | |
end | |
end | |
puts alphabetize ["b","e","a"], true | |
# => ["e","b","a"] |
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
<?php | |
function random_string($length) { | |
$LETTERS = 'abcdefghijklmnopqrstuvwxyz'; | |
$random_string = ''; | |
for ($i=0; $i < $length; $i++) { | |
$random_string = $random_string.$LETTERS[rand(0, strlen($LETTERS)-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
floats = [1.2, 3.45, 0.91, 7.727, 11.42, 482.911] | |
# Write your code below this line! | |
round_down = Proc.new { |f| f.floor } | |
# Write your code above this line! | |
ints = floats.collect(&round_down) |
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
case var | |
when 1 | |
puts 1 | |
when 2 | |
puts 2 | |
else | |
puts 'none' | |
end | |
case var |
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 'benchmark' | |
string_AZ = Hash[("a".."z").to_a.zip((1..26).to_a)] | |
symbol_AZ = Hash[(:a..:z).to_a.zip((1..26).to_a)] | |
string_time = Benchmark.realtime do | |
100_000.times { string_AZ["r"] } | |
end | |
symbol_time = Benchmark.realtime do |
NewerOlder