Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeff Lindsay progrium

View GitHub Profile
@progrium
progrium / README.md
Last active Jan 12, 2022
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 / 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 / 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
@progrium
progrium / gist:956006
Created May 4, 2011
Greenlet exception handling in gevent
View gist:956006
import gevent
import gevent.pool
class GroupWithExceptionCatching(gevent.pool.Group):
def __init__(self, *args):
super(GroupWithExceptionCatching, self).__init__(*args)
self._error_handlers = {}
def _wrap_errors(self, func):
"""Wrap a callable for triggering error handlers
@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 NowPlayingStatus.js
#!/usr/bin/env osascript -l JavaScript
ObjC.import("Cocoa");
function run(argv) {
var app = $.NSApplication.sharedApplication;
var statusBarItem = $.NSStatusBar.systemStatusBar.statusItemWithLength($.NSVariableStatusItemLength);
var track = Application('Spotify').currentTrack
ObjC.registerSubclass({
name: "ProgramDelegate",
View fds_demo.go
package main
import (
"fmt"
"github.com/.../fds"
"github.com/.../fds/dict"
"github.com/.../fds/list"
"github.com/.../fds/tree"
)