Skip to content

Instantly share code, notes, and snippets.

@ysimonson
ysimonson / Cargo.toml
Last active January 9, 2022 18:03
Rust wordle solver
[package]
name = "wordle_solver"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.4"
@ysimonson
ysimonson / bluetooth_sleep.lua
Last active March 26, 2024 03:47
Hammerspoon script to disable bluetooth when the computer is put to sleep. Requires `blueutil` to be installed (`brew install blueutil`).
require "string"
function checkBluetoothResult(rc, stderr, stderr)
if rc ~= 0 then
print(string.format("Unexpected result executing `blueutil`: rc=%d stderr=%s stdout=%s", rc, stderr, stdout))
end
end
function bluetooth(power)
print("Setting bluetooth to " .. power)
@ysimonson
ysimonson / indradb-cla.html
Created January 24, 2018 19:29
IndraDB CLA
<h1>Individual Contributor License Agreement</h1>
<p>Thank you for your interest in IndraDB. In order to clarify the intellectual property license granted with Contributions from any person or entity, IndraDB must have a Contributor License Agreement (&quot;CLA&quot;) on file that has been signed by each Contributor, indicating agreement to the license terms below. This license is for your protection as a Contributor as well as the protection of IndraDB and its users; it does not change your rights to use your own Contributions for any other purpose.</p>
<p>You accept and agree to the following terms and conditions for Your present and future Contributions submitted to IndraDB. In return, IndraDB shall not use Your Contributions in a way that is contrary to the public benefit or inconsistent with its bylaws in effect at the time of the Contribution. Except for the license granted herein to IndraDB and recipients of software distributed by IndraDB, You reserve all right, title, and interest in and to Your Co
@ysimonson
ysimonson / test.py
Last active November 1, 2017 18:17
"""
The script will run multiple simulations of flipping a coin continuously until
we hit either the sequence THHH or HHHH. It will print out how many times each
sequence was hit.
"""
# Use `secrets` rather than `random` because this is guaranteed to generate
# cryptographically secure random values
import secrets
import socket
import re
PORT = 1075
LINE_VALIDATOR = re.compile(r"(0|1) (0|1) (0|1) (0|1) (0|1)")
def main():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("0.0.0.0", PORT))
@ysimonson
ysimonson / mixed_tabs_spaces.py
Created April 20, 2017 00:39
Search for mixed tabs/spaces in files
#!/usr/bin/env python3
# Uses python3. Example: `python3 mixed_tabs_spaces.py '**/*.py'`
import glob
import sys
def has_mixed_tabs_spaces(f):
has_spaces = False
has_tabs = False
@ysimonson
ysimonson / wheel.html
Created February 18, 2017 20:06
Twirling Color Wheel
<html>
<body style="text-align: center">
<img id="img" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtoAAALaCAYAAAAP7vQzAAGx+0lEQVR42uydd5xdVdn9175TEyChgwoi0kvovSm9CoReRak2quCL5RVff4Ki0kQRFAUEAkS69N577yVUEZAOaZNp+/dHCpM75+z9tH3unWQ/n4+Sueecfc6dhMz3LtZeyyFPnjx58pBnl82B9g4A/TO//oPd0bbuWpgLXZgLHnMBmHPa/+aAx9wA5gUwEsBIeMwJYC7ATT3HYxgw43+d8OgA0AagDR5tAGoAWgA4eACAn/YE/fDoA9ANoAdANzymAOgCMBnAJHhMAjARwHh4Px7AZ9P+9zE8PgIwAcAE+Gn/BMYDGI8OTLjjAeCv/6r7BtSAyZOBK+7OfxaabQ455BCceeaZ+RuRJ08Tjcvfgjx58uQBRs4FrL0qgN5pfzk64OBdMOfcc2ME+jACwIjWGuZdf1Us1NKK+dCP+QA3zzSAng/9mKsOljsBdALoANA+DZA/n9DXnHM51w4+1gdgyrT/dcHPAPSp//T4EA4fTYPyDwH/IRw+6OnGf+97Gp/1+WnQXsOnH3yE3r9dN2DtFuC+p4AJk/OfrQzaefJk0M6TJ0+eWXra2oBtNvz86y8sgM4DdsX86MN8AOabbyQWW3x5fAl9+ALgvgDgS+jDvNPU5+nK81QE9TGodY2DaZNzffhcB6Ad3cBMKvg7qOEdAG+j37+DFrw57gW888kEfATgAzh8dNbVwPufTr2+vw+47iGgrz//2cygnSdPBu08efLkGRKz1GLAKisB6AE2Xgsj1lsHC6MLC3d24CvLjMJXAXwZcF+Gx5fRi5HANCV6uraLIrh09rAMlw7Eg2t5G2gPrTn9eDv6UcN4eHwK4H204HUA/wb8G+jHy8+/gHe6u/EuOvDuHQ+j/95nAbQCjzwHvPZu/r
@ysimonson
ysimonson / rust_try_replacer.py
Created January 5, 2017 04:16
Replaces all instances of try! in a rust codebase with the ? operator. I used this because I can't use rustfmt.
import os
import re
import sys
TRY_PATTERN = re.compile(r"try!\(")
def replace_try(contents):
match = TRY_PATTERN.search(contents)
if match:
@ysimonson
ysimonson / gist:7120798
Last active February 18, 2016 20:24
Tornado decorator to make an endpoint prerenderable for search engine crawlers
# This has been turned into a full-fledged repo:
# https://github.com/dailymuse/torender
@ysimonson
ysimonson / gist:6795714
Created October 2, 2013 15:38
Search for all files that have foobar using silver searcher, and open them in sublime
ag foobar --files-with-matches | while read filename; do subl $filename; done