Skip to content

Instantly share code, notes, and snippets.

### Keybase proof
I hereby claim:
* I am zyclotrop-j on github.
* I am zyclotrop (https://keybase.io/zyclotrop) on keybase.
* I have a public key ASAkllhs7vILmYio6WAfl6tXemFysGVS5I7AsIPFJrKy3Qo
To claim this, I am signing this object:
@Zyclotrop-j
Zyclotrop-j / Relay Cursor Spec Pagination in SQL
Created October 8, 2021 04:41
Relay Cursor Spec Pagination in SQL
-- --------------------- CREATE TABLE -------------------
-- Table: public.pagination
CREATE TABLE IF NOT EXISTS public.pagination
(
uuid uuid NOT NULL DEFAULT gen_random_uuid(),
ts timestamp without time zone NOT NULL DEFAULT now(),
-- any columns
data jsonb NOT NULL,
@Zyclotrop-j
Zyclotrop-j / After + First
Created October 8, 2021 04:48
Relay Cursor Spec Pagination in MongoDB
// see https://mongoplayground.net/p/hrVd5xrWBbh
db.collection.aggregate([
{
$match: {
...preconditions...
}
},
{
$sort: {
_id: 1
class EventTarget {
constructor(options) {
if(options) {
Object.assign(this, options);
}
this.listeners = {};
}
addEventListener (type, callback, useCaptureOptions) {
if (!(type in this.listeners)) {
@Zyclotrop-j
Zyclotrop-j / cloud-init-with-ufw-and-nodejs
Last active July 17, 2022 05:17
Cloud init config - adds basic security defaults to the instance (ssh-key, no-root login, ufw) and adds some basic package. Replace <USERNAME> (twice!) and <PUBLIC SSH KEY>
#cloud-config
users:
- name: <USERNAME>
ssh-authorized-keys:
- ssh-rsa <PUBLIC SSH KEY>
sudo: ['ALL=(ALL) NOPASSWD:ALL']
groups: sudo
shell: /bin/bash
package_update: true
package_upgrade: true
@Zyclotrop-j
Zyclotrop-j / Advent of Code
Last active December 6, 2022 05:27
Advent of Code
// Day 1 - Part 1
Math.max(...document.body.innerText.split("\n\n").map(i => i.split("\n").filter(i=>i.trim()).reduce((p, q) => p + parseInt(q), 0)))
// Day 1 - Part 2
document.body.innerText.split("\n\n").map(i => i.split("\n").filter(i=>i.trim()).reduce((p, q) => p + parseInt(q), 0)).sort((a,b) => a-b).slice(-3).reduce((a, b)=>a+b, 0)
// Day 2 - Part 1
pmap = {X: 1, Y: 2, Z: 3}
wmap={'A X': 3, 'B Y': 3, 'C Z': 3, 'A Y': 6, 'A Z': 0, 'B Z': 6, 'B X': 0, 'C X': 6, 'C Y': 0}
document.body.innerText.split('\n').filter(i => i.trim()).map(i => wmap[i.trim()] + pmap[i.trim()[i.trim().length - 1]]).reduce((p, i) => p+i, 0)
// Day 2 - Part 2
wmap2={'A X': 'Z', 'B X': 'X', 'C X': 'Y', 'B Y': 'Y', 'A Y': 'X', 'C Y': 'Z', 'C Z': 'X', 'B Z': 'Z', 'A Z': 'Y'}
@Zyclotrop-j
Zyclotrop-j / day7.ex
Created December 7, 2022 09:19
advent of code 2022, day 7
defmodule Day7 do
@maxsize 100000
@total 70000000
@needspace 30000000
@moduledoc """
Documentation for `Day7`.
"""
@doc """
/* A DECORATOR TO NOTIFY ABOUT UNUSUALLY LONG ASYNC CALLS */
/* Let your user and your error-reporting know when a network call takes unusually long */
// HOW TO USE:
/*
const makeCall = observe(.... my function to make an async call, e.g. network....., opts, takes longer, takes much longer, takes way too long)
// example: const observedFetch = observe(fetch, {id: 'my-api-calls'}, () => console.log('This is taking a little longer than usual'), () => console.log('This is taking a longer than usual'), () => console.log('This is taking a much longer than usual'));
// Then proceed as usual
makeCall(....); // or observedFetch('https://example.com').then(i => i.text()).then(i => console.log(i));
// for the "takes longer" callbacks, you can react how you want, e.g., you could hook a notification system in!