Skip to content

Instantly share code, notes, and snippets.

View karloscodes's full-sized avatar
👨‍💻
Building stuff

Carlos Castellanos karloscodes

👨‍💻
Building stuff
View GitHub Profile

Zero downtime deploys with unicorn + nginx + runit + rvm + chef

Below are the actual files we use in one of our latest production applications at Agora Games to achieve zero downtime deploys with unicorn. You've probably already read the GitHub blog post on Unicorn and would like to try zero downtime deploys for your application. I hope these files and notes help. I am happy to update these files or these notes if there are comments/questions. YMMV (of course).

Other application notes:

  • Our application uses MongoDB, so we don't have database migrations to worry about as with MySQL or postgresql. That does not mean that we won't have to worry about issues with the database with indexes being built in MongoDB or what have you.
  • We use capistrano for deployment.

Salient points for each file:

class Shape
def initialize(color)
@color = color
end
def repr
raise 'Abstract method, to be implemented on subclasses'
end
def draw
class Email::Validate
def self.call(email)
new(email, RFC::CheckSyntaxt, SMTP::CheckUserExistance).call
end
attr_reader :email, :rfc_check_syntaxt, :smtp_check_user
def initialize(email, rfc_check_syntaxt, smtp_check_user)
@email = email
@rfc_check_syntaxt = rfc_check_syntaxt
@karloscodes
karloscodes / gAppScriptBuildReport.js
Last active November 11, 2016 11:59
Google spreadsheets script to create weekly reports in support of order products to providers.
// This is meant to be executed periodically, adapt it depending on you sell pace
// or create reports for previous weeks instead of using doing it in realtime.
var moment = Moment.load();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var startOfLastWeek = moment.utc().startOf('week').add(1, 'd');
var endOfLastWeek = moment.utc().endOf('week').add(1, 'd');
Logger.log('Week starts: ' + startOfLastWeek.toString());
Logger.log('Week ends: ' + endOfLastWeek.toString());
@karloscodes
karloscodes / Bluebird-vs-Callbag.md
Last active February 27, 2018 15:39
Comparing promise chaining solutions. Javascript, Async, Bluebird, Callbag
const { forEach, fromIter, map, filter, pipe, interval, take, fromPromise, flatten } = require('callbag-basics');
const request = require('request-promise');
const Promise = require('bluebird');

const events = [
  { type: 'event', value: 1 },
  { type: 'event', value: 2 },
  { type: 'event', value: 3 },
@karloscodes
karloscodes / FunctionalProgrammingJSChallenge-1.md
Last active March 6, 2018 13:17
First steps using the Ramda library. Ramda, Javascript, Functional Programming

Example to find an object inside an array given a name then, returns its value

const R = require('ramda');

const sesNotification = {
  "notificationType": "Delivery",
  "mail": {
    "headers": [
 {
@karloscodes
karloscodes / FunctionalProgrammingJSChallenge-2.md
Last active March 6, 2018 13:27
Ramda, Javascript, Functional Programming
const R = require('ramda');
const users = [
  { ses: { sesCreds: 1 }, senders: [{ sender: 11 }, { sender: 12 }, { sender: 13 }] },
  { ses: { sesCreds: 2 }, senders: [{ sender: 21 }, { sender: 22 }, { sender: 23 }] },
  { ses: { sesCreds: 3 }, senders: [{ sender: 31 }, { sender: 32 }, { sender: 33 }] }
];

const notificationTypes = ['Bounce', 'Complaint'];
@karloscodes
karloscodes / bench.rb
Last active July 9, 2019 13:14
Ruby inmutable array concatenation. A prove benchmark.
# ruby --version
# ruby 2.6.3p62
require 'benchmark'
def without_splat(a, b, c); end
def with_splat(*a); end
@karloscodes
karloscodes / docker-compose.yml
Created July 16, 2019 20:36
A versatile docker compose
version: '3.3'
services:
pg:
image: postgres:10
volumes:
- pg_data:/var/lib/postgresql/data
ports:
- 5432:5432
@karloscodes
karloscodes / fp-oop-di.js
Last active October 7, 2019 18:38
Depdency injection OOP vs FP in javascript. A use case for currying. Partial application.
// -----------------------------------------------
// OOP dependency injection (the repository implementation can be switched in runtime)
// -----------------------------------------------
class UserService {
constructor(userRepository) {
this.userRepository = userRepository
}
create(params) {
validate(params)