Skip to content

Instantly share code, notes, and snippets.

@reywood
reywood / random.py
Created November 18, 2022 20:14
Generate a random 64 bit integer in python
from uuid import uuid4
_8_bit_mask = 0b11111111
_24_bit_mask = 0b11111111_11111111_11111111
def generate_random_64_bit_number():
u = uuid4()
return (
((u.node & _24_bit_mask) << 40)
+ ((u.clock_seq_hi_variant & _8_bit_mask) << 32)
@reywood
reywood / keymap.c
Last active September 14, 2020 01:03
Using only a subset of RGB matrix effects
#include QMK_KEYBOARD_H
uint8_t rgb_matrix_effects[] = {
RGB_MATRIX_NONE,
RGB_MATRIX_SOLID_COLOR,
RGB_MATRIX_BAND_VAL,
RGB_MATRIX_JELLYBEAN_RAINDROPS
};
uint8_t current_rgb_matrix_effect_index = 0;

Keybase proof

I hereby claim:

  • I am reywood on github.
  • I am reywood (https://keybase.io/reywood) on keybase.
  • I have a public key ASBcSxddxdyS3mGkSTL5d6FjzSehfD7WC89-C-OG8H6Gigo

To claim this, I am signing this object:

@reywood
reywood / how-to.md
Last active September 18, 2023 01:35
How to get a stack trace from a stuck/hanging python script

How to get a stack trace for each thread in a running python script

Sometimes a python script will simply hang forever with no indication of where things went wrong. Perhaps it's polling a service that will never return a value that allows the program to move forward. Here's a way to see where the program is currently stuck.

Install gdb and pyrasite

Install gdb.

# Redhat, CentOS, etc
@reywood
reywood / s3_file.py
Last active August 29, 2015 14:05
Salt state for fetching a file from an S3 bucket. Place s3_file.py in /srv/salt/[ENV]/_states/
import os
import os.path
import salt.exceptions
from tempfile import mkstemp
def get(name, bucket, path, md5, access_key=None, secret_key=None):
ret = {'name': name, 'changes': {}, 'result': False, 'comment': ''}
if md5 is None or len(md5) != 32:
@reywood
reywood / meteor-init-script
Last active July 27, 2017 18:05
SysVinit boot script for running a bundled Meteor app under Forever as a service. Should work with CentOS, Redhat, Amazon Linux, etc.
#!/bin/bash
#
# Service script for running a bundled Meteor application under Forever.
# Meteor settings JSON file should be in /etc/meteor/[YOUR APP NAME].json,
# and the METEOR_SETTINGS var below should be updated as appropriate.
#
# chkconfig: 345 80 20
# description: My node app
#
@reywood
reywood / _bootswatch-flatly-variables.scss
Last active June 6, 2023 12:07
Bootswatch Flatly Theme v3.1.1 in SCSS
// Flatly 3.1.1
// Variables
// --------------------------------------------------
//== Colors
//
//## Gray and brand colors for use across Bootstrap.
$gray-darker: lighten(#000, 13.5%); // #222
@reywood
reywood / gist:8721917
Created January 30, 2014 22:57
Modify checkbox state based on input value
<html>
<head>
<script>
function handleKeyUp(input) {
document.getElementById('cb').checked = input.value.length > 0;
}
</script>
</head>
<body>