Skip to content

Instantly share code, notes, and snippets.

@knwang
knwang / index.html.haml
Created October 8, 2011 20:35
Proofing_oven: Candidates list view refactored
.search
= form_tag search_candidates_path, method: :post do
%fieldset
= text_field_tag :search, params[:search]
= submit_tag "Search"
%table.standard
%thead
%tr
- ["Name", "Phone", "Email", "Github", "Twitter", "Local", "Willing to Relocate"].each do |th|
@knwang
knwang / candidates_controller.rb
Created October 8, 2011 20:36
Proofing_oven: Candidate Controller refactored
class CandidatesController < ApplicationController
expose(:candidates) { Candidate.search(params[:search]).order(:first_name) }
def search
render :index
end
end
@knwang
knwang / gist:2719697
Created May 17, 2012 15:39
hugarocketeer markup 1
<body>
<div id="hug_a_rocketeer">
<ul id="rocketeers">
<li>
<div id='pic_and_name'>
<img src='http://dummyimage.com/50x50/574b57/bcbfeb.png'/>
<span> Marian Phalen </span>
</div>
<ul id="props">
<li> 3 Hugs </li>
@knwang
knwang / gist:2720264
Created May 17, 2012 17:11
hugarocketeer javascript 2
$(function(){
var Person = Backbone.Model.extend({
defaults: {
img_url: '',
name: '',
hugs: 0,
},
refresh_hugs: function() {
var self = this;
$.getJSON(this.get("search_url"), function(data) {
@knwang
knwang / gist:2720266
Created May 17, 2012 17:12
hugarocketeer javascript 3
....
returned_results: 0,
initialize: function() {
var self = this;
this.collection = new People();
_.each(rocketeers, function(person) {
$.getJSON(person.get("search_url"), function(data) {
@knwang
knwang / gist:5020668
Last active December 14, 2015 03:28
How Does a Web Application Keep Track of User Identity?

How Does a Web Application Keep Track of its Users?

If you have an Gmail account, you have probably observed that when you visit http://www.gmail.com, sometimes it asks for your username and password, but sometimes it takes you directly into your inbox; Similarly, when you visit http://www.amazon.com, you may be surprised that the front page has your first name on it! How do websites like Google and Amazon keep track of user identity and information? In this article, we are going to explore this topic, and explain how web applications use cookies to track their users over time.

Web applications do not track users by default

The core technologies that power the Internet are designed such that when you make requests to web servers, for example, Google's front page http://www.google.com, the web server does not know who you are, nor does it have any memory of its past interactions with you. The protocol that governs the transportation of data between your browser and Google's server, which is called

@knwang
knwang / user_invite_friend_spec.rb
Created June 14, 2013 07:41
Rspec feature spec with rspec-given
require 'spec_helper'
feature 'User invites a friend' do
context 'User successfully invites friend to join' do
Given(:alice) { Fabricate(:user) }
When do
sign_in(alice)
invite_a_friend
friend_accepts_invitation
require 'rack'
require './extract_data'
surfing_app = Surfing.new
run surfing_app
at_exit do
data = YAML.dump(surfing_app.journal_entries)
File.open("data/journal_entries.yml", 'w') do |file|
file.write(data)
Simplest Rails
1. Route, ApplicationsController that renders some HTML
2. Separate content and flow control - HTML as "views"
3. dynamically generated pages
- data with different time
- render template, passing in the data
- render "dir/hello_world.html", locals: {time: "am"}
- data from the URL
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ %s)"
PROMPT='${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$reset_color%}$(git_prompt_info)% %{$reset_color%}'
git_prompt_info () {
local g="$(git rev-parse --git-dir 2>/dev/null)"
if [ -n "$g" ]; then
local r
local b
local d
local s