Skip to content

Instantly share code, notes, and snippets.

View petehuang's full-sized avatar

Pete Huang petehuang

View GitHub Profile
@petehuang
petehuang / 0000_create_appointments.rb
Last active December 16, 2015 17:30
Errors: Failure/Error: @appointment = Appointment.new(user_id: user.id, receiver_id: other_user.id, prepday:Date.today, preptime:Time.now, preplocation: "Norris", notes: "NA") ActiveRecord::UnknownAttributeError: unknown attribute: user_id
0000_create_appointments.rb
class CreateAppointments < ActiveRecord::Migration
def change
create_table :appointments do |t|
t.integer :user_id
t.integer :receiver_id
t.date :prepday
t.time :preptime
t.string :preplocation
<!DOCTYPE html>
<html>
<head>
<title>Directory</title>
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
</head>
<body>
<header class="navbar navbar-fixed-top navbar-inverse">
@petehuang
petehuang / routes.rb
Created May 5, 2013 17:55
redirecting to users index after a user profile edit. why does this work?
devise_for :users do
get 'users', :to => 'users#show', :as => :user_root
end
@petehuang
petehuang / cue1.rb
Created May 12, 2013 01:43
Cue Challenge answers
s = File.open("gettysburg.txt").read().downcase
maxrange = s.length
matched = {}
for range in (2..maxrange)
(matched["#{range}"] ||= []) << (0..s.length - 1).find_all { |i| s[i,range] == s[i,range].reverse }
end
@petehuang
petehuang / letsrate.js
Created June 16, 2013 19:27
Trying to override "rate" to not save a rating. From letsrate gem.
$.fn.raty.defaults.path = "/assets";
$.fn.raty.defaults.half_show = true;
$(function(){
$(".star").each(function() {
var $readonly = ($(this).attr('data-readonly') == 'true');
$(this).raty({
score: function(){
return $(this).attr('data-rating')
},
@petehuang
petehuang / helper.rb
Created June 30, 2013 16:10
Only displays the radio button generated outside of the 'until'.
def show_overall_rating(value)
count = 1
until count == value
radio_button :review, :overall, count, options={:class => 'star', :disabled => 'disabled'}
count += 1
end
radio_button :review, :overall, count, options={:class => 'star', :disabled => 'disabled', :checked => 'checked'}
end
@petehuang
petehuang / SinglyLinkedList.java
Last active December 20, 2015 19:59
Singly linked list implementation in Java
public class ListNode {
//has two pieces: data and pointer to next node
private int value;
private ListNode next;
//constructors
public ListNode() {
}
@petehuang
petehuang / DoublyLinkedList.java
Last active December 20, 2015 20:09
Doubly Linked List implementation in Java, missing "remove value" method
//same ListNode as SLL except with prev, getPrevious, setPrevious
public class ListNode {
private int value;
private ListNode prev;
private ListNode next;
//need constructor, get/set values/prev/next
@petehuang
petehuang / Stack.java
Last active December 20, 2015 21:09
Stack implementation in Java
public class Element {
private int value;
private Element next;
public Element(int value, Element next) {
this.value = value;
this.next = next;
}
}
@petehuang
petehuang / check_zipcode.rb
Created August 12, 2013 22:34
How we made our geocoding faster. This will also avoid the daily rate limit for Google Maps
#This goes as a before_filter on your controller.
#Requires 'geocoder' gem
def check_zipcode
if params[:zipcode].nil?
return
end
if !Zipcode.where('zip = ?', params[:zipcode]).empty?
zip = Zipcode.where('zip = ?', params[:zipcode]).first
return [zip.lat, zip.lng]