Skip to content

Instantly share code, notes, and snippets.

@tluyben
tluyben / convert-svg.js
Created February 9, 2025 14:01
Convert script for svg -> png
const sharp = require("sharp");
const fs = require("fs/promises");
const sizes = [16, 48, 128];
async function convertIcons() {
try {
await fs.mkdir("dist/assets", { recursive: true });
for (const size of sizes) {
@tluyben
tluyben / openroutercors.js
Created December 8, 2024 09:30
Open router cors test
// Paste this in your browser's console
async function testOpenRouter() {
const API_KEY = 'YOUR_API_KEY_HERE'; // Replace with your actual API key
try {
const response = await fetch('https://openrouter.ai/api/v1/chat/completions', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
@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"
)