Skip to content

Instantly share code, notes, and snippets.

View jeffchang's full-sized avatar

Jeff Chang jeffchang

View GitHub Profile

Views & Partials

In Sinatra:

get ‘/users/:id’ do

@user = User.find(params[:id])

erb :show_user

@jeffchang
jeffchang / form-validator.js
Last active December 21, 2015 03:39 — forked from ksolo/form-validator.js
Form Validation
$(function(){
$("form").on("submit", function(e) {
e.preventDefault();
$(".error").remove();
var email = $("input[name='email']");
var password = $("input[name='password']");
var emailRegex;
var passwordRegex;
var error = [];
$(document).ready(function () {
$("form").one("submit", function(event) {
event.preventDefault();
url = $(this).attr("action");
var value = Math.floor(Math.random() * 6) + 1;
var data = $(value).serialize();
$.post(url, data, function(response) {
$("#die-container").html(response).effect("shake");
});
/* Here is your chance to take over Socrates!
Spend 10 minutes on each of the following hacks to the socrates website.
Enter them in the console to make sure it works and then save
your results here.
Choose a new pair for each. Add your names to the section you complete.
*/
/* Here is your chance to take over Socrates!
Spend 10 minutes on each of the following hacks to the socrates website.
Enter them in the console to make sure it works and then save
your results here.
Choose a new pair for each. Add your names to the section you complete.
*/
@jeffchang
jeffchang / index.html
Created August 11, 2013 20:57 — forked from dbc-challenges/index.html
DBC Phase 2 Practice Assessment Part 3
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="http://cdn.jsdelivr.net/normalize/2.1.0/normalize.css">
<link rel="stylesheet" href="main.css">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Lato:100,900">
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/3.0.2/css/font-awesome.min.css">
</head>
# Part 4 -- Extra Credit (Refactor using Composition)
module Vehicle
attr_reader :status, :tickets
def drive
@status = :driving
end
def brake
class Vehicle
attr_reader :status, :tickets
def initialize(args)
@color = args[:color]
@tickets = 0
end
def drive
@status = :driving
@jeffchang
jeffchang / gist:5772331
Created June 13, 2013 09:11
Sudoku testing ...
class Impossible < StandardError
end
class SudokuBoard
attr_accessor :board
def initialize(board)
raise ArgumentError.new('Not enough rows') unless board.size == 9
board.each_with_index do |row, i|
@jeffchang
jeffchang / sudoku_v2.rb
Created May 24, 2013 08:56
Expanded version of the Sudoku solver intro'd in Chapter 1 of Flanagan & Matz's "The Ruby Programming Language" -- solves 9 x 9, 16 x 16 and 25 x 25 puzzles (using an array rather than a string). Enter periods for empty cells, commas between cells, and use numbers (1..9, 1..16 and 1..25) for known values. Will automatically detect size of puzzle…
module Sudoku
class Puzzle
def initialize(lines)
if (lines.respond_to? :join)
s = lines.join(",")
else
s = lines.dup
end