View css animations
@keyframes bounce { | |
0% { | |
-moz-transform: translateY(-40px); | |
-webkit-transform: translateY(-40px); | |
-ms-transform: translateY(-40px); | |
-webkit-transform: scale(0.2); | |
} | |
20%, 50%, 80%, 100% { | |
-moz-transform: translateY(0); |
View permutation_recursive.rb
#Permutations Recursive | |
def _add_head(head, res) | |
out = [] | |
res.each do |permutation| | |
0.upto(permutation.length) do |i| | |
_insert!(i, head, permutation, out) | |
end | |
end |
View subsets_recursion_ruby.rb
##Subsets | |
#my first attempt | |
def subsets(set) | |
return set if set.length == 1 | |
return [[set[0]], [set[1]], set] if set.length == 2 | |
s = subsets(set[1..-1]) | |
[[set[0]]] + s.map{|x| x+[set[0]]} + s | |
end |
View hanoi-ruby.rb
def _log(a,b) | |
"move top disk from peg #{a} to peg #{b} \n" | |
end | |
def hanoi(n, s={from: 1, free: 2, to: 3}) | |
return _log(s[:from], s[:to]) if n == 1 | |
hanoi(n-1, {from: s[:from], free: s[:to], to: s[:free]}) + | |
_log(s[:from], s[:to]) + | |
hanoi(n-1, {from: s[:free], free: s[:from], to: s[:to]}) |
View CVTemplate.html
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Jean Luc Picard - Resume</title> | |
<!--if you want to use the css file instead: | |
<link rel="stylesheet" href="stylesheet.css">--> | |
</head> | |
<style> |
View Dynamic dispatch and Method Missing in Ruby
#Examples from 'meta programming in Ruby' | |
#These methods save you from manually typing out each method for the wrapper class. | |
#If the data source is updated (new methods) you also don't need to update this wrapper class. | |
#Dynamic Dispatch | |
class Computer | |
def initialize(computer_id, data_source) | |
@id = computer_id | |
@data_source = data_source |
View badge_creator.rb
#Step 1 - Create achievement, badge, and user models | |
#Create an Achivement model | |
#This will contain all of the achievements | |
#model | |
class Achievement < ActiveRecord::Base | |
has_many :badges | |
has_many :users, through: :badges | |
end |
View multiplication_table.rb
#Multiplication table in Ruby with nested arrays | |
#[[1, 2, 3, 4], | |
# [2, 4, 6, 8], | |
# [3, 6, 9, 12], | |
# [4, 8, 12, 16]] | |
def multiplication_table(size) | |
Array.new(size) {|n| n+=1}.map do |row| | |
Array.new(size) {|col| col+=1; row*col} |
View reverse-ruby.rb
#Simple programming challenge in Ruby | |
#1) Reverse a string and array without using the ruby method 'reverse' | |
#2) Reverse a string and array recursively | |
#reverse string | |
def reverse(s) | |
i = 0 |
View sort-ruby.rb
#My implementation of sorting algorithms in Ruby | |
#insertion sort | |
def sort_insert(a) | |
index = 1 | |
while index < a.length | |
value = a[index] | |
a[0...index].each_with_index do |sorted_value, i| | |
if value < sorted_value |