Skip to content

Instantly share code, notes, and snippets.

@tluyben
tluyben / regex.js
Created December 3, 2024 15:52
regex in oK
function rx(x, y, env) {
function isNumber(str) {
if (typeof str !== "string") return false; // Must be a string
if (str.trim() === "") return false; // Empty string isn't a number
return !isNaN(str) && isFinite(Number(str));
}
x = l(x)
.v.map((t) => String.fromCharCode(t.v))
.join("");
y = l(y)
@tluyben
tluyben / claude-to-pdf.js
Created October 22, 2024 14:02
Save Claude code convo to pdf (or print etc) - not for Projects
// Function to close any open code blocks
function closeCodeBlocks() {
const closeButtons = document.querySelectorAll('button');
closeButtons.forEach((button) => {
const svgPath = button.querySelector('svg > path');
if (svgPath && svgPath.getAttribute('d').includes('M205.66')) {
// This path corresponds to the close icon (adjust if necessary)
button.click();
}
});
import { useState, useEffect } from 'react';
const subscribers = new Map<string, Set<React.Dispatch<any>>>();
function useLocalStorage<T>(key: string, initialValue: T) {
// State to store our value
const [storedValue, setStoredValue] = useState<T>(() => {
try {
const item = window.localStorage.getItem(key);
return item ? (JSON.parse(item) as T) : initialValue;
class ReactiveLocalStorage {
constructor() {
this.listeners = {};
}
setItem(key, value) {
localStorage.setItem(key, value);
this.notify(key, value);
}
#!/bin/bash
find . -name "package.json" -type f | while read -r file; do
# Backup the original file
cp "$file" "${file}.bak"
# Process dependencies and devDependencies
for key in dependencies devDependencies; do
jq --arg key "$key" '
if has($key) then
(function(){
const w = 1920, h = 1080;
// Function to make elements non-responsive
function makeNonResponsive(element) {
const style = window.getComputedStyle(element);
const width = style.getPropertyValue('width');
const height = style.getPropertyValue('height');
const position = style.getPropertyValue('position');
package main
import (
"fmt"
"io"
"os"
"os/exec"
"os/signal"
"strconv"
"strings"
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
)
@tluyben
tluyben / Dockerfile
Created March 25, 2024 10:21
Codel docker-compose start
FROM node:20.11.1-bookworm-slim
ENV NODE_ENV=development
WORKDIR /app
RUN apt update
RUN apt install -y build-essential
RUN apt install -y vim wget lynx curl mariadb-client git bash
RUN npm i -g ts-node
RUN npm i -g jest
@tluyben
tluyben / string-to-list.lisp
Last active July 27, 2023 21:19
unicode handling, basic string to list
(defun string-to-list (string)
(mapcar #'princ-to-string (coerce string 'list)))
;; (string-to-list "123🚘🚃🚅456")
;; > ("1" "2" "3" "🚘" "🚃" "🚅" "4" "5" "6")
;; and
(defun list-to-string (list)
(let ((result ""))