Skip to content

Instantly share code, notes, and snippets.

@elreimundo
elreimundo / englishnumber.rb
Created July 17, 2013 15:04
Not sure how elegant this is, but here is my number-to-its-English-word-counterpart translator
def numwords any_number
bignumwords any_number, []
end
def bignumwords number, big_array
place_names = {1 => 'thousand',
2 => 'million',
3 => 'billion',
4 => 'trillion'}
comma_count = Math.log(number,10).floor / 3
@elreimundo
elreimundo / times_table
Last active December 19, 2015 14:09
So I thought this would show a (not-very-well-spaced) times table with individual values separated by a space and each row on a new line. What am I missing?
def times_table(rows)
bigarray = []
1.upto(rows) do |x|
newarrayrow=[]
1.upto(rows) do |y|
newarrayrow << x*y
end
bigarray << newarrayrow.join(' ')
end
@elreimundo
elreimundo / triangle_validity
Last active December 19, 2015 13:18
Am I cheating? When I taught Geometry, I used to teach my kids that this was the only requirement for a (planar) triangle. I feel like I should be teaching the machine to check for isosceles, equilateral, etc., but if all we want is to determine if a triangle is valid...
def valid_triangle?(a, b, c)
(a + b > c) && (a + c > b) && (b + c > a)
end
@elreimundo
elreimundo / eightball.js
Created August 11, 2014 17:29
EightBall - intro to JS from an object-oriented perspective
// we're starting this function with an IIFE http://benalman.com/news/2010/11/immediately-invoked-function-expression/
// it's important to start this with a semicolon because otherwise any previously loaded JavaScript might try and invoke
// its last line using the anonymous function that we define here as its argument, and then invoke the resulting return value
// on line 63. That would be silly, yo. So we explicitly end the previous thought with a semicolon.
;(function () {
// we define an array of all of the possible predictions that our eight ball can make.
// unlike in Ruby, the use of all caps is purely conventional; JavaScript has no opinions about
// what capitalized variables mean.
var PREDICTIONS = [
@elreimundo
elreimundo / picker.css
Created March 2, 2014 21:01
A website to help demonstrate object-oriented design, created as part of a workshop I led for students at Dev Bootcamp
body {
background-image: url('http://pcmreviews.com/news/wp-content/uploads/2012/01/Red-carpet.jpg');
background-size: cover;
background-repeat: no-repeat;
background-position: center;
color: white;
font-family: 'Parisienne', cursive;
}
.header{
@elreimundo
elreimundo / cipher.rb
Last active August 29, 2015 13:56
A solution to a Caesar cipher challenge in which only letters are offset and in which spaces are a handful of special characters; the original challenge featured only lowercase letters and an offset of four, but this is intended to scale easily.
def north_korean_cipher message, offset = 4
unexaggerate message.chars.map{|char| decode char, offset}.join('')
end
def unexaggerate message
message.gsub(/\d+/) { |num| num.to_i / 100 }
end
def decode char, offset
case