Skip to content

Instantly share code, notes, and snippets.

@obrientimothya
obrientimothya / gist:2041588
Created March 15, 2012 03:06
Install Homebrew
/usr/bin/ruby -e "$(/usr/bin/curl -fksSL https://raw.github.com/mxcl/homebrew/master/Library/Contributions/install_homebrew.rb)"
#!/bin/bash
timezone="Australia/Melbourne"
redis_version=2.6.11
# from here: http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
# and here: https://raw.github.com/gist/257849/9f1e627e0b7dbe68882fa2b7bdb1b2b263522004/redis-server
###############################################
# To use:
# wget https://gist.github.com/raw/4497007/866287a130a5a4ca12a132fd52e391cde39f4f3f/install-redis.sh
@obrientimothya
obrientimothya / app.js
Created January 25, 2016 04:09
api-jwt /app.js
// 1. Include Packages
var express = require("express");
var bodyParser = require('body-parser');
var mongoose = require("mongoose");
var cors = require("cors");
var logger = require('morgan');
// 2. Include Configuration
var config = require('./config');
@obrientimothya
obrientimothya / config.js
Created January 25, 2016 05:12
api-jwt /config.js
module.exports = {
// 1. MongoDB
MONGO_URI: process.env.MONGO_URI || 'mongodb://localhost/apijwt',
// 2. JWT
TOKEN_SECRET: process.env.TOKEN_SECRET || 'pvpnCCZfwOF85pBjbOebZiYIDhZ3w9LZrKwBZ7152K89mPCOHtbRlmr5Z91ci4L',
// 3. Express Server Port
LISTEN_PORT: process.env.LISTEN_PORT || 3000
};
@obrientimothya
obrientimothya / routes.js
Last active January 25, 2016 11:07
api-jwt /routes.js
// 1. Include config and modules
var config = require('./config');
var moment = require('moment');
var jwt = require('jwt-simple');
var Auth = require('./controllers/auth.js');
var People = require('./controllers/people.js');
// 2. Authentication Middleware
function ensureAuthenticated(req, res, next) {
if (!req.headers.authorization) {
@obrientimothya
obrientimothya / person.js
Created January 25, 2016 05:48
jwt-api /models/person.js
// 1. Include required modules
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
mongoosePaginate = require('mongoose-paginate'),
bcrypt = require('bcryptjs');
// 2. Define the MongoDB schema for the people collection
var personSchema = new Schema({
first : {type: String, required: 'FirstNameInvalid'},
last : String,
@obrientimothya
obrientimothya / people.js
Created January 25, 2016 05:51
api-jwt /controllers/people.js
// 1. Load the Person model
var Person = require('../models/person.js');
// 2. Get a paginated list of all People
exports.list = function(req, res){
var query = {};
var page = req.params.page || 1;
var options = {
select: 'first last',
page: page
@obrientimothya
obrientimothya / create-testapp
Last active December 20, 2017 13:57
Create testapp
mkdir testapp
cd testapp
rvm use ruby-2.4.1@testapp --ruby-version --create
rails new . -T
@obrientimothya
obrientimothya / Gemfile
Created December 20, 2017 14:05
Testapp Gemfile
# --- snip
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails', '~> 3.6'
gem 'capybara'
end
# --- /snip
@obrientimothya
obrientimothya / install-rspec
Created December 20, 2017 14:11
Testapp Install RSpec
bundle install
rails g rspec:install