Skip to content

Instantly share code, notes, and snippets.

@shaunlee
shaunlee / validator.go
Last active June 22, 2024 02:51
Form validation with custom errors and nested structs
package forms
import (
"github.com/go-playground/validator/v10"
"github.com/gofiber/fiber/v2"
"reflect"
"strings"
)
/*
@shaunlee
shaunlee / tracker.go
Last active June 22, 2024 01:44
HTTP request/response logger
package tracker
import (
"fmt"
"github.com/gofiber/fiber/v2"
"log"
"strings"
"time"
)
@shaunlee
shaunlee / sqlite_write_performance.md
Last active February 29, 2024 06:46
Bunjs SQLite has poor write performance

The bun:sqlite has a write performance of only 957/s on SSD, while the node better-sqlite3 has 51080/s.

Test results:

bun:sqlite, ssd: 957/s
bun:sqlite, memory: 66906/s
node better-sqlite3, ssd: 51080/s
node better-sqlite3, memory: 56863/s
go-sqlite3, ssd: 49453/s
go-sqlite3, memory: 54632/s
@shaunlee
shaunlee / app_nav.svelte.html
Last active October 1, 2022 21:49
Svelte app navigate
<script>
import { writable, get } from 'svelte/store'
export const pages = writable([])
export const dialogs = writable([])
export default {
push (component, props = {}) {
dialogs.set([])
pages.update(e => [ ...e, { component, props } ])
@shaunlee
shaunlee / EtagMiddleware.php
Created September 6, 2022 17:00
Laravel/Lumen Etag Middleware
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class EtagMiddleware
{
public function handle(Request $request, Closure $next)
@shaunlee
shaunlee / form.js
Created April 17, 2021 23:41
Form state handling wrapped for Vue projects
import { reactive } from '@vue/reactivity'
export function createForm({
form = {},
validate,
submit,
keep = false,
}) {
const state = reactive({
form,
@shaunlee
shaunlee / CorsMiddleware.php
Last active March 14, 2017 02:36
Lumen with CORS and OPTIONS requests
<?php
namespace App\Http\Middleware;
use Closure;
class CorsMiddleware
{
/**
* Handle an incoming request.
@shaunlee
shaunlee / circle_byte_buffer.go
Created August 12, 2016 13:14
Circle byte buffer
package main
import (
"io"
"errors"
)
var ErrBufferIsNotEnough = errors.New("buffer is not enough")
type ByteBuffer struct {
@shaunlee
shaunlee / gist:dfbf5d805d4f5a3f9a54
Created October 26, 2015 04:50 — forked from jessedearing/gist:2351836
Create self-signed SSL certificate for Nginx
#!/bin/bash
echo "Generating an SSL private key to sign your certificate..."
openssl genrsa -des3 -out myssl.key 1024
echo "Generating a Certificate Signing Request..."
openssl req -new -key myssl.key -out myssl.csr
echo "Removing passphrase from key (for nginx)..."
cp myssl.key myssl.key.org
openssl rsa -in myssl.key.org -out myssl.key
angular.module('App', []).config(['$interpolateProvider', function($interpolateProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
}]);