Skip to content

Instantly share code, notes, and snippets.

@estum
estum / mat_module_eval.rb
Last active December 15, 2022 12:12
Materialize macro-defined method sources for documentation (ruby)
# The refinement module helps to inspect a composed source of meta-generated methods,
# which were defined via Module#module_eval or Module#class_eval methods
# in strings with interpolations.
#
# Unless this refinement is using, looking up for an actual source of such
# kind of method will result with a raw string literal with no interpolation applied.
#
# It's monkey patch the Module#module_eval and Module#class_eval methods to
# write a source with applied interpolation into a temporary file per method owner and
# substitutes an evaluted located path & lineno for the string.
@estum
estum / predicate_builder_array_fix.rb
Created October 10, 2020 13:09
Fix the array handling on ActiveRecord's prepared statements
# frozen_string_literal: true
# Before (creates prepared statement for each varying size of given array):
#
# $ Post.where(id: [uuid1, uuid2])
# => Post Load (0.6ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" IN ($1, $2) [["id", "a830f21d-a27b-4bde-8c05-6e5dd088712e"], ["id","531ee026-d60d-4a59-a9a5-d44c44578a98}"]]
#
# After (the only one statement for varying size of given array):
#
# $ Post.where(id: [uuid1, uuid2])
@fabiolimace
fabiolimace / UUIDv6.sql
Last active April 30, 2024 06:04
Functions for generating UUIDv6 and UUIDv7 on PostgreSQL
/*
* MIT License
*
* Copyright (c) 2023-2024 Fabio Lima
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@estum
estum / recursive_shift_rows_with_modifier.sql
Last active June 5, 2020 20:13
PostgreSQL: recursively shift rows in order using modifier
-- +--------+-------+-------+
-- | init | mod | exp |
-- |--------+-------+-------|
-- | 6 | -1 | 5 |
-- | 5 | 0 | 4 |
-- | 4 | 1 | 6 |
-- | 3 | 0 | 3 |
-- | 2 | -1 | 1 |
-- | 1 | 0 | 2 |
-- +--------+-------+-------+
@koshatul
koshatul / README.md
Last active April 29, 2024 17:13
use Apple Keychain to store GPG Passphrases

gpg-agent setup

Need to setup gpg-agent first, on OSX I use keychain (it also does ssh-agent)

$ brew info keychain
keychain: stable 2.8.5
User-friendly front-end to ssh-agent(1)
https://www.funtoo.org/Keychain
/usr/local/Cellar/keychain/2.8.5 (7 files, 108.5KB) *
@estum
estum / yieldable.rb
Created July 27, 2017 08:10
yieldable.rb: Memoized #to_proc for any callable object to use as a block argument with the "&" operator.
# This module can be used to easy make callable object or class
# to be used as a block argument with the <tt>&</tt> operator. It just
# implements the +to_proc+ method.
#
# == Examples:
#
# class Foo
# extend Yieldable
#
# def self.call(key, value)
@estum
estum / itunes-current_track-toggle_loved.applescript
Created May 26, 2017 13:51
iTunes: Toggle loved of the current track
on run {input, parameters}
tell application "iTunes"
set theTrack to get current track
if theTrack's loved then
set loved of theTrack to false
display notification "Now is not loved" with title ¬
"iTunes" subtitle theTrack's artist & " - " & theTrack's name ¬
sound name "Tink"
else
set loved of theTrack to true
@estum
estum / itunes-current_track-toggle_disliked.applescript
Last active May 26, 2017 13:52
iTunes: Toggle disliked of the current track
on run {input, parameters}
tell application "iTunes"
set theTrack to get current track
if theTrack's disliked then
set disliked of theTrack to false
display notification "Now is not disliked" with title ¬
"iTunes" subtitle theTrack's artist & " - " & theTrack's name ¬
sound name "Tink"
else
next track
@phansch
phansch / yardoc_cheatsheet.md
Last active March 1, 2024 18:17 — forked from chetan/yardoc_cheatsheet.md
Improved YARD cheatsheet
@estum
estum / app-env
Last active February 13, 2024 14:33
Simple dotenv wrapper on Bash (replace dotenv gem).
#!/usr/bin/env bash
#
#/ Usage: app-env [[-e <DOTENV_FILE>]... ] [[-s <SOURCE_FILE>]... ] [--] <command> [<args>...]
#/ app-env [-h|--help]
#/
#/ Executes a given command with environment variables loaded from dotenv files.
#/ Dotenv files are executed in current shell context, wrapped with `set -e'.
#/ Source files, which are set with the `-s' flag will be included after `set +e'
#/ It is possible to provide several files, just by using flags as many tymes as you need.
#/