Skip to content

Instantly share code, notes, and snippets.

View emanuelhfarias's full-sized avatar

Emanuel H. Farias emanuelhfarias

View GitHub Profile
Mix.install(
[
{:phoenix_playground, "~> 0.1.0"},
{:openai, "~> 0.6.1"}
],
config: [
openai: [
api_key: System.get_env("OPENAI_API_KEY"),
organization_key: System.get_env("OPENAI_ORGANIZATION_KEY")
]
@serradura
serradura / nano_case.rb
Last active March 30, 2023 12:36
NanoCase: Abstraction inspired by the u-case gem (compatible with old and new Rubies)
class NanoCase
class Result
UNDEFINED = :undefined
attr_reader :type, :data
def initialize(type, data)
@type = type
@data = data
end
@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
@serradura
serradura / 01_factory_collection_filter.rb
Created February 23, 2023 17:22
Abstractions to filter an array of hashes in Ruby
class FactoryCollectionFilter
def initialize(config)
@config = config || {}
end
def call(filters: {}, data: [])
return data if filters.empty?
filters.reduce(data) do |filtered, (filter, value)|
filter_fn = @config[filter]
@andynu
andynu / show_method_history.rb
Created August 26, 2022 18:56
Given a ruby file and method name shows you all the different versions across the git history.
#!/usr/bin/env ruby
# Given a file and method_name
# Show all the different implementations across the git history (first commit per implementation).
#
# show_method_history <file> <method_name> --html
#
# e.g. show_method_history test/test_helper.rb sign_in --html
#
# WARNING: the --html output just dumps html files into your current folder.
#
@natematykiewicz
natematykiewicz / unroutable_routes.rake
Last active June 9, 2022 19:47
Find routes that will raise a routing error when requested
desc 'Find routes that will raise a routing error when requested'
task unroutable_routes: :environment do
# A lot of this code was taken from how `rake routes` works
# https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/railties/lib/rails/commands/routes/routes_command.rb
require 'action_dispatch/routing/inspector'
unroutables = Rails.application.routes.routes.
map { |r| ActionDispatch::Routing::RouteWrapper.new(r) }.
reject { |r| r.internal? || r.engine? || r.path.starts_with?('/rails/') || !r.controller }.
@v-kolesnikov
v-kolesnikov / app.rb
Created May 23, 2020 09:08
Single file Rails app
# frozen_string_literal: true
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'rails', '~> 6.0'
end
require 'action_controller/railtie'
@rmcdongit
rmcdongit / macOS_SytemPrefs.md
Last active March 3, 2025 05:38
Apple System Preferences URL Schemes

macOS 10.15 System Preference Panes

Below are a list of System Preference pane URLs and paths that can be accessed with scripting to assist users with enabling macOS security settings without having to walk them through launching System Preferences, finding panes, and scrolling to settings. Not all panes have an accessible anchor and some are OS specific.

To find the Pane ID of a specific pane, open the System Preferences app and select the desired Preference Pane. With the pane selected, open the ScriptEditor.app and run the following script to copy the current Pane ID to your clipboard and display any available anchors:

tell application "System Preferences"
	set CurrentPane to the id of the current pane
	set the clipboard to CurrentPane
@leastbad
leastbad / action_mailbox.md
Last active January 22, 2025 23:39
Action Mailbox: The Missing Manual

This is all you really need to know in order to make Action Mailbox work in development.

  1. Fire up ngrok http 3000 and make note of your subdomain for steps 3 and 8.
  2. Create a Mailgun account because they offer sandbox addresses; grab your domain from the Dashboard.
  3. Go into Receiving and create a catch-all route pointing to: https://XXX.ngrok.io/rails/action_mailbox/mailgun/inbound_emails/mime
  4. Add your Mailgun API key to your credentials:
action_mailbox:
 mailgun_api_key: API KEY HERE