Skip to content

Instantly share code, notes, and snippets.

@aryelgois
aryelgois / git-ignore-line.sh
Last active December 14, 2024 10:59
Git filter to ignore lines in your files
#!/bin/sh
# Git filter to ignore lines in your files.
#
# Copyright (c) 2017-2019,2023 Aryel Mota Góis <[email protected]>
#
# MIT License
#
#
# SETUP:
#
@lucien144
lucien144 / cache-clear.sh
Last active November 20, 2024 05:02
Clear Cloudflare cache from command line.
#!/bin/bash
curl -X POST "https://api.cloudflare.com/client/v4/zones/{$ZONE_ID}/purge_cache" \
-H "X-Auth-Email: {$EMAIL}" \
-H "X-Auth-Key: {$API_KEY}" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}'
@andy0130tw
andy0130tw / subprocess_safe.py
Last active November 8, 2024 15:01
Finally I made it. A customized Popen to support limiting the size of stdout/stderr! (Works on non-Windows only, for now)
import contextlib
import io
import logging
import os
import queue
import selectors
import subprocess
import tempfile
import threading
from time import monotonic as _time
@minhoryang
minhoryang / README.md
Created August 20, 2019 05:19
FLASK with UDS(Unix Domain Socket)
@Mr0grog
Mr0grog / stdout_stderr_combined.py
Created January 25, 2020 07:39
Experiments in capturing combined output streams from subprocesses in Python.
# Experiments in capturing combined output streams from subprocesses.
#
# It turns out it's kind of hard to get the interleaved results of stdout and
# stderr in Python. However, in a lot of situations where Python is calling
# out to other processes, you probably want to swallow the child process's
# stderr when things to right and print it when things go wrong. Since some
# programs may be outputting results on stdout and warnings and errors on
# stderr, it makes sense that you'd want it all, and all in the order it was
# printed when things go wrong.
#
import math
import scipy.stats as st
# assumes bivariate normal, dichotomised groups
def dichotomy_r_to_d(r) :
d = 2*r / (math.sqrt(1 - r**2))
return d
# Equation 9
# https://sci-hub.tw/10.1037/1082-989X.11.4.386
@robertmaxwilliams
robertmaxwilliams / mers_min.c
Last active February 2, 2021 22:25
Simple and mildly ugly (and not very fast) implementation of 32 bit Mersenne Twister MT19937. mers_min.c is a shortened verion, mersenne_twister.c is the longer, parameterized version.
// Compile with gcc -std=c99 mersenne_twister.c -o /dev/random
// ps the -o /dev/random part is a joke, it's not actually meant to be a random device.
// Absolutely no warranty, Kopyleft I guess who gives a shit
#include <stdint.h>
#include <stdio.h>
uint32_t x[624];
uint32_t index = 0;
void twist() {
for (int k = 0; k < 624; k++) {
x[k] = x[(k+397)%624]
@qpwo
qpwo / predator_prey.py
Last active March 25, 2021 18:24
Predator-prey multi-agent reinforcement-learning environment in python without dependencies, and an implementation of an example q-learning agent
"""
A simple predator-prey multi-agent reinforcement learning environment in
python without dependencies, and an implementation of an example q-learning agent.
Python 3.9
https://gist.github.com/qpwo/a19f43368afd77288bf3b7db81fdc18b/
February, 2021 -- Public domain dedication
"""
from dataclasses import dataclass, field
import random
@qpwo
qpwo / express-typescript-auth.ts
Last active January 5, 2022 16:36
username & password authentication in node.js + express (WITHOUT passport) in typescript in a single standalone file (minimal working example)
// January 2022, Luke Harold Miles, public domain obviously
// Adapted from: https://github1s.com/expressjs/express/blob/master/examples/auth/index.js
// You can run with `ts-node express-typescript-auth.ts`
// Source for this file to get updates: https://gist.github.com/qpwo/4b2ae3aaaf222d099b34898152118c43
import { pbkdf2Sync, randomBytes, timingSafeEqual } from 'crypto'
import type { NextFunction, Request, Response } from 'express'
import express from 'express'
import type { Session } from 'express-session'
import session from 'express-session'