Skip to content

Instantly share code, notes, and snippets.

View erming's full-sized avatar
Tinkering.

Mattias Erming erming

Tinkering.
  • Software Contractor
  • Sweden
View GitHub Profile
@erming
erming / useModel.js
Created July 13, 2025 13:55
useModel.js
import _ from "lodash";
import { useState, useLayoutEffect, useMemo } from "preact/hooks";
export const useModel = (origin) => {
const [model, setModel] = useState(origin);
function reset() {
setModel(_.cloneDeep(origin));
}
#include <iostream>
void toJSON() {
std::string json;
int prependComma = 0;
int rows = 0;
auto _beginBlock = [&] () { prependComma = 1; rows = 0; };
auto _endBlock = [&] () { prependComma = 0; rows = 0; };
function tryParseJson(string) {
try {
const output = JSON.parse(string);
if (output && typeof output === "object") {
return output;
}
} catch {}
return null;
}
#!/bin/bash
sudo apt-get -y install sysbench
sysbench --test=cpu --cpu-max-prime=20000 run
#!/bin/bash
. /etc/os-release
echo "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /" | sudo tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list
curl -L "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/Release.key" | sudo apt-key add -
sudo apt update
sudo apt -y install podman
const fastify = require("fastify");
const sqlite3 = require("sqlite3");
const { nanoid } = require("nanoid");
const app = fastify();
const db = new sqlite3.Database(":memory:");
db.serialize();
db.run(`
CREATE TABLE data (
@erming
erming / swap.sh
Last active October 16, 2021 13:53
#!/bin/bash
echo "Begin..."
sudo dd if=/dev/zero of=/swapfile bs=128M count=16
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo swapon -s
sudo apt update && sudo apt install certbot python-certbot-nginx
sudo certbot --nginx
@erming
erming / grid.css
Created January 9, 2021 10:55
A simple CSS grid based on flexbox
* {
box-sizing: border-box;
}
[class^=col-] {
flex: 0 0 100%;
padding: 0 15px;
}
.container {
max-width: 540px;
margin: 0 auto;
#ifndef _QUEUE_H
#define _QUEUE_H
#undef min
#undef max
#include <queue>
template <class T>
class Queue {