Skip to content

Instantly share code, notes, and snippets.

View alexpchin's full-sized avatar

Alex Chin alexpchin

View GitHub Profile
@alexpchin
alexpchin / gist:86bc4fe40a409814d153
Created October 27, 2015 12:07
Run Rails in Production
rails s -e production
@alexpchin
alexpchin / angularjs_resource_tokenhandler.js
Last active September 3, 2015 22:58 — forked from nblumoe/angularjs_resource_tokenhandler.js
AngularJS service to send auth token with $resource requests
.factory('TokenHandler', function() {
var tokenHandler = {};
var token = "none";
tokenHandler.set = function( newToken ) {
token = newToken;
};
tokenHandler.get = function() {
return token;
@alexpchin
alexpchin / Mongo-Nested-or-Embedded.md
Last active August 29, 2015 14:28
Mongo Nested / Embedded

This is more an art than a science. The [Mongo Documentation on Schemas][1] is a good reference, but here are some things to consider:

  • Put as much in as possible

The joy of a Document database is that it eliminates lots of Joins. Your first instinct should be to place as much in a single document as you can. Because MongoDB documents have structure, and because you can efficiently query within that structure there is no immediate need to normalize data like you would in SQL. In particular any data that is not useful apart from its parent document should be part of the same document.

  • Separate data that can be referred to from multiple places into its own collection.

This is not so much a "storage space" issue as it is a "data consistency" issue. If many records will refer to the same data it is more efficient and less error prone to update a single record and keep references to it in other places.

@alexpchin
alexpchin / Git.md
Last active August 29, 2015 14:27 — forked from yegeniy/Git.md
git: commands I commonly use, relevant ramblings, and configuration.

Commands I Commonly Use

  1. Clone an existing repository:

    git clone <repo>

    (e.g. https://gist.github.com/1125520.git).

  2. [Checkout and pull an existing branch][gcp]:

@alexpchin
alexpchin / gist:b42343922a96698abd18
Last active August 29, 2015 14:27 — forked from liamcurry/gist:2597326
Vanilla JS vs jQuery

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@alexpchin
alexpchin / authentication_with_bcrypt_in_rails_4.md
Last active August 29, 2015 14:26 — forked from thebucknerlife/authentication_with_bcrypt_in_rails_4.md
Simple Authentication in Rail 4 Using Bcrypt

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

@alexpchin
alexpchin / useful-sqlite3-commands.md
Created July 22, 2015 12:34
Useful sqlite3 commands

List the tables in your database:

.tables

List how the table looks:

.schema tablename

Print the entire table:

@alexpchin
alexpchin / irb-pimping.md
Last active August 29, 2015 14:25
Pimping irb

gem install irbtools

Optional.

require 'irb/completion'
require 'map_by_method'
require 'what_methods'
require 'pp'
IRB.conf[:AUTO_INDENT]=true
## Prepare ###################################################################
# Remove RVM
rvm implode
# Ensure your homebrew is working properly and up to date
brew doctor
brew update
## Install ###################################################################
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
{{ user.name }} | Business Card Generator
</a>
</div>
</div>
</nav>
<div class="container-fluid">