This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Script to deploy new releases on git push, automatically rolling back and rejecting pushes that fail to start. | |
# The repo must have a Makefile with `build`, `start` and `stop` targets. | |
# Each deployment starts from scratch, and ALL FILES UNDER THE REPO WORKTREE ARE DELETED. | |
# Use the parent dir if persistence is important. | |
# This script is meant to be executed as an `update` hook, which runs on every pushed ref, before it's accepted. | |
# Documentation: https://git-scm.com/docs/githooks | |
# - Exiting with an error rejects the push. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
def find_moves(target): | |
stack = deque([(0, 0, "")]) | |
while True: | |
# current: how many X's we currently have. | |
# clipboard: how many X's were copied. | |
# history: sequence of "T", "C" and "P" | |
current, clipboard, history = stack.popleft() | |
if current >= target: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Programming Language Checklist | |
by Colin McMillen, Jason Reed, and Elly Fong-Jones, 2011-10-10 | |
updated by BoppreH, 2024-01-24 | |
You appear to be advocating a new: | |
[ ] functional [ ] imperative [ ] object-oriented [ ] stack-based [ ] concurrent | |
[ ] interpreted [ ] compiled [ ] JIT [ ] cloud [ ] AI [ ] beginner-friendly | |
[ ] academic-friendly [ ] visual [ ] sharable [ ] esoteric | |
[ ] memory safe [ ] memory unsafe [ ] provable [ ] Turing-incomplete | |
[ ] statically-typed [ ] dynamically-typed [ ] completely incomprehensible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Login and visit each stackexchange site. Schedule it daily to win the Fanatic Badge after 100 days. | |
""" | |
# Create account.py module with 'email', 'password', and 'stackexchange_user_id'. | |
import account | |
import requests | |
import re | |
session = requests.Session() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from PIL import Image, ImageDraw | |
if len(sys.argv) > 1: | |
gif_path, = sys.argv[1:] | |
im = Image.open(gif_path) | |
width, before_height = im.size | |
images_before = [im.copy()] | |
while im.tell() < im.n_frames-1: | |
im.seek(im.tell()+1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Proxy: | |
""" | |
Wraps an object to keep track of modifications, including to its children. | |
""" | |
def __init__(self, obj, modified_flag=None): | |
# Must use `super().__setattr__` to avoid recursing on itself. | |
super().__setattr__('_obj', obj) | |
super().__setattr__('_modified_flag', modified_flag or [False]) | |
@property |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python implementation of | |
# $ grep 'lasagna' beef.txt | sort -n | uniq | |
import re | |
lines = list(set(line for line in open('beef.txt') if 'lasagna' in line)) | |
lines.sort(key=lambda line: int(re.match('\d*', line)[0] or 0)) | |
for line in lines: print(line, end='') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Runs Grey Goo ascensions with no input required. Just run this script once a day and it'll do some basic farming (11-leaf clovers, eating fortune cookies, etc) and reincarnate in the same path when possible. | |
void do_jobs() { | |
# Spend time doing Jobs Boards adventures. Not very rewarding, but | |
# levels us up enough to cast daily skills and gives some pocket change. | |
if (my_adventures() >= 10) { | |
visit_url("place.php?whichplace=town&action=town_oddjobs"); | |
while (my_adventures() >= 10) { | |
run_choice(985, "pwd&option=3"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Save to C:\Users\{USER}\AppData\Roaming\Mozilla\Firefox\Profiles\{PROFILE_NAME}\chrome\userContent.css | |
# And enable "toolkit.legacyUserProfileCustomizations.stylesheets" on about:config | |
@-moz-document domain(www.youtube.com) | |
{ | |
a:visited { | |
color: grey !important; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import collections | |
Interface = collections.namedtuple('Interface', 'name description subnet_mask ipv4_addresses ipv4_gateway ipv6_addresses ipv6_gateway dhcp_server dns_servers') | |
def parse_ipconfig(): | |
""" | |
Parses results from ipconfig. PowerShell has more structured functions, but | |
they don't serialize properly | |
(https://stackoverflow.com/questions/69997138/serialization-differences-between-powershells-format-list-and-convertto-json). |
NewerOlder