Skip to content

Instantly share code, notes, and snippets.

View khamusa's full-sized avatar

Samuel Brandão khamusa

  • São Paulo, Brazil
View GitHub Profile
@khamusa
khamusa / service-layer.md
Last active June 12, 2021 15:39
Service layer

In my last company we (I, mostly) made way too many design mistakes in our first attempt at implementing a GraphQL api. We wanted to make sure we'd not repeat ourselves in the next one.

One of the first things we did was to ensure every mutation used the same convention for exposing errors. We defined the following on the base mutation payload type:

module Types
  class BaseMutationPayload < Types::BaseObject
    field :errors, [String], null: false
@khamusa
khamusa / postgres_custom_enums_on_rails_schema_migrations.rb
Last active January 12, 2022 14:19
Support custom postgres enum types on rails migrations and schema.rb
# frozen_string_literal: true
# Adds migration and schema.rb support to postgres custom enum types, tested on rails 4.2
# The implementation is quite fragile against ActiveRecord version upgrades since it touches many core AR classes.
# The following code should be placed in an initializer
# On migrations:
#
# create_enum(:mood, %w(happy great been_better))
# create_table :person do
# t.enum :person_mood, enum_name: :mood
# end
@khamusa
khamusa / gc_malloc_allocations.patch
Last active April 25, 2018 18:39
Patch for compiling ruby 2.4.0 supporting MEMORY and ALLOCATIONS metrics with rails-perftest gem
commit 043ab545e23347f0c55cad1d152dd8fb2c46fa21
Author: Samuel Brandão <gb.samuel@gmail.com>
Date: Wed Apr 25 15:16:19 2018 -0300
GC calculations of allocated size
diff --git a/gc.c b/gc.c
index 847062557f..4bd2284698 100644
--- a/gc.c
+++ b/gc.c
@khamusa
khamusa / filters.js.coffee
Created June 9, 2016 21:02
Esboço de filtros para collections em js
define 'algumacoisa/filters', (), [] ->
class SomeFilteredCollectionCoordinator
initialize: ->
@filterGroups = [
new Filters.Group('has_rsvped', [
new Filters.Choice(when: false, selected: true),
new Filters.Choice(when: true)
]),
new Filters.Group('arrived_at', [
@khamusa
khamusa / estimate_remaining_time_for_index_creation_on_mongodb.js
Created January 22, 2016 11:38
In-Progress MongoDB Index Creation Remaining Time Estimation
// Quick, dirty, but useful.
// This script will estimate the rime remaining for any index building operations
// currently in course.
// You can either call it by passing a known index building operation opid to the
// estimate function or call estimateIndexOps() with no arguments, that will
// find all index building operations and estimate each one of them.
//
// Usage:
// estimateIndexOps();
// estimate(opid);