Skip to content

Instantly share code, notes, and snippets.

View wilsonsilva's full-sized avatar

Wilson Silva wilsonsilva

View GitHub Profile
@karpathy
karpathy / add_to_zshrc.sh
Created August 25, 2024 20:43
Git Commit Message AI
# -----------------------------------------------------------------------------
# AI-powered Git Commit Function
# Copy paste this gist into your ~/.bashrc or ~/.zshrc to gain the `gcm` command. It:
# 1) gets the current staged changed diff
# 2) sends them to an LLM to write the git commit message
# 3) allows you to easily accept, edit, regenerate, cancel
# But - just read and edit the code however you like
# the `llm` CLI util is awesome, can get it here: https://llm.datasette.io/en/stable/
gcm() {
class BaseClient
class APINotFound < StandardError; end
attr_reader :auth_strategy
def initialize(auth_strategy: :headers, headers: {})
@auth_strategy = auth_strategy
@headers = headers
end

Unhappy path

Before delving into how we support database (DB) transactions, let's first consider how we can handle operations that only pertain to the unhappy path. This consideration is important because, as we will see, it will become relevant when we reach the main topic.

Most of the time, the unhappy path is something managed by the caller (e.g., a controller rendering an error in case of failure). However, there are situations where it makes sense to encapsulate part of the unhappy path within the operations class. For instance, you might want to log the failure somewhere.

When relying on the vanilla #steps method, the implementation is straightforward:

class CreateUser &lt; Dry::Operation
@bizz84
bizz84 / macOS-Podfile
Last active October 5, 2023 01:42
macOS Podfile template for Flutter apps
# Set the platform at the top
platform :osx, '10.15'
# Rest of the pod file
# Update post_install step
post_install do |installer|
# Ensure pods use the minimum deployment target set above
# https://stackoverflow.com/a/64385584/436422
pods_project = installer.pods_project
module ArrayColumns
extend ActiveSupport::Concern
class_methods do
def array_columns_sanitize_list(values = [])
return [] if values.nil?
values.select(&:present?).map(&:to_s).uniq.sort
end
def array_columns(*column_names)
@eseidel
eseidel / flutter_companies.md
Last active November 13, 2023 14:28
List of companies serving Flutter developers

This is a list of companies serving Flutter developers who replied to my Twitter thread on June 14th, 2023.

This does not include companies using Flutter (there are simply too many to list!), only those offering products or services for Flutter developers.

Presence on this list is not imply any endorsement of the company or its products (other than Shorebird, of course, I endourse my own company).

@baweaver
baweaver / block_transform_ast.rb
Last active August 3, 2023 22:53
Pattern matching applied to ASTs, defining the transformation between shorthand and standard block format.
require "rubocop"
# Useful for debugging and seeing how the nodes deconstruct
def deep_deconstruct(node)
return node unless node.respond_to?(:deconstruct)
node.deconstruct.map { deep_deconstruct(_1) }
end
def block_to_shorthand?(a, b)
@zorbash
zorbash / changes.rb
Last active February 8, 2022 16:02
Fetch changelogs of updatable gems
require 'bundler'
require 'net/http'
require 'json'
require 'uri'
def fetch_gem(gem_name)
URI("https://rubygems.org/api/v1/gems/#{gem_name}.json").
then(&Net::HTTP.method(:get)).
then(&JSON.method(:parse))
rescue JSON::ParserError
# demo gameplay here: https://youtu.be/wQknjYk_-dE
# this is the core game class. the game is pretty small so this is the only class that was created
class Game
# attr_gtk is a ruby class macro (mixin) that adds the .args, .inputs, .outputs, and .state properties to a class
attr_gtk
# this is the main tick method that will be called every frame the tick method is your standard game loop.
# ie initialize game state, process input, perform simulation calculations, then render
def tick
defaults
@avosalmon
avosalmon / firebase_token.rb
Last active June 3, 2024 00:04
Verify Firebase auth JWT token
require 'base64'
require 'httparty'
require 'jwt'
class FirebaseToken
JWT_ALGORITHM = 'RS256'.freeze
PUBLIC_KEY_URL = 'https://www.googleapis.com/robot/v1/metadata/x509/[email protected]'.freeze
def initialize(token)
@token = token