Skip to content

Instantly share code, notes, and snippets.

0xFA1A8B6d57B252b8307770A569023f6568DF54E3
@kwaters12
kwaters12 / the_good_parts
Last active August 29, 2015 14:02
Javascript: The Good Parts notes
Ch.2 - The Grammar
- Blocked comments /* */
- Line comments //
- /* */ can mess up regular expressions, so it is recommended to stick to //
Names
- names are strings. A list of reserved words:
abstract
boolean break byte
case catch char class const continue
@kwaters12
kwaters12 / algorithms
Created March 28, 2014 22:33
Algorithm Study
Algorithm - any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values as output.
Runtime Analysis
- One of the most important aspects of an algorithm is how fast it is.
- Worst-case runtime - how long it would take the algorithm to run if it were given the most insidious of all possible inputs.
- Average-case runtime - how long it would take the algorithm to run if it were given all possible inputs.
- worst-case is often easier to reason about, and therefore is more frequently used as a benchmark.
Approximate completion time for algorithms, N = 100
@kwaters12
kwaters12 / amazon_paperclip
Created March 20, 2014 04:49
Uploading Images to Amazon S3 using Paperclip Gem
-- Workflow - from http://blog.littleblimp.com/post/53942611764/direct-uploads-to-s3-with-rails-paperclip-and
Our app will work as follows:
User uploads their file directly to a temporary directory on S3
A form callback posts the temporary file URL to our app
Our app creates a new Document object, sets some initial data from the temporary S3 file, then queues a background process to move the temporary file to the location that Paperclip expects it to be and to process thumbnails if required
Show users a message if they visit a file page while its still being processed
@kwaters12
kwaters12 / namespaces
Created March 6, 2014 23:50
Namespaces
module Computers
class Apple
end
end
module Fruits
class Apple
end
end
@kwaters12
kwaters12 / gist:9395349
Created March 6, 2014 17:44
Active Record Notes
1. Retrieving Objects from the Database
Finder methods. All return an instance of ActiveRecord::Relation:
bind
create_with
eager_load
extending
from
group
having
includes
@kwaters12
kwaters12 / rails_restricted_names
Created March 3, 2014 23:52
Rails Restricted Names
:_delete
:title
session
request
cookies
response
post
send_data
send_file
@kwaters12
kwaters12 / likebutton
Created March 3, 2014 23:47
Adding a Like button
1. rails g migration add_like_to_projects like_counter:integer
2. routes.rb ->
resources :projects do
get :like, on: :member
end
3. projects_controller.rb ->
def like
session[:project_ids] ||= []
if session[:project_ids].include? params[:id].to_i
@kwaters12
kwaters12 / gist:9312903
Created March 2, 2014 20:01
Base Project Gems
gem 'bootstrap-sass'
gem 'quiet_assets'
gem 'better_errors'
gem 'formtastic'
gem 'formtastic-bootstrap'
@kwaters12
kwaters12 / session_notes
Created March 1, 2014 06:12
Session Notes
Session
- stores small amounts of data that will be persisted between requests.
- only available in the controller and the view
- Session storage mechanisms:
ActionDispatch::Session::CookieStore - Stores everything on the client.
ActionDispatch::Session::CacheStore - Stores the data in the Rails cache.
ActionDispatch::Session::ActiveRecordStore - Stores the data in a database using Active Record. (require activerecord-session_store gem).
ActionDispatch::Session::MemCacheStore - Stores the data in a memcached cluster (this is a legacy implementation; consider using CacheStore instead).
- stores unique ID for each session as a cookie
- CookieStore holds around 4kb of data.