Skip to content

Instantly share code, notes, and snippets.

@joehenry087
joehenry087 / gist:275dc7525ecfe29df78641eec659cb3d
Created September 4, 2021 16:35
Creating pretty, concise and unique base 62 ids
// Not sure where I found this approach. Probably a combination of multiple kind people's advices.
// Basically we make a random number or something and encode it as 62 bit, for concise URL ids.
// I don't recall how uniqueness is guaranteed but I think its because we are basing the ID off the timestamp. You could also add a unique constraint on your DB column of course.
CREATE sequence global_id_sequence MINVALUE 0 MAXVALUE 1023 START 0 CYCLE;
CREATE OR REPLACE FUNCTION generate_number(OUT number_id bigint) AS $$
DECLARE
shard_id int := 1;
start_epoch bigint := 1498490095287;
@Tech-TX
Tech-TX / design_details.txt
Created December 11, 2020 01:06
Development code for PMS5003, BME280 and TFT LCD for a dirt cheap particle counter
Objective of the design: use inexpensive components to produce a cleanroom-style particle counter that can be run semi-continuously, monitored from outside the cleanroom.
The 攀藤 (PlanTower) PMS5003 (fifth generation) or PMS7003 (seventh generation) dust sensor costs $15 to $22 on eBay from Shenzhen suppliers. It samples 0.1 liter and calculates dust particles in > 0.3um, 0.5um, 1um, 2.5um, 5um and 10um bins. In order to get a useful reading in a cleanroom, we need to add the results from 100 samples (10 liters of air) or the counts are too small to be reliable. ISO 14644-1:1999 specifies counts in 1 cubic metre of air, which would require 10,000 samples from this small sensor. 100 samples takes roughly 300 seconds to process, so sampling 1 m3 would take 500 minutes (8.3 hours). As this device is not intended to be a NIST-traceable particle counter, sampling at 1% should give a reasonable estimate of the cleanroom quality. Note that the two smallest particle bins have up to 50% uncertainty; the larger
@superseb
superseb / k3s-etcd-commands.md
Last active November 2, 2024 14:56
k3s etcd commands

k3s etcd commands

etcd

Setup etcdctl using the instructions at https://github.com/etcd-io/etcd/releases/tag/v3.4.13 (changed path to /usr/local/bin):

Note: if you want to match th etcdctl binaries with the embedded k3s etcd version, please run the curl command for getting the version first and adjust ETCD_VER below accordingly:

curl -L --cacert /var/lib/rancher/k3s/server/tls/etcd/server-ca.crt --cert /var/lib/rancher/k3s/server/tls/etcd/server-client.crt --key /var/lib/rancher/k3s/server/tls/etcd/server-client.key https://127.0.0.1:2379/version
@unixfox
unixfox / jool.conf
Last active June 5, 2023 14:29
IPv6 only NAT64 (Jool) with RA (radvd) + DNS64 (bind9)
{
"comment": "Sample configuration for the NAT64 Jool service.",
"instance": "default",
"framework": "netfilter",
"global": {
"comment": "Sample pool6 prefix",
"pool6": "64:ff9b::/96"
}
#!/usr/bin/env python3.6
import requests
import json
import re
from datetime import datetime
from datetime import timedelta
def token():
headers = {
'Accept': 'application/json',
@haproxytechblog
haproxytechblog / blog20181017-01.map
Last active August 21, 2023 15:42
Introduction to HAProxy Maps
# A comment begins with a hash sign
static.example.com be_static
www.example.com be_static
# You can add additional comments, but they must be on a new line
example.com be_static
api.example.com be_api
@amitripshtos
amitripshtos / alternative-scheduler-for-celery.py
Created August 22, 2018 09:53
Alternative to celery beat for people who got burned hard
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.executors.pool import ThreadPoolExecutor
from apscheduler.jobstores.memory import MemoryJobStore
from apscheduler.job import Job
import json
import logging
from apscheduler.triggers.cron import CronTrigger
import time
from celery import Celery
from typing import List
@ibraheem4
ibraheem4 / postgres-brew.md
Last active October 14, 2024 11:59 — forked from sgnl/postgres-brew.md
Installing Postgres via Brew (OSX)

Installing Postgres via Brew

Pre-Reqs

Brew Package Manager

In your command-line run the following commands:

  1. brew doctor
  2. brew update
@001101
001101 / accounting.sql
Created February 18, 2017 09:08 — forked from NYKevin/accounting.sql
Basic double-entry bookkeeping system, for PostgreSQL.
CREATE TABLE accounts(
id serial PRIMARY KEY,
name VARCHAR(256) NOT NULL
);
CREATE TABLE entries(
id serial PRIMARY KEY,
description VARCHAR(1024) NOT NULL,
amount NUMERIC(20, 2) NOT NULL CHECK (amount > 0.0),
-- Every entry is a credit to one account...
@mpneuried
mpneuried / Makefile
Last active August 22, 2024 10:36
Simple Makefile to build, run, tag and publish a docker containier to AWS-ECR
# import config.
# You can change the default config with `make cnf="config_special.env" build`
cnf ?= config.env
include $(cnf)
export $(shell sed 's/=.*//' $(cnf))
# import deploy config
# You can change the default deploy config with `make cnf="deploy_special.env" release`
dpl ?= deploy.env
include $(dpl)