Skip to content

Instantly share code, notes, and snippets.

View signalwerk's full-sized avatar
💫
on the r͢oad

Stefan Huber signalwerk

💫
on the r͢oad
View GitHub Profile
@signalwerk
signalwerk / grid.scss
Last active June 3, 2024 15:46
Draw the columns of a grid in the background
.container-grid {
--columns: 6;
--gap: 1.5rem;
position: relative;
overflow: hidden;
display: grid;
grid-template-columns: repeat(var(--columns), 1fr);
grid-column-gap: var(--gap);
@signalwerk
signalwerk / convert.sh
Last active April 24, 2024 22:29
Convert a video to HLS format with multiple resolutions
#!/usr/bin/env bash
# Convert a video to HLS format with multiple resolutions
# Usage: ./convert.sh input.mp4
# current version:
# https://gist.github.com/signalwerk/5eaddbd2825501e4ea61784efbf84a31
# for more complex converting see also
# https://gist.github.com/mrbar42/ae111731906f958b396f30906004b3fa
@signalwerk
signalwerk / useFetch.js
Created January 10, 2024 22:59
Fetch a JSON and have the option to chancel the request
import { useState, useEffect } from "react";
const useFetch = (url, options) => {
const [response, setResponse] = useState(null);
const [error, setError] = useState(null);
const [loading, setLoading] = useState(false);
const abortController = new AbortController(); // Move abortController outside useEffect
useEffect(() => {
const signal = abortController.signal;
@signalwerk
signalwerk / count.sh
Last active August 8, 2023 15:53
Count code lines in git repo
#!/bin/bash
# run
# bash <(curl https://gist.githubusercontent.com/signalwerk/7b4411c13073da371b5d3d5d4d73cc9b/raw/count.sh)
# Define the output CSV file
output_csv="code_lines.csv"
# Header for the CSV file
echo "Commit,Year,Month,Date,Total Lines,Largest File" > "$output_csv"
@signalwerk
signalwerk / index.html
Last active June 2, 2023 11:58
Slideshow for Marc Rudin
<!DOCTYPE html>
<html>
<head>
<title>Marc Rudin</title>
<style>
body,
html {
margin: 0;
padding: 0;
height: 100%;
@signalwerk
signalwerk / form.js
Last active May 21, 2023 22:47
Conditional form handling based on JSON-Definiton
// Latest Vesrsion
// curl https://gist.githubusercontent.com/signalwerk/9802b92b6606d4ec2aca58d8f0def4be/raw/form.js > form.js
//
// Example:
//
// document.addEventListener("DOMContentLoaded", (event) => {
// const formCondition = document.querySelector("input[id$=condition]");
// if (formCondition) {
// form(JSON.parse(formCondition.value));
// }
@signalwerk
signalwerk / ChatGPT.mjs
Created April 29, 2023 18:24
Minimal ChatGPT request to the OpenAI-API
// This code sends a prompt to the OpenAI API and then outputs the response
// to the terminal and to a file.
// Setup:
// npm init -y && npm i dotenv node-fetch
// echo "OPENAI_API_KEY=sk-XXX" > .env
import fs from "fs";
import fetch from "node-fetch";
import * as dotenv from "dotenv";
@signalwerk
signalwerk / ip-print.js
Created April 29, 2023 18:10
Alternative IP notations
// alternative ip notations
// https://ma.ttias.be/theres-more-than-one-way-to-write-an-ip-address/
// https://twitter.com/h43z/status/1618220318023364608
dotNotationToDec({ ip: "185.15.230.26" }); // liip.ch;
dotNotationToDec({ prefix: "185.", ip: "15.230.26" });
/*
output:
dec http://3104826906/
@signalwerk
signalwerk / record.js
Last active March 31, 2024 16:00
Record from a canvas element to a webm file
// convert .webm to .mp4 and remove audio
// ffmpeg -i in.webm -vcodec h264 -an out.mp4
function dateString() {
const now = new Date();
return (
now.getUTCFullYear() +
"-" +
("0" + (now.getUTCMonth() + 1)).slice(-2) +
@signalwerk
signalwerk / template.js
Last active April 29, 2023 18:31
Replace {{ values }} in String
// This is a basic templating function. It replaces any {{key}} in the
// string with the corresponding value in data. If no data is provided,
// then the template is returned as-is.
//
// Example:
// template("Hello, {{name}}!", { name: "John" }) → "Hello, John!"
// template("Hello, {{name}}!") → "Hello, {{name}}!"
export function template(string, data = {}) {
let out = string;