Skip to content

Instantly share code, notes, and snippets.

@ostcar
ostcar / build.zig
Created April 2, 2024 17:12
Example of a build.zig file, that preprocesses a roc platform
const std = @import("std");
const CrossTarget = std.zig.CrossTarget;
const OptimizeMode = std.builtin.OptimizeMode;
const LazyPath = std.Build.LazyPath;
const Compile = std.Build.Step.Compile;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
@ostcar
ostcar / gist:eb78515a41ab41d1755b
Last active October 28, 2023 10:34
Adds a _id suffix to PrimaryKeyRelatedField
class IdManyRelatedField(ManyRelatedField):
field_name_suffix = '_ids'
def bind(self, field_name, parent):
self.source = field_name[:-len(self.field_name_suffix)]
super().bind(field_name, parent)
class IdPrimaryKeyRelatedField(PrimaryKeyRelatedField):
"""
@ostcar
ostcar / main.go
Created June 18, 2023 15:38
Run roc with go
package main
import (
"context"
_ "embed"
"fmt"
"log"
"os"
"github.com/tetratelabs/wazero"
@ostcar
ostcar / code.go
Created November 12, 2022 12:23
Show memory usage in go services
// From https://github.com/dustin/go-humanize
func intToByte(s uint64) string {
sizes := []string{"B", "kB", "MB", "GB", "TB", "PB", "EB"}
base := 1000.0
logn := func(n, b float64) float64 {
return math.Log(n) / math.Log(b)
}
if s < 10 {
import re
from django.db import models
from django import forms
class HexFormField(forms.CharField):
default_error_messages = {
'invalid': 'Enter a valid hexfigure: e.g. "ff0022"',
}

Keybase proof

I hereby claim:

  • I am ostcar on github.
  • I am ostcar (https://keybase.io/ostcar) on keybase.
  • I have a public key ASCTQlqdzbn1FxrCM8hmPe1KsjR1IcTcj0V0y3Cofv9qogo

To claim this, I am signing this object:

@ostcar
ostcar / bigjson.go
Created January 13, 2020 22:09
Test decoding of big list of ints
package main
import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"io"
"strconv"
"time"
@ostcar
ostcar / all_data_dict.py
Last active January 25, 2019 20:52
Example for an all_data_dict
from collections import UserDict
from typing import Any, Dict, Generator, Tuple, Union
ElementID = Tuple[str, int]
Element = Dict[str, Any]
CollectionType = Union[Dict[int, Element], "Collection"]
class AllData(UserDict):
def __init__(self, initialdata: Dict[str, CollectionType]) -> None:
@ostcar
ostcar / inyoka_dev.yml
Created October 13, 2015 14:45
systemd-nspawn config for inyoka providing mysql and redis
---
- hosts: inyoka_dev
tasks:
- name: enable network
service:
name: "{{ item }}"
state: started
enabled: yes
with_items:
@ostcar
ostcar / openslides_ws_test.py
Created November 11, 2016 18:28
Test mass connection to the openslides projector
#!/usr/bin/env python
import asyncio
import functools
from datetime import datetime, timedelta
import websockets
WEBSOCKET_URI = 'ws://localhost:8000/ws/projector/1/'
CONNECTION_COUNT = 500