Skip to content

Instantly share code, notes, and snippets.

@mayfer
mayfer / gist:8361699
Created January 10, 2014 20:11
jQuery example that checks to see if the two passwords are the same upon submitting the form.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<style type='text/css'>
html { margin: 0; padding: 0; }
body { margin: 0; padding: 30px; background: #049; font-family: Menlo, monospace; font-size: 11px; }
#container { width: 600px; margin: 0 auto; }
.red { background: #a00; }
@mayfer
mayfer / jquery_example.html
Created January 10, 2014 20:11
jQuery example that checks to see if two passwords are the same upon submitting the form.
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<style type='text/css'>
html { margin: 0; padding: 0; }
body { margin: 0; padding: 30px; background: #049; font-family: Menlo, monospace; font-size: 11px; }
#container { width: 600px; margin: 0 auto; }
.red { background: #a00; }
@mayfer
mayfer / exam.rb
Created February 6, 2014 00:53
Example ruby exercise
class Exam
attr_accessor :passes
attr_accessor :fails
def initialize(students)
@students = students
@passes = []
@mayfer
mayfer / anagrams.rb
Created February 20, 2014 21:41
Find the word with most number of anagrams
words = File.open('/usr/share/dict/words').read
words.gsub!(/\r\n?/, "")
hashes = {}
anagrams = {}
most = 1
most_anagram = ''
words.each_line do |word|
word = word.strip.downcase
@mayfer
mayfer / algorithms.rb
Created February 21, 2014 20:29
Problem solving and runtime complexity exercises
# given an array of integers, find the largest value
def find_largest(numbers)
# initialize our "largest number" to the first number in the array
# because it is the largest so far
largest = numbers[0]
# looping over each number once
numbers.each do |i|
@mayfer
mayfer / orm.rb
Created May 21, 2014 18:00
Generic ORM example
require 'pg'
class Orm
@@conn = PG.connect(
dbname: 'dfq35t7uirbums',
port: 5432,
user: 'bmdjwluxchptuq',
host: 'ec2-54-204-41-178.compute-1.amazonaws.com',
password: 'aEH-cKdr2zoXYUAjI8Xjma5eXK'
@mayfer
mayfer / author.rb
Created May 21, 2014 18:01
Author ORM example
require 'pg'
class Author
@@conn = PG.connect(
dbname: 'dfq35t7uirbums',
port: 5432,
user: 'bmdjwluxchptuq',
host: 'ec2-54-204-41-178.compute-1.amazonaws.com',
password: 'aEH-cKdr2zoXYUAjI8Xjma5eXK'
@mayfer
mayfer / examples.rb
Created June 3, 2014 23:55
Functions that find most common prey, and see if words rhyme
r = {
"shrimp" => [
"algae",
"other_shrimps",
"seaweed",
],
"toad" => [
"children",
"flies",
@mayfer
mayfer / intro.html
Created June 10, 2014 05:15
Intro to JS
<html>
<head>
<!-- we need to load jquery before we use it -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
// this code must run when the document is fully loaded
// otherwise we will try to bind events on elements that don't exist yet (html and code is parsed top to bottom)
$(document).ready( function () {
@mayfer
mayfer / largest.rb
Created July 9, 2014 00:18
Three alternative methods of looping in ruby to find the maximum number in an array.
def maximum(numbers)
largest = numbers.first
index = 0
# keep looping over every element in the array
while index < numbers.size
# check to see if current number is larger than the largest one so far