Skip to content

Instantly share code, notes, and snippets.

@franzwong
franzwong / README.md
Last active July 16, 2024 03:30
Start VM with QEMU on MacOS (Apple silicon cpu)

Start VM with QEMU on MacOS

  1. Install qemu
brew install qemu
  1. Download QEMU_EFI.fd
@franzwong
franzwong / main.py
Created April 21, 2024 02:44
Mock kdb+/q ticker plant
import socket
import struct
import sys
import threading
import numpy as np
from qpython import qconnection, MetaData, CONVERSION_OPTIONS
from qpython._pandas import PandasQReader, PandasQWriter
from qpython.qcollection import QTable, qlist, qtable
from qpython.qconnection import MessageType
@franzwong
franzwong / Dockerfile.native
Created February 17, 2024 14:37
Multistage docker build of Quarkus native with GraalVM
FROM ghcr.io/graalvm/native-image-community:21 as build
WORKDIR /workspace/app
COPY .mvn .mvn
COPY mvnw .
COPY pom.xml .
COPY src src
RUN ./mvnw install -Dnative
VOLUME /root/.m2
@franzwong
franzwong / loki-config.yaml
Created September 17, 2023 03:04
Sample Loki config
auth_enabled: false
server:
http_listen_port: 3100
common:
path_prefix: /loki
replication_factor: 1
ring:
kvstore:
@franzwong
franzwong / main.q
Last active August 8, 2023 08:29
example of prometheus kdb exporter
/ Usage: rlwrap q main.q -p 8080
/ Metrics can be viewed at http://localhost:8080/metrics
/ extract.q can be downloaded in https://github.com/KxSystems/prometheus-kdb-exporter
system"l /src/prometheus-kdb-test/lib/extract.q"
labelkeys:`city
labelvalues:enlist "Tokyo"
.prom.newmetric[`temperature;`gauge;labelkeys;"Temperature"]
@franzwong
franzwong / rebuild_droplet.sh
Created April 13, 2023 02:11
Rebuild DigitalOcean droplet
#!/bin/bash
function rebuild_droplet() {
local -r token=${1}
if [[ ${#} -ge 2 ]]; then
local -r image_slug=${2}
else
local -r image_slug=ubuntu-22-04-x64
fi
@franzwong
franzwong / log_file
Created February 25, 2023 03:13
Filter log lines with date range and match pattern
2023-02-25 14:32:01 INFO: Successfully connected to database server
2023-02-25 14:33:27 ERROR: Unable to process request: invalid input format
2023-02-25 14:35:11 WARNING: Disk space is running low - only 10% remaining
2023-02-25 14:38:09 DEBUG: Received response in 0.0025 seconds
2023-02-25 14:41:02 INFO: User login successful - username: jdoe, IP address: 192.168.1.10
2023-02-25 14:44:12 ERROR: Failed to establish connection with external service
2023-02-25 14:47:09 DEBUG: Processing data - record count: 1000
2023-02-25 14:51:05 INFO: System restart initiated by admin user - reason: security patch installation
2023-02-25 14:55:23 WARNING: High CPU usage detected - current usage: 90%
2023-02-25 14:59:14 ERROR: Request timed out - no response received from server.
@franzwong
franzwong / DemoJob.java
Last active February 5, 2023 08:12
Retry with time interval for Quartz
package org.example;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.PersistJobDataAfterExecution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@franzwong
franzwong / Main.java
Created February 5, 2023 00:58
Quartz schedular example
package org.example;
import org.quartz.Job;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
@franzwong
franzwong / Client.java
Last active January 4, 2023 04:25
Use Java Selector to handle multiple clients with single thread
package com.franzwong.selector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
public class Client {