Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View samliu's full-sized avatar

Sam Liu samliu

View GitHub Profile
@samliu
samliu / crawl_planets_toward_origin.ts
Last active August 17, 2021 08:04
Dark Forest Plugin
// Crawl Planets Toward Origin
//
// Capture unowned planets around you, but heading toward coordinates 0,0.
// This is mostly the stock "crawl planets" plugin with like 5 lines of changes.
import { EMPTY_ADDRESS } from "https://cdn.skypack.dev/@darkforest_eth/constants";
import {
PlanetType,
PlanetTypeNames,
PlanetLevel,
@samliu
samliu / secret_life_of_a_love_song.txt
Last active June 12, 2021 08:06
The Secret Life of a Love Song - Nick Cave
West Country Girl
With a crooked smile and a heart-shaped face
Comes from the West Country where the birds sing bass
She's got a house-big heart where we all live
And plead and counsel and forgive
Her widow's peak, her lips I've kissed
Her gloves of bone at her wrist
That I have held in my hand
Her Spanish fly and her monkey gland
@samliu
samliu / check_vaccine.py
Last active April 14, 2021 19:29
Find CVS appointments for COVID-19 vaccine, and get them texted to your phone.
"""check_vaccine.py
Checks CVS for vaccine appointment availability and sends text messages if they show up.
Requires paid account on Twilio. You can fund $5 and it'll be plenty, a SMS is less than 1 cent.
Assuming you use a *nix system with Python 3 and want to deploy via crontab, you can do something like this:
1. `which python` Record the output. (It's nice to give crontab the full path of your python binary.)
2. `export VISUAL=vim` (For `crontab -e` to use vim; my personal preference.)
3. `crontab -e` to create a new line in your crontab. Next line is an example:
@samliu
samliu / means.py
Created May 25, 2018 21:06
Playing with means
"""Playing with means.
Geometric and Arithmetric means will only ever be equal when every item on the
list is the same. So if you keep entering 2,2,2,2,2,2,etc the two averages will
be the same. As soon as a new value is in the list the two values will diverge.
You can use this to look at how much the values diverge by with the introduction of outliers.
"""
class MovingAvg(object):
@samliu
samliu / spelling_bee.py
Last active December 24, 2017 08:49
NYT Spelling Bee
"""spelling_bee.py: Creates puzzles for NYT's spelling bee game.
Computers are fast. This leverages a ton of linear passes through a dictionary
because it's just for fun and puzzle examples still come back in under a second.
Performance improvements left as exercise to the reader.
No dependencies beyond Python 2.7+.
Author: Sam Liu <sam@ambushnetworks.com>
License: MIT
@samliu
samliu / dot_graph_builder.py
Last active November 19, 2018 22:10
Create simple GraphViz dot code from a graph builder API in Python.
"""Python GraphViz dot generator. Create simple GraphViz dot code from a graph
builder API.
The goal is to hook this up with a GUI at some point.
Future Improvements
* Potentially subprocess the graphviz generator to allow this to spit out
graphviz SVG or PNG files!
* UI that calls this API when you click certain elements.
@samliu
samliu / convert_epoch_time.py
Created June 20, 2017 22:44
Time converter so I can read timestamps
#!/usr/bin/env python
from datetime import datetime as dt
import sys
def main():
if len(sys.argv) < 3:
print ('Converts epoch milis/micros to human-readable timestamps.\n'
'Usage: ./convert_epoch_time.py micros <micros>\n'
@samliu
samliu / kvstore.js
Created June 9, 2017 01:18
SQLite-based Key-value store for use on glitch.com node.js projects. Raw
// This is a module that uses SQLite as a flat-file database to implement a simple key-value store.
//
// Exported methods:
// get(key, callback) - Retrieve the value for a given key in the store.
// insert(key, value) - Add a key/value to the store. If the key already exists, update its value.
// getAll(callback) - Retrieve all values in the database
// resetdb() - Reset the database
//
// Since this uses SQLite, it's locking and will likely have scalability issues when many concurrent users are
// accessing the database. Sequelize allows you to replace sqlite with a more production-ready database such
@samliu
samliu / binary_converter.py
Created June 7, 2017 06:00
Translate a postsecret's binary
# Translate binary into english characters.
# Written to translate a PostSecret on 01-24-2016.
#
# Author: Sam Liu <sam@ambushnetworks.com>
#
# 01001001001000000110101101101110011011110111
# 01110010000001001001001001110110110100100000
# 01100001001000000110011101100101011001010110
# 10110010111000100000010010010010011101101101
# 001000000111000001110010011011110111010101100

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name: