Skip to content

Instantly share code, notes, and snippets.

View angrychimp's full-sized avatar

Randall Kahler angrychimp

View GitHub Profile
@angrychimp
angrychimp / awsc-mezz-data.json
Created February 16, 2023 23:43
AWS Console Service Manifest
{
"regions": [
{
"id": "us-east-1",
"name": "US East",
"location": "N. Virginia",
"optIn": false
},
{
"id": "us-east-2",
@angrychimp
angrychimp / parse-json.php
Created December 28, 2021 17:08
Fine JSON errors in JSONL file
<?php
$fin = fopen($argv[1], 'r');
$lno = 0;
while ($line = fgets($fin)) {
$lno++;
try {
$decoded = json_decode($line, true, 512);
if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
throw new \Exception("Invalid JSON format");
@angrychimp
angrychimp / gen-coupons.py
Created December 2, 2021 20:23
Generates random coupon codes
import random
import string
from sys import argv
from time import time
from datetime import datetime, timedelta
# print("\n".join([",".join([x, "".join(random.choices(string.ascii_lowercase + string.digits, k=10))]) for x in range(10)]))
start = int(time())
print(",".join(["id","code","expdate"]))
print("\n".join([",".join([
@angrychimp
angrychimp / slack_members.php
Created September 2, 2021 20:26
Fetch number of members in a Slack channel
<?php
// Your ID and token
$botToken = 'xoxb-xxxxxxxxxx-xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx';
$channelID = 'C12345678';
// Setup cURL
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://slack.com/api/conversations.info?channel=$channelID&include_num_members=true",
def duration(sec):
is_float = isinstance(sec, float)
parts = [
('days', int(sec / 86400)),
('hours', int((sec % 86400) / 3600)),
('minutes', int((sec % 3600) / 60)),
('seconds', float(sec % 60) if is_float else int(sec % 60))
]
for i in range(len(parts)):
if float(parts[i][1]) > 0:
@angrychimp
angrychimp / fix-csv-array.py
Created June 17, 2020 17:37
Fix CSV files with array data
import csv
import os
import sys
sourcefile = os.path.expanduser(sys.argv[1])
targetfile = sourcefile.replace('.', '-fixed.', 1)
with open(sourcefile) as csvfile, open(targetfile, 'w') as fixfile:
reader = csv.DictReader(csvfile)
writer = csv.DictWriter(fixfile, reader.fieldnames)
writer.writeheader()
for row in reader:
@angrychimp
angrychimp / api-contact-latency-test.py
Created May 6, 2020 18:44
Testing contact availability latency via the Cordial API
import json
from urllib.parse import quote
import urllib3
import requests
DEFAULT_API_VERSION = 'v2'
DEFAULT_API_DOMAIN = 'api.cordial.io'
CORDIAL_APIKEY = ''
urllib3.disable_warnings()
@angrychimp
angrychimp / logo.html
Created November 11, 2019 17:18
random isometric logo
<svg color={value.color} viewBox='0 0 32 32' width='100%' height='100%'>
<path stroke="currentColor" strokeWidth='1px' fill="transparent" d='M13,11L8,21M8,21L22,18M22,18L13,11M0,32L8,21M8,21L0,0M8,21L32,32M32,32L22,18M0,0L13,11M13,11L32,0M32,0L22,18M32,32L32,0L0,0L0,32Z' strokeDasharray='0 0 0 0' />
<path stroke="currentColor" strokeWidth='3' fill="transparent" d='M32,32L32,0L0,0L0,32Z' />
<path stroke="currentColor" strokeWidth='1' fill="transparent" d='M2,0A2,2,0,1,1,-2,0A2,2,0,1,1,2,0M34,32A2,2,0,1,1,30,32A2,2,0,1,1,34,32M2,32A2,2,0,1,1,-2,32A2,2,0,1,1,2,32M34,0A2,2,0,1,1,30,0A2,2,0,1,1,34,0M24,18A2,2,0,1,1,20,18A2,2,0,1,1,24,18M10,21A2,2,0,1,1,6,21A2,2,0,1,1,10,21M15,11A2,2,0,1,1,11,11A2,2,0,1,1,15,11' />
</svg>
@angrychimp
angrychimp / useful.md
Last active May 7, 2022 21:14
A collection of tools, scripts, browser extensions, etc. that I've found make my life easier.

Browser Extentions

@angrychimp
angrychimp / raspbian-wifi-boot.md
Created March 22, 2018 22:07
How to get wi-fi and SSH working via image adjustments prior to a first boot.
  1. Download the image
  2. Flash the image to your microSD using Etcher
  3. Unmount/remount the microSD as necessary
  4. For wi-fi, add a file to the root folder named wpa_supplicant.conf
    • Content can be generated using
      read -p "SSID: " ssid
      read -s -p "Passphrase: " passphrase
      psk=$(wpa_passphrase $ssid $passphrase)

echo "country=US