Skip to content

Instantly share code, notes, and snippets.

View danopia's full-sized avatar

Daniel Lamando danopia

View GitHub Profile
@danopia
danopia / fetch-to-dataurl.ts
Created November 8, 2020 09:44
Small Deno sample of downloading a binary file into a data URL
import * as Base64 from 'https://deno.land/std@0.76.0/encoding/base64.ts';
async function toDataUrl(resp: Response): Promise<string> {
const contentType = resp.headers.get('content-type') ?? 'application/octet-stream';
const buffer = await resp.arrayBuffer();
return `data:${contentType};base64,`+Base64.encode(buffer);
}
const gifUrl = 'https://matthews.sites.wfu.edu/misc/jpg_vs_gif/testImage.gif';
console.log(await fetch(gifUrl).then(toDataUrl));
@danopia
danopia / README.md
Last active May 10, 2021 18:11
Print table in terminal with saml2aws assumed role profile information, as Deno script

$ aws-profiles

Purpose

When using saml2aws to assume AWS roles from a single-sign-on account, you'll need to get new credentials every workday (if not hourly). And users who use multiple accounts need to manage multiple sessions. It becomes hard to track which sessions you have active, and which sessions are expired.

@danopia
danopia / spaces-to-csv.ts
Created September 10, 2020 14:48
Small Deno tools
// In a Unix pipe, accepts 'tableized' input with many spaces between fields,
// and outputs the data as a traditional CSV.
// Does not handle input where fields contain their own spaces.
import { BufReader, BufWriter } from "https://deno.land/std@0.68.0/io/bufio.ts";
import { TextProtoReader } from "https://deno.land/std@0.68.0/textproto/mod.ts";
const input = new TextProtoReader(new BufReader(Deno.stdin));
while (true) {
@danopia
danopia / commands.js
Created September 7, 2020 07:08
deno irc bot prototype
export const commands = [
{
name: 'coinbase',
args:
script: 'https://......../command.js',
allow: {
net: ['api.coinbase.com'],
},
},
export default fetch
@danopia
danopia / main.go
Created July 14, 2020 18:14
google/netfilter batch insert size limit repro
package main
import (
"log"
// "time"
"github.com/google/nftables"
nftexpr "github.com/google/nftables/expr"
)
@danopia
danopia / app.js
Created June 29, 2020 08:13
Correlate Kubernetes pod traffic logs with other pods in the cluster by IP address
import Kubernetes from './kubernetes.js'
const kubectl = new Kubernetes({namespace: process.env.KUBE_NAMESPACE});
const logMinutes = 30;
(async () => {
// Tally IP addresses that hit us
const ipHits = new Map;
for (const pod of await kubectl.listPods({app: process.env.KUBE_APP_LABEL})) {
console.log(`Checking ${logMinutes}m of`, pod.metadata.name)
@danopia
danopia / Dockerfile
Last active April 23, 2020 11:55
hello-sts
FROM golang:1.14 AS build-go
WORKDIR /src
# cache deps
ADD go.* /src/
RUN go mod download
# build module
ADD * /src/
RUN go build -o /bin/hello-sts
# pack into minimal image
=> App running at: http://localhost:3000/
I20191124-22:57:41.292(-8)? Preparing to install package conduit
I20191124-22:57:41.364(-8)? Fetching package contents for conduit
I20191124-22:57:41.536(-8)? Parsing package
I20191124-22:57:41.599(-8)? Creating new package resources
I20191124-22:57:41.839(-8)? Injecting sass:Compile
I20191124-22:57:41.842(-8)? Using builtin
I20191124-22:57:41.870(-8)? Injecting coffeescript:Compile
I20191124-22:57:41.870(-8)? Using builtin
I20191124-22:57:42.189(-8)? Done installing package conduit !!
@danopia
danopia / frame_reader.go
Last active August 6, 2019 16:13
in-process video machine vision alg
package main
import (
"fmt"
"image"
"io"
"log"
"os"
"github.com/nareix/joy4/av/avutil"