Skip to content

Instantly share code, notes, and snippets.

@fabiolimace
fabiolimace / UUIDv6.sql
Last active May 12, 2024 03:47
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
@joepie91
joepie91 / .md
Last active May 7, 2024 09:12
Running a Node.js application using nvm as a systemd service

Read this first!

Hi there! Since this post was originally written, nvm has gained some new tools, and some people have suggested alternative (and potentially better) approaches for modern systems. Make sure to have a look at the comments to this article, before following this guide!


The original article

Trickier than it seems.

@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) *
@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.
#/
@datenimperator
datenimperator / Gemfile
Created September 7, 2012 18:55
Sinatra, sprockets, compass, bootstrap-sass playing together
source :rubygems
gem 'shotgun', :group=>:development
gem 'rack-cache'
gem 'sinatra', :require => 'sinatra/base'
gem 'sinatra-support'
gem 'haml'
@estum
estum / switch_on.rb
Last active August 8, 2023 05:52
Ruby alternative switch-case syntax.
# = Kernel#switch
# Provides alternative switch-case syntax.
#
# # support methods:
# value = []
# switch value do
# on empty?: -> { "none" }
# on one?: -> { "one" }
# on many?: -> { "many" }
# end
@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])
@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 |
-- +--------+-------+-------+