Skip to content

Instantly share code, notes, and snippets.

View juuh42dias's full-sized avatar
👩‍💻
working from (coworking || café)

Juliana Dias juuh42dias

👩‍💻
working from (coworking || café)
View GitHub Profile
@andersondias
andersondias / calculate_shipping_cost.rb
Created April 23, 2025 20:31
Sample code using the Operation + Result pattern
class CalculateShippingCost < Operation
def initialize(order)
@order = order
end
def perform
validation_result = validate_address
return validation_result if validation_result.failure?
calculate_shipping_cost
@leandronsp
leandronsp / README.md
Created November 20, 2024 19:57
Reverse Polish Notation (RPN) in Assembly x86_64

RPN in ASM x86_64

nasm -f elf64 -g rpn.asm -o rpn.o
ld rpn.o -o rpn
./rpn

Output

@VictorTaelin
VictorTaelin / HVML.c
Last active November 9, 2024 20:55
$10k bounty - make HVML.c 50% faster on Apple M3
// Post: https://x.com/VictorTaelin/status/1854326873590792276
// Note: The atomics must be kept.
// Note: This will segfault on non-Apple devices due to upfront mallocs.
#include <stdint.h>
#include <stdatomic.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
@mauricioabreu
mauricioabreu / invert_binary_tree.py
Last active November 3, 2023 18:14
Invert binary tree
class Node:
def __init__(self, value, left=None, right=None):
self.value = value
self.left = left
self.right = right
def invert_binary_tree(root):
if root:
stack = [root]
@leandronsp
leandronsp / background_job_test.go
Created August 5, 2023 02:15
A dead simple background processor in Go, using a double-ended queue based on a doubly linked list
// go mod init queues
// go mod tidy
// go get github.com/stretchr/testify/assert
// go mod tidy
// go test background_job_test.go
package queues
import (
"fmt"
@leandro
leandro / versatile_methods.rb
Created April 13, 2023 00:23
A different approach, compared to using `Module#module_function`
# The idea here is to make all the methods below accessible through the module
# itself and through the classes including the module, but having the methods
# publicly available both as instance and as class methods.
module A
def self.abc = 123
def self.xyz = 456
def self.append_features(klass)
methods_being_added = singleton_methods - [:append_features]
delegation_setter = ->(mod, methods) { delegate *methods, to: mod }
@leandro
leandro / lib__graphql__utils.rb
Created April 5, 2023 13:28
Retrieving the queried fields from a GraphQL operation request (when using `graphql-ruby` gem)
module Graphql
class Utils
CONTEXT_CLASS = GraphQL::Query::Context
FIELD_CLASS = GraphQL::Language::Nodes::Field
FRAGMENT_CLASS = GraphQL::Language::Nodes::FragmentSpread
# Given a GraphQL context (literally, the +context+ method from inside any GraphQL field
# method), this method will return all the fields requested in the operation request.
# So, considering the following query example:
#
@kddnewton
kddnewton / json.rb
Last active August 7, 2023 19:54
Faster JSON parser in Ruby
# frozen_string_literal: true
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "json_pure"
gem "benchmark-ips"
end
@frankyston
frankyston / app.rb
Last active October 4, 2022 09:56
Apurar os resultado da eleições de 2022 para Presidente
require 'net/http'
require 'json'
require 'cgi'
def delimiter(number)
number.reverse.scan(/.{1,3}/).join(',').reverse
end
while (true) do
uri = URI('https://resultados.tse.jus.br/oficial/ele2022/544/dados-simplificados/br/br-c0001-e000544-r.json')
@serradura
serradura / mecha_basic.rb
Last active July 31, 2022 11:57
mecha.rb - a minimalist finite state machine implemented using Ruby 3.1 (basic = 34 LOC, enhanced = 53 LOC)
class Mecha
private attr_accessor(:states_map, :callbacks, :transitions, :current_state)
public :transitions, :current_state
def initialize(initial_state:, transitions:)
self.states_map = transitions.parameters.select { |(type, _)| type == :keyreq }.to_h { [_2, _2] }
self.callbacks = Hash.new { |hash, key| hash[key] = [] }
self.transitions = transitions.call(**states_map).transform_values(&:freeze).freeze