Skip to content

Instantly share code, notes, and snippets.

@tindzk
tindzk / Dockerfile
Created April 7, 2024 12:21
Building pixiecore for ARM64
FROM golang:latest AS builder
ENV GOARCH=arm64
ENV GOOS=linux
ENV CGO_ENABLED=0
WORKDIR /build
RUN go install go.universe.tf/netboot/cmd/pixiecore@latest
use tokio::net::UdpSocket;
use std::net::{Ipv4Addr, SocketAddrV4};
pub async fn send_udp_message() {
let google_dns = Ipv4Addr::new(8, 8, 8, 8);
let buffer = &[
32, 189, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 4, 101, 54, 55, 51, 5, 100, 115, 99, 101, 57, 10, 97,
107, 97, 109, 97, 105, 101, 100, 103, 101, 3, 110, 101, 116, 0, 0, 65, 0, 1,
];
import { randomFillSync } from "node:crypto";
// Defined for length >= 2
//
// From https://stackoverflow.com/a/27747377/13300239
export function randomStr(length: number): string {
const rnd = new Uint8Array(length / 2);
randomFillSync(rnd);
// i.e. 0-255 -> '00'-'ff'
@tindzk
tindzk / log-bodies-akka-http.scala
Created September 7, 2021 09:58
Log request and response bodies with Akka-HTTP and ZIO
import zio.logging.Logging
import zio.ZIO
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.HttpResponse
import akka.http.scaladsl.server.Directives._
import scala.concurrent.{ExecutionContext, Future}
%
% Generate Poission spike train using a uniform probability distribution
%
% Generates up to r * T spikes.
% None of the spike times will exceed T.
%
% @param r firing rate (Hz)
% @param T spike train duration (seconds)
% @param dt time resolution (seconds)
% @return V Spike times (seconds)
@tindzk
tindzk / cpuinfo
Created January 13, 2019 17:11
Hetzner Cloud CX21
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 85
model name : Intel Xeon Processor (Skylake, IBRS)
stepping : 4
microcode : 0x1
cpu MHz : 2099.998
cache size : 16384 KB
physical id : 0
@tindzk
tindzk / scalanative.scala
Created January 3, 2019 13:30
Detect if program is run within Scala Native
def isScalaNative: Boolean =
System.getProperty("java.vm.name") == "Scala Native"
@tindzk
tindzk / ZipArchive.scala
Last active July 24, 2018 13:55 — forked from Swind/ZipArchive.scala
Unzip file
object ZipArchive {
def unZip(source: File, targetFolder: File): Unit = {
val zipFile = new ZipFile(source)
try
zipFile.entries.asScala.foreach { entry =>
val target = new File(targetFolder, entry.getName)
if (entry.isDirectory) target.mkdirs()
else {
target.getParentFile.mkdirs()
val in = zipFile.getInputStream(entry)
@tindzk
tindzk / PrefixClasses.scala
Created July 7, 2018 11:35
Prefix all referenced CSS tags in HTML files
import pine._
import better.files._
// Place file in src/
object PrefixClasses extends App {
File.currentWorkingDirectory.glob("*.html").foreach { file =>
val newContent = HtmlParser.fromString(file.contentAsString).map {
case t: Tag[_] => t.`class`.update(_.map(cls =>
if (cls.startsWith("sk-")) cls else "sk-" + cls))
case n => n
@tindzk
tindzk / pine-bloop.txt
Created May 6, 2018 17:47
Compiling Pine with Bloop
$ bloop test pineJVM --verbose
[D] Scheduled compilation of 'pineJVM' starting at 19:44:29.349.
[D] No changes
[D] Scheduled compilation of 'pineJVM-test' starting at 19:44:29.356.
[D] Full compilation, no sources in previous analysis.
[D] All sources are invalidated.
[D] Recompiling all 11 sources: invalidated sources (11) exceeded 50.0% of all sources
Compiling 11 Scala sources to /home/tim/dev/pine/.bloop/pineJVM/scala-2.12/test-classes ...
[D] Getting ch.epfl.scala:compiler-bridge_2.12:1.1.1+49-1c290cbb:compile for Scala 2.12.4-bin-typelevel-4
[D] Getting ch.epfl.scala:compiler-bridge_2.12:1.1.1+49-1c290cbb:compile for Scala 2.12.4-bin-typelevel-4