Skip to content

Instantly share code, notes, and snippets.

@bryanjhv
bryanjhv / Crypt.ts
Created January 18, 2024 21:01
Laravel Encryption Crypt WebCrypto implementation
function s2b(data: string) {
return Uint8Array.from(data, c => c.charCodeAt(0)).buffer
}
function b2s(data: ArrayBufferLike) {
return String.fromCharCode(...new Uint8Array(data))
}
function hex(data: ArrayBufferLike) {
return [...new Uint8Array(data)].map(x => x.toString(16).padStart(2, '0')).join('')
import type { FastifyInstance } from 'fastify'
import fp from 'fastify-plugin'
import type { ZodAny, ZodError, ZodTypeAny } from 'zod'
import { z } from 'zod'
import { fromZodError } from 'zod-validation-error'
declare module 'fastify' {
// TODO: Copy ZodTypeProvider here (output)
interface FastifyTypeProviderDefault {
output: this['input'] extends ZodTypeAny ? z.infer<this['input']> : unknown
import { extname } from 'node:path'
import sharp, { FormatEnum } from 'sharp'
import type { Plugin } from 'vite'
function sharpPlugin(): Plugin {
return {
name: 'vite:sharp',
enforce: 'post',
apply: 'build',
async generateBundle(_, bundle) {
#!/bin/bash
args=(
minimal=yes # build only gpsd
gpsdclients=no # without clients
gpsd_group=uucp # arch linux group
socket_export=yes # fixes gps_unpack
control_socket=yes # for /run/gpsd.sock
)
/*
An example that converts os.Args to argc/argv for C.
Can be used with any []string with the same procedure.
*/
package main
/*
#include <stdio.h>
#include <stdlib.h>
package main
import (
"encoding/binary"
"fmt"
"net"
"time"
)
type Packet struct {
@bryanjhv
bryanjhv / README.md
Created December 19, 2022 19:30
GPSD for GeoClue2 using NMEA over TCP

CLUE-NMEA-GPSD

GPSD for GeoClue2 using NMEA over TCP.

Installation

  1. Copy the XML file to /etc/avahi/services/nmea-0183.service.
  2. Run glue.py in order to start the service (listens on 10110/tcp).
  3. Optionally create a service (systemd or the like) for it to start at boot.
  4. Optionally disable all GeoClue2 sources except network-nmea to use GPS only.
// Simple Golang script for controlling Wiz light bulbs.
// It uses UDP discovery and makes it blink randomly.
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
// Log custom tags used by running go root, and the files where they
// are used, so you can quickly see which tags can be used for
// specific behavior or just see, for example, which modules are CGo.
package main
import (
"fmt"
"go/scanner"
"go/token"