Skip to content

Instantly share code, notes, and snippets.

View mac-chaffee's full-sized avatar

Mac Chaffee mac-chaffee

View GitHub Profile
@mac-chaffee
mac-chaffee / discord_bot_server_shutdown.py
Last active July 21, 2019 19:33
A discord bot that can start, stop, and check the status of Google Compute Engine instances. Automatically shuts down after a configurable amount of time.
import asyncio
import traceback
from discord.ext import commands
from googleapi import GoogleApi
VM_ARGS = {
"instance": "",
"project": "",
"zone": ""
@mac-chaffee
mac-chaffee / markov-discord-bot.py
Created April 24, 2019 01:17
A simple bot to imitate me on discord
# https://github.com/Rapptz/discord.py
# pip install discord.py
import discord
from discord.ext import commands
# https://github.com/dead-beef/markovchain
# pip install markovchain
from markovchain.text import MarkovText, ReplyMode
bot = commands.Bot(command_prefix='!')
@mac-chaffee
mac-chaffee / dynamic_factorial.exs
Last active December 27, 2017 22:34 — forked from CMCDragonkai/dynamic_factorial.exs
Elixir: Tail Recursive Factorial - Avoids growing stack space linearly. This is related to dynamic programming: http://stackoverflow.com/q/12649970/582917
// factorial tail recursive (Elixir style)
// 4! means 1*2*3*4, we can ignore 1, which makes it 2*3*4 = 24
def factorial(num), do: factorial(num, 1)
defp factorial(num, _product) when num < 0, do: raise ArithmeticError
defp factorial(num, product) when num <= 1, do: product
defp factorial(num, product), do: factorial(num - 1, product * num)
@mac-chaffee
mac-chaffee / compress_all.sh
Created May 9, 2017 23:22
Bash script to compress all files in a folder using ImageMagick
for img in *; do
convert $img -quality 20% -verbose compressed_$img
done
@mac-chaffee
mac-chaffee / Bash PS1 with colors and git branch name
Last active January 21, 2023 17:00
Terminal title, blue path name, orange git branch name, newline, green dollar sign.
# Terminal title, blue path name, orange git branch name, newline, green dollar sign.
PS1="\[\e]0;\u@\h: \w\a\]\[\033[01;34m\]\w/ \[\033[38;5;166m\]\$(__git_ps1 '(%s)')\n\[\033[01;32m\]\$ \[\033[00m\]"
# example:
# ~/my-project/ (master)
# $ cd docs
# ~/my-project/docs/ (master)
# $
@mac-chaffee
mac-chaffee / CodeFormat.vba
Created November 18, 2016 17:41
Syntax highlighting for pseudo-code in Microsoft Word.
Sub CodeFormat()
If Selection.range.Start = Selection.range.End Then
MsgBox "You havn't selected any text"
Exit Sub
End If
Dim i As Long
Dim j As Long
Dim PrimaryList
Dim SecondaryList