Skip to content

Instantly share code, notes, and snippets.

@mayfer
mayfer / index.html
Created February 10, 2015 19:09
jQuery todo list WITH ajax
<html>
<head>
<style>
body { background: #358; color: #fff; padding: 50px; font-family: sans-serif; }
a { color: #fff; font-size: 40px; }
section {
width: 800px;
margin: 0px auto;
}
@mayfer
mayfer / index.html
Created February 10, 2015 19:04
Example showing methods within instances of functions, via the "this" keyword. Also, chaining methods by returning "this" every time.
<html>
<head>
<style>
body { background: #358; color: #fff; padding: 50px; font-family: sans-serif; }
</style>
</head>
<body>
<script>
@mayfer
mayfer / division.rb
Created February 9, 2015 18:51
division.rb
# implement division without using multiplication or division operators.
# return the result and the remainder.
# this implementation uses addition for the sum
def divide(number, divisor)
count = 0
sum = 0
while sum <= (number - divisor)
# implement division without using multiplication or division operators.
# return the result and the remainder.
# this implementation uses addition for the sum
def divide(number, divisor)
count = 0
sum = 0
while sum <= (number - divisor)
@mayfer
mayfer / exceptions.rb
Created February 9, 2015 18:44
exceptions
class EmptyArrayError < StandardError
end
def avg(arr)
if arr.length == 0
raise EmptyArrayError, "Average can only be called on arrays that have values."
end
@mayfer
mayfer / index.html.erb
Created February 6, 2015 19:35
flow player
<script src="//embed.flowplayer.org/5.5.2/embed.min.js">
<div class="flowplayer" style="width: 624px; height: 400px;">
<video>
<source type="video/mp4" src="/data/mp4.mp4">
</video>
</div>
</script>
@mayfer
mayfer / permissions.txt
Created February 6, 2015 19:34
file permissions
File Permissions
1 2 3
- --- --- ---
d rwx rwx rwx
r: Read
w: Write
x: Execute (execute file as a program, or execute directory meaning see contents of directory)
@mayfer
mayfer / files_controller.rb
Created February 6, 2015 19:29
File upload
class FilesController < ApplicationController
def index
end
def upload
upload = params[:babyfile]
name = upload.original_filename
directory = "public/data"
# create the file path
@mayfer
mayfer / select.rb
Created February 5, 2015 22:20
Block example (re-writing select with puts)
def select(arr)
arr.each do |elem|
if yield elem
puts elem
end
end
end
select([1, 5, 7, 2, 4, 6]) do |elem|
elem % 2 == 1
@mayfer
mayfer / palindrome.rb
Created February 5, 2015 22:19
Find longest palindromes
def find_longest_palindromes
words = File.open('/usr/share/dict/words').read
longest_words = []
words.each_line do |line|
word = line.strip