Skip to content

Instantly share code, notes, and snippets.

View lisaychuang's full-sized avatar

Lisa Huang-North lisaychuang

View GitHub Profile
@lisaychuang
lisaychuang / application.css
Last active March 31, 2019 23:38
Ember Octane: Hangman game styles
.hangman {
margin: 0 auto;
border: 1px solid black;
}
.hangman line {
stroke: black;
stroke-width: 4;
}
.hangman.dead line,
.hangman.dead circle {
@lisaychuang
lisaychuang / application.hbs
Last active March 30, 2019 00:24
Ember Octane Hangman SVG starter file
<svg height="400" width="400" class="hangman">
<g id="body">
<line id="rope" x1="200" y1="20" x2="200" y2="60" />
<g id="head">
<circle cx="200" cy="80" r="20" stroke="black" stroke-width="4" fill="white" />
<g id="rEyes">
<circle cx="193" cy="80" r="4" />
<circle cx="207" cy="80" r="4" />
@lisaychuang
lisaychuang / create-wishlist.js
Created September 9, 2018 17:42
Rails-riflepaper createWishlist JS file
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.
function createWishlist(url, data) {
$.post(url, data, "json")
// on success create a new instance of our model object
.done(json => {
let myWishList = new Wishlist(json);
myWishList.updateHTML();
})
@lisaychuang
lisaychuang / _newForm.html.erb
Created September 9, 2018 02:57
Rails-riflepaper Wishlist New Page
<h1>Create a new wishlist</h1>
<!-- Form for creating a new Wishlist -->
<%= form_for([user, wishlist]) do |f|%>
<p>
<%= f.label :name %>
<%= f.text_field :name %><br>
<%= f.label :budget %>
<%= f.number_field :budget, value: number_to_currency(f.object.budget.to_f, delimiter: '', unit: ''), step: :any %><br>
@lisaychuang
lisaychuang / show.html.erb
Created September 8, 2018 23:41
Rails-riflepaper Wishlist Show Page
<!-- Wishlist square -->
<div class="wishlist-info">
<h1>Wishlist: <%= @wishlist.name%></h1>
<p>Created on: <%= @wishlist.date_created%></p>
<p>Budget: <%= number_to_currency(@wishlist.budget)%></p>
<p>Notes: <%= @wishlist.notes%></p>
<% if display_edit_delete_link %>
<%= link_to("Edit wishlist", edit_user_wishlist_path(@user, @wishlist)) %><br><br>
@lisaychuang
lisaychuang / show.html.erb
Created September 8, 2018 23:27
Rails-riflepaper Product Show Page
<!-- Button to show Next Product using AJAX GET request-->
<button class="js-next" data-id="<%= @product.id %>">Next product</button>
<br>
<!-- Product square -->
<div class="product-square">
<h1 class="name"><%= @product.name%></h1>
<p class="category">Category: <%= @product.category.name%></p>
<p class="price">Price: <%= "#{number_to_currency(@product.price)}" %></p>
@lisaychuang
lisaychuang / router.rb
Created August 8, 2018 06:59
rails-riflepaper router
Rails.application.routes.draw do
post '/wishlists/:id/toggle_product' => 'wishlists#toggle_product', as: :toggle_wishlist_product
resources :users do
resources :wishlists
end
resources :sessions
resources :products do
@lisaychuang
lisaychuang / scraper.rb
Created August 8, 2018 06:05
rails-riflepaper web scraper
require 'nokogiri'
require 'open-uri'
require 'pry'
class Scraper
def get_page(url_str)
html = open(url_str)
doc = Nokogiri::HTML(html)
doc
@lisaychuang
lisaychuang / product.rb
Created August 8, 2018 05:55
Rails-riflepaper Product Model
class Product < ActiveRecord::Base
belongs_to :wishlist
belongs_to :category
# Validations
validates :name, :price, :url, :image_link, presence: true
validates :url, uniqueness: true
validates :name, length: {minimum: 2}
#Scope methods
@lisaychuang
lisaychuang / layout-menubar.erb
Created August 6, 2017 18:37
Sinatra Course Management: layout.erb menu bar section
<%# SHOW Dropdown menu only when user is logged in %>
<div class="mui-col-md-2">
<% if logged_in? %>
<div class="mui-dropdown">
<button class="mui-btn mui-btn--raised" data-mui-toggle="dropdown">
<span class="mui-caret"></span>
</button>
<ul class="mui-dropdown__menu mui-dropdown__menu--right">