Skip to content

Instantly share code, notes, and snippets.

@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(']]');
}]);
@shaunlee
shaunlee / router.php
Created August 28, 2015 06:32
Phalcon Micro MVC Router
<?php
$filename = $_SERVER['REQUEST_URI'];
if ($i = strpos($filename, '?')) {
$filename = substr($filename, 0, $i);
}
if (file_exists(__DIR__ . $filename)) {
return false;
}
@shaunlee
shaunlee / clear_tube.php
Last active March 2, 2016 10:24
beanstalkd: clear tube
<?php
include 'pheanstalk/pheanstalk_init.php';
$ph = new Pheanstalk_Pheanstalk('127.0.0.1');
$ph->ignore('default')->watch($tube);
while ($job = $ph->reserve(0)) {
$ph->delete($job);
fwrite(STDOUT, $job->getId() . "\r");