Skip to content

Instantly share code, notes, and snippets.

@mgartner
mgartner / st_union.crdb.sql
Last active October 20, 2023 17:30
Examples in Postgres and CockroachDB showing that the st_union aggregate function does not ignore duplicates. The number of duplicate values input to the function affects the output.
-- 1 duplicate.
SELECT st_union(g) FROM (
SELECT '01060000000200000001030000000100000004000000000000000000444000000000000044400000000000003440000000000080464000000000008046400000000000003E4000000000000044400000000000004440010300000002000000060000000000000000003440000000000080414000000000000024400000000000003E40000000000000244000000000000024400000000000003E4000000000000014400000000000804640000000000000344000000000000034400000000000804140040000000000000000003E40000000000000344000000000000034400000000000002E40000000000000344000000000000039400000000000003E400000000000003440'::GEOMETRY
FROM generate_series(1, 1)
) gen(g);
-- st_union
-- ------------------------------------------------------------------------------------------------------------------------
@mgartner
mgartner / tlp_reduce.sql
Last active September 14, 2021 14:47
Example for reducing a TLP query
-- How to reduce a TLP query.
-- Below is an example where the TLP predicate is `true`.
-- Put this at the end of a failing tlp.log.
SELECT IF(
(
SELECT count(*) FROM (
-- Count all rows in the table here.
SELECT count(*) FROM t
INTERSECT
@mgartner
mgartner / results.txt
Last active May 18, 2019 00:36
Benchmark for different forms of checking list uniqueness in Elixir.
WARMUP: 8.65
WARMUP: 12.806
WARMUP: 5.377
unique_length? @ints_uniq: 7.888
unique_map? @ints_uniq: 11.046
unique_recursion? @ints_uniq: 5.157
@mgartner
mgartner / scheduled_job.rb
Last active December 14, 2015 14:38 — forked from kares/scheduled_job.rb
Recurring jobs with delayed_job_mongoid
#
# Recurring Job using Delayed::Job
#
# Setup Your job the "plain-old" DJ (perform) way, include this module
# and Your handler will re-schedule itself every time it succeeds.
#
# Sample :
#
# class MyJob
# include Delayed::ScheduledJob
@mgartner
mgartner / gist:3997978
Created November 2, 2012 01:00
Busy wait vs asynchronous callback
# I think the only way to do what you want is to use some sort of busy-wait.
# However, I think it would be better for your ModelHelper to use callbacks instead.
class ModelHelper
# Using busy-wait.
def self.find_other_thing_by_id_busy(id)
other_thing = nil
make_async_request(id) do |response|
other_thing = OtherThing.new(response)