Skip to content

Instantly share code, notes, and snippets.

class EventsController < ApplicationController
def index
@events = Event.all.reverse
end
end
@philwilt
philwilt / binaryTree
Created December 2, 2014 18:57
Binary Tree Ancestor
class Node
constructor: (val) ->
@val = val
@left = null
@right = null
findAncestors = (node, val, arr) ->
return false if node == null
if node.val == val
return arr.push(val)
@philwilt
philwilt / analyze_stocks
Last active August 29, 2015 14:10
stock_prices
def analyze_stocks(prices)
best_buy_day = nil
best_sell_day = nil
max_profit = 0
prices.each_with_index do |buy_price, buy_day|
prices.slice(buy_day..prices.length).each_with_index do |sell_price, sell_day|
profit = sell_price - buy_price
if profit > max_profit
best_sell_day = buy_day + sell_day + 1
@philwilt
philwilt / version strategy
Created November 1, 2014 02:20
api versioning
URI Versioning:
-Good for namespace routes
-Bad for aesthetics
Header:
-Good for pretty urls
-Bad cause its less clear what's happening and have to set on every request
Accept header:
-Kinda the same as header
@philwilt
philwilt / bst
Last active August 29, 2015 14:08
binary search tree
class BinarySearchTree
constructor: () ->
@val = null
@size = 0
@right = null
@left = null
insert: (val) ->
if (@val == null)
@philwilt
philwilt / angular vocab
Created October 28, 2014 03:56
angular notes
module - way of compartmentalizing pieces of code for similar functionality
scope - app context
data binding - connecting UI and biz logic
directives - attach functionality to DOM
controllers - functionality for models
dependency injection - dependencies for controllers and modules
Discontinued in 2.0:
Controllers
Directive Definition Object
@philwilt
philwilt / commentscreate
Created September 30, 2014 03:03
comment on article code
# view/comments/_form.html.haml
= form_for(@comment) do |f|
- if @comment.errors.any?
#error_explaination
%h2= pluralize(@comment.errors.count, 'error')
%ul
- @comment.errors.full_message.each do |message|
%li= message
.field
@philwilt
philwilt / bourbon-rails
Last active August 29, 2015 14:06
Rails with bourbon neat with bitters and refills
# Gemfile
# styles and structure for bourbon
gem 'bitters'
# sass mixins
gem 'bourbon'
# grid framework for bourbon
gem 'neat'
# patterns for bourbon
gem 'refills'
@philwilt
philwilt / custom-topbar
Created September 19, 2014 01:54
Customizing top bar colors for foundation 5
// framework_and_overrides.css.scss
@import "_settings";
@import "foundation";
// _settings.css.scss
$accent-color-1: #8bbb4b;
$topbar-bg-color: $accent-color-1;
$topbar-bg: $accent-color-1;
$topbar-dropdown-bg: $accent-color-1;
@philwilt
philwilt / Personal Domain DNS
Created September 18, 2014 18:04
Personal Domain DNS records
$ host philwilt.com
philwilt.com has address 64.74.223.6
philwilt.com mail is handled by 10 p.nsm.ctmail.com.
$ dig philwilt.com
; <<>> DiG 9.8.5-P1 <<>> philwilt.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34499