Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeff Lindsay progrium

View GitHub Profile
@progrium
progrium / datetimeformat.js
Last active Nov 20, 2021
Intl.DateTimeFormat is kinda nutty with custom format strings, this makes it sane
View datetimeformat.js
function dateTimeFormat(timestamp, locale, str, ...opts) {
const d = new Date(timestamp);
return str.replace(/{(\d+)}/g, function(match, number) {
return typeof opts[number] != 'undefined'
? new Intl.DateTimeFormat(locale, opts[number]).format(d)
: match;
});
}
console.log(dateTimeFormat("2021-11-19T19:19:36.598071-06:00", "en", "{0} at {1}!", {dateStyle:"short"}, {timeStyle:"long"}))
View styling.ts
// styling module provides a helper for building style
// and class attributes for elements.
type Styling = string | Object | Style | (() => boolean);
type ConditionedStyle = [string, () => boolean];
export function from(...styling: Styling[]): Style {
return Style.from(...styling);
}
@progrium
progrium / cli.go
Created Sep 2, 2021
350 line reimplementation of cobra, simplified and with no dependencies
View cli.go
package cli
import (
"bytes"
"context"
"flag"
"fmt"
"os"
"reflect"
"strings"
@progrium
progrium / server.go
Created Aug 25, 2021
simple qtalk rpc server example
View server.go
// server.go
package main
import (
"fmt"
"log"
"net"
"strings"
"github.com/progrium/qtalk-go/codec"
@progrium
progrium / client.go
Last active Aug 25, 2021
simple qtalk rpc example client
View client.go
// client.go
package main
import (
"context"
"log"
"github.com/progrium/qtalk-go/codec"
"github.com/progrium/qtalk-go/fn"
"github.com/progrium/qtalk-go/talk"
View fds_demo.go
package main
import (
"fmt"
"github.com/.../fds"
"github.com/.../fds/dict"
"github.com/.../fds/list"
"github.com/.../fds/tree"
)
@progrium
progrium / README.md
Last active Nov 24, 2021
Setting up M1 Macs for x86 development with Homebrew
View README.md

Key Points

  • In general, binaries built just for x86 architecture will automatically be run in x86 mode
  • You can force apps in Rosetta 2 / x86 mode by right-clicking app, click Get Info, check "Open using Rosetta"
  • You can force command-line apps by prefixing with arch -x86_64, for example arch -x86_64 go
  • Running a shell in this mode means you don't have to prefix commands: arch -x86_64 zsh then go or whatever
  • Don't just immediately install Homebrew as usual. It should most likely be installed in x86 mode.

Homebrew

Not all toolchains and libraries properly support M1 arm64 chips just yet. Although

@progrium
progrium / README.md
Last active Oct 17, 2021
Large Type CLI utility for Mac in less than 80 lines of Go
View README.md

largetype

largetype screenshot

Building

Note: For now, Apple Silicon users need to be set up for x86 mode

First, download Go or brew install go. Then, put largetype.go in a directory called largetype and from there run:

$ go mod init largetype
View html.ts
function ItemList(items: Item[]) {
return html`
<div class="flex flex-row">
<for each=${items} do=${(item) => html`
<if cond=${item.enabled} then=${() => html`
<div class="text-white mx-2">${item.label}</div>
`}>
`} else=${() => html`
<div class="text-gray font-bold">No items</div>
`}>
View topframe.go
package main
import (
"fmt"
"log"
"net"
"net/http"
"os"
"os/user"
"path/filepath"