Skip to content

Instantly share code, notes, and snippets.

View oddlyfunctional's full-sized avatar

Marcos Felipe Pimenta Rodrigues oddlyfunctional

View GitHub Profile
class Building
attr_reader :address
def initialize(rooms, address, width, length)
@rooms = rooms
@address = address
@width = width
@length = length
end
@oddlyfunctional
oddlyfunctional / interface.rb
Created July 10, 2017 14:23
Christmas list
require 'open-uri'
require 'nokogiri'
def list_gifts(gifts_list)
gifts_list.each_with_index do |gift, index|
name = gift["name"]
bought = gift["bought"]
if bought
status = "[x]"
@oddlyfunctional
oddlyfunctional / interface.rb
Created July 11, 2017 14:19
Modeling data with associations
require_relative "patients_repository"
require_relative "rooms_repository"
require_relative "room"
require 'csv'
rooms_repository = RoomsRepository.new("rooms.csv")
patient_repository = PatientsRepository.new("patients.csv", rooms_repository)
room = Room.new(capacity: 10)
rooms_repository.add(room)
require 'csv'
require_relative '../models/customer'
class CustomerRepository
def initialize(csv_path)
@csv_path = csv_path
@customers = []
load_csv if File.exist?(@csv_path)
@next_id = @customers.empty? ? 1 : @customers.last.id + 1
end
$(document).ready(function() {
$("#images").on('click', ".image", function(event) {
$(this).toggleClass('img-circle');
});
$("#add").on("click", function geraImagem(event) {
event.preventDefault();
var id = Math.floor(Math.random() * 11);
var url = "http://lorempixel.com/160/160/city/" + id;
def calculate(first, second, operator)
if operator == "+"
result = first + second
elsif operator == "-"
result = first - second
elsif operator == "*"
result = first * second
elsif operator == "/"
result = first / second
end
carteira = 100
custo_da_aposta = 10
valor_do_premio = 50
while carteira >= custo_da_aposta
carteira = carteira - custo_da_aposta
# 1) Imprimir "Bem-vindo ao jockey, faça sua aposta!"
puts "Bem-vindo ao jockey, faça sua aposta!"
@oddlyfunctional
oddlyfunctional / index.js
Created January 23, 2019 10:06
Force error, skipping cleanup
try {
throw 'some error';
await db.destroy();
} catch (error) {
// ...
}
@oddlyfunctional
oddlyfunctional / graphql-clients-benchmark.md
Last active May 26, 2021 04:57
Comparison between GraphQL clients

Client-side GraphQL

graphql_ppx

Let's first analyze how to write the queries. I experimented the graphql_ppx with a few different features (nullable and non-nullable variables, fragments, convert response into record automatically). The type safety is very neat, both the input variables and the response have specific types (no Js.Json.t!), and the queries/mutations are validated against the schema! This makes it really easy to write queries, although I worry about integrating new versions of the schema since the repos are separated (we should probably re-fetch the schema as part of the CI).

As for the drawbacks, there are not many:

  • The ppx really messes up my language server sometimes.
  • I haven't tried a lot but I couldn't find easily a way to use refmt to format the queries.
  • I couldn't find anything about custom directives, the lack of which would prevents us from using some features from the GraphQL clients (for example, managing local state using Apollo's @client directive).
  • I haven't
open Task;
type task('a) = Task.t('a);
type issuer;
type nameId;
type email;
type user;
type validatedUser = ValidatedUser(user);
type unvalidatedUser;