Skip to content

Instantly share code, notes, and snippets.

View requaos's full-sized avatar
🍱
<-- code

Neil requaos

🍱
<-- code
View GitHub Profile
@requaos
requaos / dock.sh
Created November 29, 2023 20:43
local script to set laptop display gamma and brightness and also position docked displays (autorandr is reported to be better, but I have not looked for where it stores it's saved profiles)
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p bash xorg.xrandr brightnessctl
CONNECTED_DISPLAYS="$(xrandr | grep "\sconnected" | awk '{ print $1 }')"
DOCK_LEFT="DVI-I-2-2"
DLF="0"
DOCK_CENTER="HDMI-0"
DCF="0"
DOCK_RIGHT="DVI-I-1-1"
DRF="0"
@requaos
requaos / xps_9320.nix
Created October 3, 2023 15:16 — forked from notgne2/xps_9320.nix
It Just Works ™️
{
config,
pkgs,
lib,
inputs,
...
}: let
ipu6-camera-bin = with pkgs;
stdenv.mkDerivation rec {
pname = "ipu6-camera-bin";
@requaos
requaos / ascii_art.py
Created June 3, 2022 19:04
codeacademy python ascii art thing
# Neil Skinner
# I like brains
initials = {
'N': [17, 25, 21, 19, 17, 17, 17],
'S': [14, 17, 16, 14, 1, 17, 14],
}
def zipped_map(things):
l = []

Keybase proof

I hereby claim:

  • I am requaos on github.
  • I am requaos (https://keybase.io/requaos) on keybase.
  • I have a public key ASCpdfI1zctm92moE2Culbg68Teg7bMacSDu7Tip8wjjtAo

To claim this, I am signing this object:

START TRANSACTION;
create function tallreach_rank(time_threshold integer, time_posted timestamp with time zone, up_votes integer, down_votes integer) returns numeric
immutable
language plpgsql
as
$$
DECLARE
start_time TIMESTAMP WITH TIME ZONE;
Ts INT;
-- From: https://stackoverflow.com/questions/8871426/how-to-calculate-an-exponential-moving-average-on-postgres
start transaction;
create or replace function ema_func(state numeric, inval numeric, alpha numeric)
returns numeric
language plpgsql as $$
begin
return case
when state is null then inval
else alpha * inval + (1-alpha) * state
-- Forwarning: This function is not optimized, so please leave a coment if you see something that I didn't
start transaction;
create or replace function rsi_func(state circle, inval numeric)
returns circle
language plpgsql as $$
begin
return case
when state is null then (select circle(point(sum(CASE WHEN t.gains >= 0 THEN t.gains ELSE 0 END)/14,(abs(sum(CASE WHEN t.gains < 0 THEN t.gains ELSE 0 END))/14)), inval) rs from (select price - lag(price, 1) over (rows between 14 preceding and current row) gains from quotes where type = 'last') as t)
else circle(point(((select g[0] from point(state) as g) * 13 + (CASE WHEN inval - radius(state) >= 0 THEN inval - radius(state) ELSE 0 END))/14,((select l[1] from point(state) as l) * 13 + (CASE WHEN inval - radius(state) < 0 THEN inval - radius(state) ELSE 0 END))/14), inval)
@requaos
requaos / postgresUniqueConstraintErrorHandlingWithSQLBoiler.go
Created April 10, 2019 20:47
When using SQLBoiler with Postgres DB, you will eventually need to react to unique constraint violations in a constructive manner:
logger := zap.NewNOP()
err = pilot.Insert(ctx, m.DB.Master(), boil.Infer())
switch err := errors.Cause(err).(type) {
case nil:
// Carry on
case *pq.Error:
if err.Code.Name() == "unique_violation" && err.Constraint == "unique_constraint_name" {
// Do something
return nil
START TRANSACTION;
ALTER TABLE public.stories
ADD COLUMN text_search tsvector;
UPDATE public.stories SET text_search =
setweight(to_tsvector(author), 'A') ||
setweight(to_tsvector(title), 'A') ||
setweight(to_tsvector(description), 'B');
@requaos
requaos / relativePathsUpdate.sql
Created March 12, 2019 21:36
Fix relative image paths from crappy rss feeds, after the fact.
DO $$
declare
urlprefix text;
thing RECORD;
BEGIN
FOR thing in (SELECT * from stories where image like '/%') LOOP
urlprefix = substring(thing.url, '^.+?\/\/.+?\/');
UPDATE stories SET image = LEFT(urlprefix, LENGTH(urlprefix)-1) || thing.image WHERE id = thing.id;
END LOOP;