Skip to content

Instantly share code, notes, and snippets.

@tcard
tcard / daily-git-commit.sh
Last active October 5, 2022 05:35
Daily Git commit cronjob
#!/usr/bin/env bash
set -euo pipefail
function dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working tree clean" ]] && echo " (dirty)"
}
current_branch="$(git rev-parse --abbrev-ref HEAD)"
git add . # TODO: Save and then restore stage state
description="$(date +'%F %T') $current_branch$(dirty): $(git show -s --format='%h %s')"
@tcard
tcard / viewplan.go
Created November 5, 2021 10:42
This bad boy will open a Postgres plan visualizer in your browser (Mac) for the given query
func ViewPlan(ctx context.Context, db sqler.Queryer, s string, params ...interface{}) {
explain, err := func() (string, error) {
rows, err := db.Query(ctx, `EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON) `+s, params...)
if err != nil {
return "", err
}
defer rows.Close()
var explain strings.Builder
for rows.Next() {
var v string
@tcard
tcard / timetrack.py
Created September 6, 2021 15:06
Poor man's time tracker for projects
#!/usr/bin/env python
# LICENSE: See the bottom of this file.
# README
#
# Put this script in a directory. Make it executable. Edit the projects list
# below.
#
# The script will let you pick a project, then keep track of time spent on it
@tcard
tcard / clientcert.go
Created April 13, 2021 08:59
Go client certificate
package main
import (
"crypto/tls"
"crypto/x509"
_ "embed"
"fmt"
"log"
"net/http"
)

Keybase proof

I hereby claim:

  • I am tcard on github.
  • I am tcardenas (https://keybase.io/tcardenas) on keybase.
  • I have a public key ASATlAtPAROfdiXE8m13R_7dk0G5oYBN3o4yMHEPAXYqCAo

To claim this, I am signing this object:

@tcard
tcard / LICENSE
Last active January 12, 2021 07:50
Poor man's block websites script
Copyright (c) 2021 Toni Cárdenas
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-- My solution to https://mystery.knightlab.com/
SELECT * FROM crime_scene_report WHERE date = 20180115 AND type = 'murder' AND city = 'SQL City';
-- Security footage shows that there were 2 witnesses. The first witness lives at the last house on "Northwestern Dr". The second witness, named Annabel, lives somewhere on "Franklin Ave".
SELECT p.id, transcript
FROM person p
JOIN interview i ON p.id = i.person_id
WHERE address_street_name LIKE '%Franklin%'

Keybase proof

I hereby claim:

  • I am tcard on github.
  • I am tcardenas (https://keybase.io/tcardenas) on keybase.
  • I have a public key ASCuP5PccO3i6ZlUFIq67-bScHFGn1J075tiUnitRKUgBQo

To claim this, I am signing this object:

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tcard
tcard / tagged.go
Last active August 29, 2015 14:27
Tagged unions in Go
package main
import (
"fmt"
"unsafe"
)
// data Shape a = Circle { radius :: a } | Rect { base :: a, height :: a} | Together { left :: Shape a, right :: Shape a }
type ID_shape_float64 struct {
TAG int // Can be 0 (circle), 1 (rect), or 2 (together)