Skip to content

Instantly share code, notes, and snippets.

@jjylik
jjylik / account_adapter.py
Created February 11, 2024 15:04
django-allauth SAML
class AcmeSocialAccountAdapter(DefaultSocialAccountAdapter):
# ...or save_user
def populate_user(self, request: Request, sociallogin: SocialLogin, data: dict) -> Any:
user = super().populate_user(request, sociallogin, data)
roles = sociallogin.account.extra_data.get("roles", [])
# Do something with extra attributes incoming from the SAML authentication response
user.roles = map_to_your_app_roles(roles)
return user
@jjylik
jjylik / first.js
Created December 3, 2022 14:33
Wolf, goat, cabbage blog post
const animals = ['wolf', 'goat', 'cabbage']
boat.init(animals)
boat.load(animals[0])
boat.moveToNext()
boat.moveToNext()
//The next step is to load the cabbage
boat.load(animals[2])
// Crash!
@jjylik
jjylik / file-size-mismatch.ts
Last active November 12, 2022 15:25
Local fetch gives "wrong" number of bytes in iOS
//react-native-fs
const imagePath = '/somewhere/image.jpeg';
const imageFile = await RNFS.stat(imagePath)
const response = await fetch('file://'+imagePath);
const imageBody = await response.blob();
// Android returns true, iOS false :/
console.log(imageBody.size === imageFile.size)
@jjylik
jjylik / fork.go
Created August 21, 2022 11:51
Fork syscall in go
package main
import (
"fmt"
"syscall"
)
func main() {
a := 10
// NOTE: this does not actually work in any non-trivial applications.
@jjylik
jjylik / index.ts
Created March 26, 2022 13:23
Pulumi configs to user data script
import * as pulumi from '@pulumi/pulumi'
import {Droplet, DropletSlug, Region} from '@pulumi/digitalocean';
import * as fs from 'fs';
const dropletName = 'myDroplet';
const region = Region.AMS2;
const size = DropletSlug.DropletS1VCPU1GB;
const config = new pulumi.Config();
@jjylik
jjylik / Controller.tsx
Created August 29, 2021 11:09
Slow react-hook-form render
// Fast TS compile
<Controller
control={control}
...>
</Controller>
// Slow TS compile
<Controller<MyInputs, 'myField'>
control={control}
...>
@jjylik
jjylik / LazyScreenExample.tsx
Last active April 25, 2021 09:51
React native inline requires
const RootStack = (): JSX.Element => {
return (
<Stack.Navigator initialRouteName={initialRouteName}>
<Stack.Screen
name="SomeScreenWithLazyWrapper"
component={ScreenWrapper}
options={{title: 'Screen 1'}}
/>
<Stack.Screen
name="SomeScreenWithGetComponent"
@jjylik
jjylik / diff.txt
Created April 11, 2021 09:09
Alpine vs Google distroless image "diff -dqry" output
# diff -dqry alpine distroless > diff
Only in alpine/bin: arch
Only in alpine/bin: ash
Only in alpine/bin: base64
Only in alpine/bin: bbconfig
Only in alpine/bin: busybox
Only in alpine/bin: cat
Only in alpine/bin: chgrp
Only in alpine/bin: chmod
Only in alpine/bin: chown
@jjylik
jjylik / fetch-content-length.ts
Created March 28, 2021 07:07
Fetch content length
async function fetchContentLength(url: string): Promise<string | null> {
const response = await fetch(url, {method: 'HEAD'});
return response.headers.get('content-length');
}
@jjylik
jjylik / events.log.json
Last active March 7, 2021 09:06
WAL2JSON output naive go parser
{
"change": [
{
"kind": "update",
"schema": "public",
"table": "users",
"columnnames": ["id", "name"],
"columntypes": ["bigint", "text"],
"columnvalues": [14, "emily"],
"oldkeys": {