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.

ZSH CheatSheet

This is a cheat sheet for how to perform various actions to ZSH, which can be tricky to find on the web as the syntax is not intuitive and it is generally not very well-documented.

Strings

Description Syntax
Get the length of a string ${#VARNAME}
Get a single character ${VARNAME[index]}
@roalcantara
roalcantara / 0_tldr.zsh
Last active June 5, 2025 19:32
Glob (globbing)
## TL;DR
setopt extendedglob
ls *(<tab> # to get help regarding globbing
rm ../debianpackage(.) # remove files only
ls -d *(/) # list directories only
ls /etc/*(@) # list symlinks only
ls -l *.(png|jpg|gif) # list pictures only
ls *(*) # list executables only
ls /etc/**/zsh # which directories contain 'zsh'?
@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 June 21, 2025 21:58
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 May 28, 2025 07:42
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