Skip to content

Instantly share code, notes, and snippets.

View RickyCook's full-sized avatar
🏳️‍🌈

Ricky Cook RickyCook

🏳️‍🌈
View GitHub Profile
@RickyCook
RickyCook / promiseState.js
Last active June 1, 2021 19:10
JS func to get the state of a promise
/* Checks the state of a Promise without need to wait for a non-pending result
*
* This is an issue, because the state of a Promise object is inaccessible from
* JavaScript, so we are unable to take actions based on the current state of
* a Promise being pending or not
*/
const PROMISE_STATE_PENDING = Symbol()
async function promiseState(prom) {
try {
const result = await Promise.race([prom, Promise.resolve(PROMISE_STATE_PENDING)])
@RickyCook
RickyCook / main.js
Last active December 7, 2018 02:51
A TamperMonkey script that hides the Reddit post list "underlay" when you open a post thread
// ==UserScript==
// @name RedditHider
// @namespace https://www.reddit.com
// @version 0.2
// @description Hide Reddit main page when a thread is opened
// @author Ricky Cook
// @include https://www.reddit.com/*
// @grant none
// @updateURL https://gist.githubusercontent.com/RickyCook/72fc3a971a638b10864d98ffe3fc2ffd/raw/main.js
// ==/UserScript==
defmodule Notifier.Webhook.App do
use Application
require Logger
def start(_type, _args) do
Logger.debug("App.start")
import Supervisor.Spec
children = [
supervisor(Notifier.Webhook.Worker, []),
@RickyCook
RickyCook / trim_utf8.py
Last active May 16, 2019 01:53
Trim valid UTF8 bytes to a given max length, ensuring valid UTF8 afterwards
#!/usr/bin/env python3
import unittest
CONTINUATION_HIGH_BITS = 0b10
CONTINUATION_SHIFT_RIGHT = 8 - CONTINUATION_HIGH_BITS.bit_length()
def is_continuation(byte):
return byte >> CONTINUATION_SHIFT_RIGHT == CONTINUATION_HIGH_BITS
@RickyCook
RickyCook / collar.py
Created August 25, 2019 04:33
Decode a messy binary sequence whose value is ASCII/UTF-8 and that's all you know
#!/usr/bin/env python3
import sys
from copy import deepcopy
from pprint import pprint
class Decoder(object):
def __init__(
@RickyCook
RickyCook / codepipelinehack.py
Created February 7, 2020 00:10
CodePipeline hack to "support" symlinks
# CodePipeline doesn't support symlinks. They are reflected on
# disk as their target path in the file contents.
check_content_path = True
while check_content_path:
content = sql_path.read_text()
try:
new_sql_path = sql_path.parent.joinpath(content)
if new_sql_path.exists():
sql_path = new_sql_path
else:
@RickyCook
RickyCook / auth_state_machine.js
Created April 1, 2020 10:08
Authentication state machine
const TIMEOUT_MS = 2000;
const FSM_DEF = {
id: 'tokenRequest',
initial: 'timing',
context: {
payload: { statusCode: 500, body: '{"error":"Unknown error [init]"}'},
},
states: {
timing: {
@RickyCook
RickyCook / races.js
Created April 12, 2020 05:25
Random pairs generation
// sortedHashes = ['a', 'b', 'c', 'd', 'e', ...]
// doneRaces = [['a', 'c'], ['c', 'e'], ['a', 'b'], ...]
function getNewVoteRace(sortedHashes, doneRaces) {
let firstHash;
let secondIdxMax;
let secondTotalOpts;
let secondBlacklist;
while(_.isNil(secondIdxMax) || secondBlacklist.length >= secondTotalOpts) {
@RickyCook
RickyCook / _notes.md
Last active September 25, 2024 03:14
Quick bastion Wireguard VPN

Quick and dirty Wireguard bastion VPN

Enable IPv4 forwarding

sysctl -w net.ipv4.ip_forward=1 or echo 1 > /proc/sys/net/ipv4/ip_forward

/etc/sysctl.conf: net.ipv4.ip_forward = 1

Check IPv4 forwarding

@RickyCook
RickyCook / README.md
Created June 24, 2020 01:18
Slack Settings

Because Slack is shit

Sidebar

  • Sort by priority

Theme

  • Dark

Messages and Media

  • Compact