Skip to content

Instantly share code, notes, and snippets.

View s3cur3's full-sized avatar

Tyler A. Young s3cur3

View GitHub Profile
@s3cur3
s3cur3 / get_canonical_taxi_sign.cpp
Created February 6, 2017 22:35
Transforms a user-input taxi sign into a canonical string representation
#include <iostream>
#include "WED_Sign_Parser.h"
using namespace std;
int main(int argc, const char * argv[])
{
if(argc >= 2)
{
string sign_text;
@s3cur3
s3cur3 / create_git_repo.sh
Last active May 29, 2019 20:54
Create a repo on the X-Plane dev server
#!/bin/bash
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
echo "This script must be run with sudo"
exit
fi
if [ $# -lt 2 ]; then
echo 1>&2 "Usage: \$ ./$0 name_of_repo_to_create group_to_own_it"
exit 2
@s3cur3
s3cur3 / explicitly_ignore_return_values.ex
Last active February 8, 2021 18:16
A Credo check to issue a warning on unused return values from functions.
defmodule ExplicitlyIgnoreReturnValues do
@moduledoc """
This is a horrifying hack.
It is a complete copy & paste of Credo's stock unused_operation and unused_function_return_helper,
but modified slightly to reverse the logic; instead of specifying modules and types to warn about when unused,
we specify an "allow list" of the *only* modules & functions to allow ignoring.
See original copypasta source here:
https://github.com/rrrene/credo/blob/master/lib/credo/check/warning/unused_operation.ex
@s3cur3
s3cur3 / world_cache.ex
Created July 1, 2020 10:53
Sample gauge usage for AppSignal
defmodule MmoServer.WorldCache do
@moduledoc "A cache of all aircraft in the world, intermittently updated for 'flight tracker' API usage"
use GenServer
require Logger
import Appsignal, only: [set_gauge: 2]
def start_link(_), do: GenServer.start_link(__MODULE__, %{}, name: __MODULE__)
# Log a new connected user
def put(%{session_id: sid, lon: lon, lat: lat} = acf) when is_integer(sid) do
@s3cur3
s3cur3 / git_checkout_dammit.sh
Created December 21, 2020 19:07
Nukes all the untracked files that Git checkout complains about, then actually performs the checkout
#!/bin/bash
if git checkout "$1" ; then
echo "No untracked files had to be deleted"
else
git checkout "$1" 2>&1 > /dev/null | grep $'\t' | xargs rm
git checkout "$1"
echo "Deleted conflicting untracked files"
fi
@s3cur3
s3cur3 / key-transform.swift
Last active March 20, 2021 12:13 — forked from christianselig/milkshake.swift
Generic versions of transforming Dictionary keys and values, inspired by https://twitter.com/ChristianSelig/status/1372961695346352130
extension Dictionary {
func mapKeys<NewKey>(_ transform: (Key) -> NewKey) -> [NewKey: Value] {
reduce(into: [NewKey: Value]()) { result, item in
result[transform(item.key)] = item.value
}
}
}
/// 🥤
extension Dictionary where Key: RawRepresentable {
@s3cur3
s3cur3 / demo.exs
Last active September 9, 2021 13:44
Elixir GenServer versus Python class
my_user = User.start_link("Tyler", "abcd-efgh-1234-5678")
# Prints "Hi, I'm Tyler"
User.say_hello(my_user)
# Prints a process ID
IO.inspect(my_user)
# Prints the state data:
# %{name: "Tyler", id: "abcd-efgh-1234-5678"}
@s3cur3
s3cur3 / greeter.ex
Created December 2, 2021 15:59
A GenServer that will experience intermittent crashes due to timeouts
defmodule Greeter do
use GenServer
def start_link(opts) do
name = Access.get(opts, :name, __MODULE__)
GenServer.start_link(__MODULE__, name, name: name)
end
def greet(server \\ __MODULE__, name) do
GenServer.call(server, {:greet, name})
@s3cur3
s3cur3 / fix_wxwidgets.sh
Last active February 14, 2022 21:39
Install wxwidgets in a way Elixir/Erlang's :observer can use
# If you're here, I assume it's because you tried to run
# :observer for the first time on your Mac and discovered
# it won't work because of some obscure issue with wxwidgets
# (formerly known to Homebrew as wxmac).
#
# This script will fix it for you.
# 1. Remove the old and busted copy
brew uninstall wxwidgets --ignore-dependencies
@s3cur3
s3cur3 / elixir-ci.yml
Last active April 11, 2022 19:37
Basic Elixir CI (Felt's starting point)
name: Build and Test Elixir Server
on:
push:
branches:
- main
pull_request:
branches:
- main