Skip to content

Instantly share code, notes, and snippets.

View BenFranzi's full-sized avatar
🚀

Ben Franzi BenFranzi

🚀
View GitHub Profile
@BenFranzi
BenFranzi / c.tsx
Last active May 12, 2024 09:50
Quick Reference
import React, { useState, useEffect } from 'react';
import axios from 'axios';
const TodoComponent = () => {
const [todos, setTodos] = useState([]);
const [newTodo, setNewTodo] = useState('');
const [editTodoId, setEditTodoId] = useState(null);
const [editedTodoText, setEditedTodoText] = useState('');
const [loading, setLoading] = useState(false);
const [error, setError] = useState('');
@BenFranzi
BenFranzi / index.js
Created April 29, 2024 22:51
Quick CRUD
import http from "http";
import url from "url";
import seed from "./seed.json" assert { type: "json" };
const items = structuredClone(seed);
let nextId = items.length ? items.at(-1).id + 1 : 0;
function GET(req, res) {
const queryObject = url.parse(req.url, true).query;
@BenFranzi
BenFranzi / patterns.ts
Last active May 6, 2024 06:00
Common patterns
// binary search
export default function binarySearchIndex(list: number[], target: number): number {
let lo = 0;
let hi = list.length - 1;
while (lo <= hi) {
const mid = lo + Math.floor((hi - lo) / 2);
if (list[mid] === target) {
return mid;
@BenFranzi
BenFranzi / redirect.js
Created March 7, 2024 03:17
Wasteland
const http = require('http');
const server = http.createServer((req, res) => {
// Check the value of the "Brand" header
const brandHeader = req.headers['brand'];
// Define port mappings based on brand
const portMapping = {
'BrandA': 3001,
'BrandB': 3002,
@BenFranzi
BenFranzi / .eslintrc.cjs
Last active May 14, 2024 02:04
TS Starter
module.exports = {
root: true,
env: {browser: true, es2020: true},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'@bengineer.dev/core'
],
parser: '@typescript-eslint/parser',
rules: {
@BenFranzi
BenFranzi / nginx.conf
Last active February 27, 2024 03:32
Simple nginx proxy demo
map $http_brand $brand_port {
ACME 3001;
LEXCORP 3002;
default 0;
}
server {
listen 80;
server_name localhost;
@BenFranzi
BenFranzi / csv-parser.js
Last active September 1, 2023 05:47
CSV Parser Exercise
function csvParser(raw) {
const collector = [];
let line = [];
let isWithinQuotes = false;
let buffer = '';
for (let char of raw) {
// if a quote appeared and the previous character wasn't an escape character
if (char === '"' && buffer[buffer.length - 1] !== '\\') {
isWithinQuotes = !isWithinQuotes;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<canvas id="canvas"></canvas>
<div class="item">
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@BenFranzi
BenFranzi / bens-faves
Last active September 15, 2020 04:35
Spots-15-09-20
## Top artists -- Short Term (4 weeks)
The Black Keys
ConcernedApe
DAYBREAK
Ball Park Music
Thomas Newman
天府事變
Taylor Swift
Lofi Hip-Hop Beats
Jaroslav Beck