Skip to content

Instantly share code, notes, and snippets.

@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);
#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
##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
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]})
<!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>
#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
@Yorgg
Yorgg / badge_creator.rb
Last active November 21, 2023 13:21
Creating badge and achievements functionality in Ruby on Rails
#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
@Yorgg
Yorgg / multiplication_table.rb
Last active August 29, 2015 14:26
Multiplication table in ruby
#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}
@Yorgg
Yorgg / reverse-ruby.rb
Last active August 29, 2015 14:26
Reverse Ruby Methods
#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
@Yorgg
Yorgg / sort-ruby.rb
Last active August 29, 2015 14:25
Sorting in Ruby
#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