Skip to content

Instantly share code, notes, and snippets.

View oboxodo's full-sized avatar

Diego Algorta oboxodo

View GitHub Profile

Avoid has_many/one + belongs_to circular dependency

This is based on the use of Shopify's packwerk.

Asuming we have a posting pack with a Post model and a commenting pack with a Comment model, and we want the commenting pack to have a declared dependency on the posting pack, then here's a pattern to avoid the has_many :comments usual declaration on the Post model while still being able to have very similar functionality to the dependent option to react/restrict when a post is destroyed.

If you need to fetch a post's comments, you can simply use Comments.where(post: @post) instead of the

@oboxodo
oboxodo / main.rb
Last active January 23, 2023 00:13 — forked from coorasse/main.rb
CanCanCan Issue
# This file serves the purpose of starting a discussion on CanCanCan to try and
# avoid instantiating in memory a lot of uneeded objects when calling `can?`.
# I think in many cases it should be possible to leverage `accessible_by` to
# resolve the ability using an optimized SQL query instead.
# This file started life as a copy of https://gist.github.com/coorasse/3f00f536563249125a37e15a1652648c
begin
require 'bundler/inline'
rescue LoadError => e
@oboxodo
oboxodo / tail-of-trace.log
Last active November 14, 2022 22:10
Debugging to get help from Heroku's Terraform provider on a plan. Nothing secret in this log. (https://github.com/heroku/terraform-provider-heroku/issues/350)
2022-11-14T18:07:42.268-0300 [TRACE] vertex "provider[\"registry.terraform.io/heroku/heroku\"]": visit complete
2022-11-14T18:07:42.268-0300 [TRACE] vertex "heroku_config.production (expand)": starting visit (*terraform.nodeExpandApplyableResource)
2022-11-14T18:07:42.268-0300 [TRACE] vertex "heroku_config.production (expand)": expanding dynamic subgraph
2022-11-14T18:07:42.268-0300 [TRACE] vertex "heroku_config.production (expand)": entering dynamic subgraph
2022-11-14T18:07:42.268-0300 [TRACE] vertex "heroku_config.production": starting visit (*terraform.NodeApplyableResource)
2022-11-14T18:07:42.268-0300 [TRACE] vertex "heroku_config.production": visit complete
2022-11-14T18:07:42.268-0300 [TRACE] vertex "heroku_config.production (expand)": dynamic subgraph completed successfully
2022-11-14T18:07:42.268-0300 [TRACE] vertex "heroku_config.production (expand)": visit complete
2022-11-14T18:07:42.268-0300 [TRACE] vertex "heroku_config.production": starting visit (*terraform.NodeApplyableResourceInstance)
2022
@oboxodo
oboxodo / crawl_for_nfts_from_validated_creator.ts
Created March 30, 2022 01:21
Transaction crawling for a list of mints from a given verified creator
// This is alpha code trying to replace a getProgramAccounts call with a Transaction Crawling algorithm to find all mints from a Metaplex Candy Machine.
// DISCLAIMER: Use at your own risk.
//
// This code was originally based on the code from @samuelvanderwaal in https://github.com/metaplex-foundation/get-collection/blob/39116b680301c23c91e3960578c4a37c1c8e07c3/get-collection-ts/index.ts
// The purpose of that code is different, but I learnt a lot from it.
//
// Also got some inspiration from @0xAlice's code in https://github.com/penta-fun/sol-nft-tools/blob/8931ae422fa47b79008d57b01a30aeefd97b8cb6/util/get-nft-mints.ts
import { ConfirmedSignatureInfo, Connection, PublicKey } from "@solana/web3.js";
import { programs } from "@metaplex/js";
@oboxodo
oboxodo / change_apple_keyboard_to_pc_muscle.sh
Created December 13, 2021 14:47
Change Apple Keyboard layout to work as a PC keyboard
#!/bin/sh
# https://github.com/torvalds/linux/blob/2585cf9dfaaddf00b069673f27bb3f8530e2039c/drivers/hid/hid-apple.c#L38-L58
# https://blog.desdelinux.net/en/apple-keyboard-work-properly-ubuntu/
# fnmode
# Mode of fn key on Apple keyboards
# 0 = disabled, [1] = fkeyslast, 2 = fkeysfirst
echo 2 > /sys/module/hid_apple/parameters/fnmode
@oboxodo
oboxodo / MetaplexDisplay.md
Created October 17, 2021 03:54
Steps for Metaplex NFT Display

So you want to display a Metaplex NFT

This guide will attempt to give an overview of the technical/coding steps that are required to render a Metaplex NFT with any programming language/platform. I'll attempt to write it a programming language-agnostic manner; you'll need to fill in the particular methods of performing the steps with your coding language of choice.

For the purposes of discussion, we'll call the Solana account that holds the Metaplex NFTs the "NFT-Account."

Step 1: Call getTokenAccountsByOwner

The first thing you need to do is call the getTokenAccountsByOwner JSON RPC method as documented here:

@oboxodo
oboxodo / README.md
Last active August 29, 2019 19:16
Solano CI hook scripts for CodeClimate's coverage test-reporter supporting parallel builds

This is an example for running Code Climate Test Reporter in Solano CI (ex-TDDIUM).

This example is particular for SimpleCov and Amazon's AWS but it should still be a good template for other coverage tools and cloud storage providers.

For these scripts to work you'll need to set 3 ENV vars in Solano CI:

  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • CC_TEST_REPORTER_ID
-- Trying to get similar info that can be get from https://rollbar.com/quimbee/quimbee/versions/
-- but based on a custom attribute instead of the `code_version`.
-- Still not there.
SELECT body.trace.extra.code_version_release_iteration, max(timestamp), count_distinct(item.counter), count(*)
FROM item_occurrence
WHERE item.environment = "production"
AND item.level >= 30
GROUP BY 1
ORDER BY 2 DESC
LIMIT 20
@oboxodo
oboxodo / brite_verify.rb
Last active January 17, 2019 17:12
BriteVerify simple email validation client supporting configurable timeouts
class BriteVerify
require "json"
require "faraday"
URL = "https://bpi.briteverify.com"
PATH = "/emails.json"
DEFAULT_TIMEOUT = 1.freeze
class Error < StandardError; end
@oboxodo
oboxodo / cursor-based-pagination-mvp.patch
Created January 28, 2017 19:03
MVP for adding cursor based pagination to an scaffolded Rails blog
commit 3babf31134cafb211041202d19fa6f5a9359aed1
Author: Diego Algorta <diego@oboxodo.com>
Date: Sat Jan 28 15:59:06 2017 -0300
Add cursor based pagination
diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb
index 16bba99..a921aff 100644
--- a/app/controllers/posts_controller.rb
+++ b/app/controllers/posts_controller.rb