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
@karloscodes
karloscodes / optimistic-locking.md
Last active October 16, 2023 19:53
Pesimistic locking sequence diagram
sequenceDiagram
    participant John as John
    participant DB as Database
    participant Mary as Mary

    John->>DB: begin_transaction()
    Note over DB: Lock acquired on source & dest accounts
@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)
@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 / 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 / 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 / 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 / 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 / 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());
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
class Shape
def initialize(color)
@color = color
end
def repr
raise 'Abstract method, to be implemented on subclasses'
end
def draw