Skip to content

Instantly share code, notes, and snippets.

View johnpena's full-sized avatar

John Peña johnpena

View GitHub Profile
@johnpena
johnpena / iterm_tab.scpt
Created January 31, 2024 17:15
Applescript script to open a new tab in iTerm if a window exists, otherwise to open a new window. Useful with Hammerspoon.
tell application "iTerm"
activate
-- Check if iTerm is running and has at least one window
if (count of windows) is greater than 0 then
-- iTerm is running and has at least one window, so create a new tab
tell current window
create tab with default profile
end tell
else
-- iTerm is running but has no windows, so create a new window
#!/usr/bin/env bash
function kvset {
curl -s "localhost:4000/set?$1=$2" > /dev/null
}
function kvget {
url="localhost:4000/get?key=$1"
curl -s "$url" | jq '.value?'
}
@johnpena
johnpena / main.go
Created November 25, 2023 14:46
Recurse Center key value server implementation
package main
import (
"encoding/json"
"log"
"net/http"
)
const port = ":4000"
@johnpena
johnpena / summarize.ipynb
Created May 17, 2023 17:53
summarize.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
CREATE OR REPLACE FUNCTION humanize_time_span(ts timestamp) RETURNS varchar AS
'
SELECT
CASE
WHEN (now() - ts::timestamp)::INT < 60 THEN 'Within the last minute'
WHEN ((now() - ts::timestamp)::INT) / 60 < 60 THEN ((now() - ts::TIMESTAMPTZ)::INT / 60)::INT || ' Minutes ago'
WHEN (now() - ts::TIMESTAMPTZ)::INT / (60 * 60) < 24 THEN ((now() - ts::TIMESTAMPTZ)::INT / (60 * 60))::INT || ' Hours ago'
ELSE ((now() - ts::TIMESTAMPTZ)::INT / (60 * 60 * 24))::INT || ' Days ago'
END
'
package observability
import (
"context"
"fmt"
"github.com/correlatedlabs/pkg/go-common/env"
"github.com/correlatedlabs/pkg/go-common/util"
log "github.com/sirupsen/logrus"
"go.opentelemetry.io/otel"
@johnpena
johnpena / twoschoice.go
Created November 29, 2022 14:08
Demonstration of the two's choice method of balancing servers in a reverse proxy
package main
import (
"flag"
"log"
"math/rand"
"net/http"
"net/http/httputil"
"net/url"
"strings"
@johnpena
johnpena / template.sh
Created October 27, 2022 18:34
template.sh
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then
set -o xtrace
fi
// filepath server/server.go
package server
type Server struct {}
// filepath server/foo/subserver.go
package foo
type subserver struct {
server.Server
@johnpena
johnpena / keybase.md
Created March 19, 2021 16:42
keybase.md

Keybase proof

I hereby claim:

To claim this, I am signing this object: