Skip to content

Instantly share code, notes, and snippets.

@mnadel
mnadel / twilio-main.js
Last active April 5, 2020 19:03
A Twilio app (via a series of Functions) that sends the caller to voicemail, but only if they correctly answer a captcha
const record = (twil) => {
twil.record({
transcribe: true,
transcribeCallback: "/transcribed", // see twilio-vm.js
action: "/call-missed", // see twilio-missed.js
maxLength: 90,
finishOnKey: "*"
})
}
@mnadel
mnadel / parse-prom-rules
Last active February 12, 2020 18:40
Parse a Prometheus rules (v1.x) file
#!/usr/bin/env python
import re
import sys
import csv
class State:
def __init__(self, val):
self._val = val
self._remaining = []
@mnadel
mnadel / s3du
Created April 4, 2018 17:46
du (disk usage) but for s3 (via ls-bucket)
#!/usr/bin/env python
import sys
import argparse
parser = argparse.ArgumentParser(description="du your s3")
parser.add_argument("--max-depth", type=int, help="max depth to report")
parser.add_argument("--raw", action="store_true", help="do not pretty print output")
args = parser.parse_args()
@mnadel
mnadel / ls-bucket
Created April 4, 2018 17:45
`ls -l` all objects in an S3 bucket
#!/usr/bin/env ruby
require "aws-sdk-s3"
bucket = Aws::S3::Resource.new.bucket(ARGV[0])
bucket.objects().each do |obj|
puts "#{obj.size} #{obj.key} #{obj.last_modified}"
end
@mnadel
mnadel / kcdo
Last active February 14, 2023 07:36
Exec Across (Some, All) Pods in Kubernetes
#!/usr/bin/env bash
PROGNAME=$(basename $0)
function usage {
echo "usage: $PROGNAME [-n NAMESPACE] [-m MAX-PODS] -s SERVICE -- COMMAND"
echo " -s SERVICE K8s service, i.e. a pod selector (required)"
echo " COMMAND Command to execute on the pods"
echo " -n NAMESPACE K8s namespace (optional)"
echo " -m MAX-PODS Max number of pods to run on (optional; default=all)"
@mnadel
mnadel / change-mac
Last active December 24, 2016 02:52
Change your Mac's MAC
#!/usr/bin/env bash
MYMAC=$(/usr/sbin/networksetup -getmacaddress Wi-Fi | grep -oE "[a-zA-Z0-9]{2}:([a-zA-Z0-9]{2}:?)+")
if [ "$1" == "--help" ] || [ $# -gt 1 ]; then
echo "usage: $(basename $0) [--random|--orig]"
exit 1
fi
if [ $# -eq 0 ] || [ "$1" == "--random" ]; then
@mnadel
mnadel / gist:bb4308d37840a8238939
Created February 9, 2016 15:32
Hate vim? Interactive rebase with Notepad++ instead.
C:\> git config --global core.editor "C:/Progra~2/Notepad++/notepad++.exe -multiInst -nosession -noPlugin """$*""""
@mnadel
mnadel / ThrottledTplDataflowPipelne.cs
Last active May 25, 2020 17:47
Applying Backpressure (aka Throttling) in TPL Dataflow
using System.Threading;
using System.Threading.Tasks.Dataflow;
class Pipeline<T>
{
private readonly SemaphoreSlim _semaphore;
private readonly BufferBlock<T> _buffer;
Pipeline(Action<T> action, int capacity)
{
@mnadel
mnadel / gist:aae1b4092cb2c5b0d521
Created November 7, 2014 17:06
Golang Concurrency Pattern
package main
import (
"sync"
"fmt"
)
func main() {
ch := make(chan int)
var wg sync.WaitGroup

Keybase proof

I hereby claim:

  • I am mnadel on github.
  • I am mnadel (https://keybase.io/mnadel) on keybase.
  • I have a public key whose fingerprint is 026C 37B7 178B 36E9 87B0 2765 AA7A EA3E 31CC 9983

To claim this, I am signing this object: