Skip to content

Instantly share code, notes, and snippets.

View ecasilla's full-sized avatar
🏠
Working from home

Ernie Casilla ecasilla

🏠
Working from home
  • This Crust Planet
  • Washington,DC
View GitHub Profile
@ecasilla
ecasilla / bash
Last active August 29, 2015 13:56
bash_profile
eval "$(rbenv init -)"
# =================
# Bash Prompt
# =================
# --------------------
# Colors for the prompt
# --------------------
RED="\[\033[0;31m\]"
@ecasilla
ecasilla / bashrc
Created February 27, 2014 03:09
bash_rc
PATH=$PATH:$HOME/.rvm/bin
@ecasilla
ecasilla / !sudo
Created March 1, 2014 21:30
!sudo Anymore
Ensure the correct permissions are set by running the following in Terminal:
sudo chown -R $USER /usr/local

Ubuntu 12.04, Ruby, Rails, Nginx, Unicorn and git-deploy

In the seemlingly endless search for the actual correct and easy way to deploy a Rails app, we have tried several ways. We tried out using Apache2 and running a cluster of Thin servers. With the built in threading of Puma we decided to use it with Nginx.

Server Setup

  • Create new server
  • Login to new server
    • ssh root@IPaddress (you can also use the domain name if you have the DNS setup already)
    • accept the RSA key
@ecasilla
ecasilla / Demo.js
Created March 6, 2014 16:23
Js Inhertiance
Inheritance
Inheritance allows a class of objects to inherit the properties of another class.
Lets say for example we want to have a Parent and Child classes. We want the Child class to inherit from Parent.
function Parent() {};
Parent.prototype.name = 'Parent';
@ecasilla
ecasilla / closure
Last active August 29, 2015 14:07
Using this as a way to show students about closures and scope
for (var i = 1; i <=5; i++){
setTimeout(function(){
console.log("vaule of i is: " + i);
},i*1000);
}
for (var i = 1; i <=5; i++){
(function(i){
setTimeout(function(){
@ecasilla
ecasilla / Random.js
Created November 19, 2014 16:58
Pure JS Random Function
function random(m_w, m_z) {
m_z = 36969 * (m_z & 65535) + (m_z >> 16);
m_w = 18000 * (m_w & 65535) + (m_w >> 16);
return (m_z << 16) + m_w;
}
@ecasilla
ecasilla / curry.js
Created November 19, 2014 17:15
Currying In Js
function curry(fn) {
//create sunt double function to check artiy of the calling function i.e fn
return function() {
//check the length of args and if its greater copy them and return a new function
if (fn.length > arguments.length) {
//copy logic
var slice = Array.prototype.slice;
var args = slice.apply(arguments)
//new function with args copied
return function() {
@ecasilla
ecasilla / http.js
Created November 21, 2014 23:52
Express HTTPS
//run in the command line one at a time
//openssl genrsa -out privatekey.pem 1024
//openssl req -new -key privatekey.pem -out certreq.csr
//openssl x509 -req -days 3650 -in certreq.csr -signkey -private.pem -out newcert.pem
var express = require('express'),
https = require('https'),
fs = require('fs');
privateKey = fs.readFileSync('path/to/privateKey.pem'),
cert = fs.readFileSync('path/to/newCert.pem'),
@ecasilla
ecasilla / md5-path.js
Created December 22, 2014 13:57
append md5 to path for browser caching
var calculateMD5String, filepath, md5;
md5 = require('MD5');
calculateMD5String = function(path) {
return '-' + md5(fs.readFileSync(path));
};
filepath = "app" + calculateMD5String("app.js") + ".js";