Skip to content

Instantly share code, notes, and snippets.

View sebnyberg's full-sized avatar
🇸🇪

Sebastian Nyberg sebnyberg

🇸🇪
View GitHub Profile
@sebnyberg
sebnyberg / main.go
Created March 29, 2023 20:27
ChatGPT module thing
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/ec2"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
type VpcArgs struct {
Name string
CidrBlock string
@sebnyberg
sebnyberg / keybase.md
Last active September 9, 2022 10:23
keybase.md

Keybase proof

I hereby claim:

  • I am sebnyberg on github.
  • I am sebnyberg (https://keybase.io/sebnyberg) on keybase.
  • I have a public key whose fingerprint is DF53 5589 DAE0 9ECB 9014 4758 0D00 5B0E C045 DB7C

To claim this, I am signing this object:

@sebnyberg
sebnyberg / a_test.go
Last active August 5, 2022 11:30
Sort + inplace dedup vs map
package a
import (
"math/rand"
"sort"
"testing"
)
var res []int
var res2 map[int]struct{}
@sebnyberg
sebnyberg / snippets.json
Created July 10, 2022 11:29
snippets.json
{
"TestCases": {
"prefix": "tcs",
"body": [
"func Test_$1(t *testing.T) {",
"\tfor _, tc := range []struct{",
"\t\t$2 $3",
"\t\twant $4",
"\t}{",
"\t\t{$0},",
@sebnyberg
sebnyberg / guide.md
Last active August 30, 2025 04:24
Ubuntu installation on iMac 2019 (MacOS 11 - Big Sur)

Ubuntu 20.04 with Wifi on iMac 2019 (MacOS 11 - Big Sur)

The purpose of this document is to summarize some of the things I had to figure out to successfully install Ubuntu on my iMac '19 27" 5K, a.k.a. iMac 19,1.

t2linux

From what I could find, iMac's do not have the t2 security chip. However, it does share hardware (and firmware) with contemporary Macbook Pros. For this reason, the t2linux.org website contains lots of helpful information about how to install Ubuntu on an iMac.

However, the guides on the t2linux website did not work for me when I ran it, so I had to mix and match some old pages from the wiki to make things work. Also, most issues are focused on Macbooks, not iMacs.

@sebnyberg
sebnyberg / example.sh
Last active March 25, 2022 16:56
Make sure to use errexit
#!/usr/bin/env bash
#
# Archive a folder by uploading it to S3 and
# renive it locally
#
# Usage:
#
# ./s3archive.sh $dir $bucket
#
echo "Uploading to archive bucket..."
@sebnyberg
sebnyberg / example.md
Last active March 25, 2022 15:58
Unintuitive Bash behavior for variables

Setting a local variable then running a command does not provide the variable to the child process:

$ GREETING=hi
$ python3 -c 'import os; print(os.environ.get("GREETING", "unknown"))'
unknown

However, setting a local variable in the same statement as the command does:

@sebnyberg
sebnyberg / ipow.c
Created February 6, 2022 16:21 — forked from orlp/ipow.c
int64_t ipow(int64_t base, uint8_t exp) {
static const uint8_t highest_bit_set[] = {
0, 1, 2, 2, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 255, // anything past 63 is a guaranteed overflow with base > 1
@sebnyberg
sebnyberg / main.go
Created January 17, 2022 15:17
concurrent_errors.go
package main
import (
"context"
"fmt"
"math/rand"
"strings"
"sync"
"time"
@sebnyberg
sebnyberg / grpc_proto_request_details.py
Created December 16, 2021 18:20
Unsafe parsing of error details (trailing metadata) from client-side in GRPC Python
def maybe_parse_details(e: grpc.RpcError) -> any:
if "_state" not in e.__dict__ or "trailing_metadata" not in e._state.__dict__:
return None
md = dict(e._state.trailing_metadata)
if "grpc-status-details-bin" not in md:
return None
val = md["grpc-status-details-bin"]
status = status_pb2.Status.FromString(val)