Skip to content

Instantly share code, notes, and snippets.

Avatar

Tim Morgan seven1m

View GitHub Profile
@seven1m
seven1m / remote_id.rb
Created September 26, 2022 20:11
Get / Change `remote_id` in Planning Center
View remote_id.rb
# usage: ruby remote_id.rb pco_id [remote_id]
#
# pco_id Planning Center profile ID
# remote_id Specify new remote ID
#
# get remote id:
# ruby remote_id.rb 1234
#
# set remote id:
# ruby remote_id.rb 1234 5678
@seven1m
seven1m / webserver.rb
Created September 1, 2022 00:18
web server in pure ruby using TCPServer
View webserver.rb
require 'socket'
server = TCPServer.new 3000
loop do
client = server.accept
method, request_target, _http_version = client.gets.strip.split
headers = {}
until (line = client.gets) =~ /^\r?\n$/
name, value = line.strip.split(': ')
View 07_dijkstra.rb
# Dijjkstra's Algorithm
# Book: Grokking Algorithms by Aditya Y. Bhargava
# Chapter: 7
class ShortestPath
def initialize(start_node, dest_node, graph)
@start_node = start_node
@dest_node = dest_node
@graph = graph
@seven1m
seven1m / lots_of_symbols.rb
Last active December 21, 2021 01:54
Adaptation of the first 10,000 words from https://gist.github.com/h3xx/1976236, as a list of Ruby symbols
View lots_of_symbols.rb
:the
:of
:and
:to
:a
:in
:that
:I
:was
:he
@seven1m
seven1m / awsping.sh
Last active November 8, 2021 18:56
Script to get latency for 3 AWS US regions
View awsping.sh
#!/bin/bash
# usage: ./awsping.sh | sort -n 2.7
# 39.93 us-east-2
# 44.95 us-east-1
# 64.89 us-west-2
function region_latency() {
local region="$1"
ping -c 1 ec2.$region.amazonaws.com &>/dev/null # throw away the first ping because DNS
@seven1m
seven1m / hello_world_llvm.cpp
Last active September 24, 2022 22:14
Simple 'hello world' example in LLVM IRBuilder
View hello_world_llvm.cpp
// % clang++ $(llvm-config --cxxflags --ldflags --system-libs --libs core) -o hello_world_llvm hello_world_llvm.cpp
// % ./hello_world_llvm
// hello world
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/IR/IRBuilder.h>
#include <stdio.h>
using namespace llvm;
@seven1m
seven1m / frame.py
Last active September 4, 2021 18:02
A small Python script that creates a semi-transparent resizable frame that stays on top. I use it to mark an area of my screen (the area where my webcam is overlayed) off-limits when screencasting.
View frame.py
#!/usr/bin/env python
# shamelessly stolen and adapted from https://gist.github.com/KurtJacobson/374c8cb83aee4851d39981b9c7e2c22c
# usage: python3 frame.py [width] [height] [x] [y] [opacity]
import cairo
import gi
import sys
import resource
View package_manager_cheat_sheet.md
package manager sync db install upgrade uninstall
apt-get update install install remove
brew update install upgrade uninstall
bundle N/A install update remove
gem N/A install install uninstall
pacman -y -S -S -R
@seven1m
seven1m / download_albums_from_flickr.rb
Created September 3, 2020 02:26
Ruby script to download albums from Flickr
View download_albums_from_flickr.rb
# downloads photos from your Flickr albums; each album is its own folder
#
# usage:
#
# gem install flickr
# FLICKR_API_KEY=abc123def456 FLICKR_SHARED_SECRET=abc123 FLICKR_USER_ID=11111111@N00 ruby download.rb
require 'flickr'
require 'fileutils'
require 'open-uri'
@seven1m
seven1m / fzf_branch_selection.zsh
Created August 6, 2020 15:59
Alias I use for switching branches
View fzf_branch_selection.zsh
# fuzzy finder branch selection
# if run by itself, switches to the selected branch
# if run in a subshell, echos the selected branch
function fgb() {
if [[ "$ZSH_SUBSHELL" == "0" ]]; then
git checkout $(fgb)
else
gbranches |
fzf --height 40% --ansi |
awk '{print $1}' |