Skip to content

Instantly share code, notes, and snippets.

I want to do an IN query by providing a specific order from a previous query

Desired SQL Query

SELECT * 
FROM fnords
INNER JOIN   unnest('{9026, 9025, 9024, 9021, 9020, 9019}'::int[]) WITH ORDINALITY t(id, ord) USING (id)
WHERE id IN (9026, 9025, 9024, 9021, 9020, 9019)
ORDER BY t.ord;
@hukl
hukl / view.erl
Created November 1, 2019 14:04
Meta Programming in Erlang - Defining view template modules on the fly for pre-caching bbmustache templates.
-module(scio_view).
-compile(export_all).
-compile(nowarn_export_all).
load_templates() ->
Files = view_paths(),
{ok, RegExp} = re:compile("\\b(\\w+).mustache$"),
<a href="#" class="myButton">green</a>
.myButton {
background-color:#b0b0b0;
-moz-border-radius:9px;
-webkit-border-radius:9px;
border-radius:9px;
border:1px solid #e0e0e0;
display:inline-block;
cursor:pointer;
@hukl
hukl / int_set.go
Created March 14, 2017 14:01
Minimal Integer Set Implementation in Go
type int_set map[int]struct{}
func (s *int_set) Add(key int) {
(*s)[key] = struct{}{}
}
func (s *int_set) Values() []int {
var result []int
for k, _ := range *s {
result = append(result, k)
openssl rsautl -decrypt -inkey private.pem -oaep -in cryptedmessage -out decrypted
RSA operation error
11511:error:0407A079:rsa routines:RSA_padding_check_PKCS1_OAEP:oaep decoding error:/BuildRoot/Library/Caches/com.apple.xbs/Sources/OpenSSL098/OpenSSL098-64.30.2/src/crypto/rsa/rsa_oaep.c:199:
11511:error:04065072:rsa routines:RSA_EAY_PRIVATE_DECRYPT:padding check failed:/BuildRoot/Library/Caches/com.apple.xbs/Sources/OpenSSL098/OpenSSL098-64.30.2/src/crypto/rsa/rsa_eay.c:614:
@hukl
hukl / truth_example.erl
Last active December 10, 2015 11:13
Blog post example for truth table in erlang
% Day 14 and after last match of season: 100
% State Resetted: 010
% Finished processing StateLevel > MaxLevel: 001
% Flag | Current | Is State | Finished | Meaning
% | Season Over? | Reset? | Processing? |
% -----|--------------|----------|-------------|------------------------------------------
% 100 | 1 | 0 | 0 | resume progress current season
% 101 | 1 | 0 | 1 | noop day 14
% 110 | 1 | 1 | 0 | start progression
@hukl
hukl / truth_example.rb
Last active December 16, 2015 13:06
Blog post example for truth tables
# defining some constants
ARCHIVE_REQUESTED = 1 # binary 01
ARCHIVE_NOT_REQUESTED = 0 # binary 00
FINISHED_PROCESSING = 2 # binary 10
NOT_FINISHED_PROCESSING = 0 # binary 00
NOOP = 0 # binary 00
START = 1 # binary 01
BROKEN = 2 # binary 10
-module().
-behavior(gen_server).
% Managment API
-export([start/0, start_link/0, stop/0]).
% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
code_change/3]).
@hukl
hukl / gist:40c12883cf25d5d8a1ed
Created November 27, 2014 12:59
FreeBSD.conf
FreeBSD: {
url: "pkg+http://pkg.eu.FreeBSD.org/${ABI}/latest",
mirror_type: "srv",
enabled: yes
}
@hukl
hukl / ruby.sh
Created May 9, 2014 21:05
example rc script
#!/bin/sh
# PROVIDE: request_counter
# REQUIRE: LOGIN
# KEYWORD: shutdown
. /etc/rc.subr
name=request_counter
rcvar=request_counter_enable