Skip to content

Instantly share code, notes, and snippets.

View rochacon's full-sized avatar

Rodrigo Chacon rochacon

  • Remote
  • 12:57 (UTC -03:00)
View GitHub Profile
@rochacon
rochacon / list-queues-sizes.ts
Last active March 16, 2024 22:08
Bun shell experiments
// this script lists all queues with a message count diferrent than 0
// usage: bun list-queues-sizes.ts
import { $ } from 'bun';
const queuesUrls = await $`aws sqs list-queues`.json();
const attrs = "QueueArn ApproximateNumberOfMessages ApproximateNumberOfMessagesNotVisible ApproximateNumberOfMessagesDelayed";
const queueAttributes = await Promise.all(queuesUrls.QueueUrls.map((url) => (
$`aws sqs get-queue-attributes --attribute-names ${{ raw: attrs }} --queue-url ${url}`.quiet().json()
)));
const output = queueAttributes.filter((e) => e.Attributes.ApproximateNumberOfMessages !== "0").map((e) => e.Attributes);
@rochacon
rochacon / cmd-to-websocket.go
Created December 8, 2014 20:17
Stream a command stderr and stdout throught websockets
package main
import (
"bufio"
"fmt"
"github.com/gorilla/websocket"
"io"
"log"
"net/http"
"os/exec"
@rochacon
rochacon / kshell
Last active December 8, 2023 17:44
kshell
#!/bin/bash
set -euo pipefail
test "${DEBUG:-false}" = "true" && set -x
USERNAME="${USER}"
NAMESPACE="${NS:-${USERNAME}}"
IMAGE="${IMAGE:-docker.io/pkgxdev/pkgx}"
ENV_FROM="${ENVFROM:-${NAMESPACE}}"
@rochacon
rochacon / wg-ns
Created December 8, 2023 17:25
wg-ns: wireguard network namespace setup helper
% cat bin/wg-ns
#!/bin/bash
set -exuo pipefail
name="${1?must provide name as argument}"
netns="${name}"
wg_conf="/etc/wireguard/wg.conf"
ipv4="$(grep Address "${wg_conf}" | grep -Po '([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\/32)')"
dnsaddr="$(grep DNS "${wg_conf}" | grep -Po '([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\/32)')"
package main
import (
"flag"
"fmt"
"log"
"os"
"sort"
"strings"
"text/tabwriter"
@rochacon
rochacon / portscan.go
Created May 30, 2020 03:18
portscan a cidr block port
package main
import (
"flag"
"fmt"
"log"
"net"
"os"
"sync"
"time"
@rochacon
rochacon / gist:1514222
Created December 23, 2011 13:32
Easy Django ModelForm widget placeholder
#
# This code inserts the placeholder attribute, using the field's label,
# for all TextInput, Textarea, DateInput, DateTimeInput, TimeInput widgets
# of your ModelForm
#
class MyForm(forms.ModelForm):
class Meta:
model = MyModel
def __init__(self, *args, **kwargs):
@rochacon
rochacon / README.md
Created April 10, 2015 05:15
AUR Sync

aur-sync is a simple script to keep AUR packages up to date.

How to use it:

# 1. First you need to create some directories where the work will happen:
mkdir -p /tmp/aur-sync-ws
mkdir -p /tmp/aur-sync-ws/build
mkdir -p /tmp/aur-sync-ws/src
cd /tmp/aur-sync-ws

Keybase proof

I hereby claim:

  • I am rochacon on github.
  • I am rochacon (https://keybase.io/rochacon) on keybase.
  • I have a public key whose fingerprint is 1C1D A0A2 1A14 2267 1BBC 680B D2FF 14CE D133 597F

To claim this, I am signing this object:

@rochacon
rochacon / s3proxy.go
Last active September 28, 2018 12:20
S3 Proxy in Go
package main
import (
"crypto/sha256"
"flag"
"fmt"
"github.com/gorilla/mux"
"hash"
"io"
"launchpad.net/goamz/aws"