Skip to content

Instantly share code, notes, and snippets.

View jens1101's full-sized avatar

Jens Tschirpig jens1101

View GitHub Profile
@jens1101
jens1101 / numberClamp.js
Created June 5, 2023 07:37
How to clamp numbers in JS
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);

Some apps are not signed and MacOS automatically quarantines them, because they might be malicious. Usually one would just need to right-click on the app and press open to bypass the warning, but that sometimes doesn't work. The sure- fire way to just get it to work is by removing the quarantine flag via the terminal:

xattr -d com.apple.quarantine /Applications/[app name].app
@jens1101
jens1101 / filename-and-dirname.js
Last active March 23, 2023 09:11
Common `import.meta.url` use cases
import { fileURLToPath } from "url";
import { dirname } from "path";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
@jens1101
jens1101 / index.html
Created September 21, 2022 13:54
Recolouring elements using SVG filters
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Title</title>
</head>
<body>
<h1>Recolouring Using SVG Filters</h1>
<!-- Filter created inside of an invisible SVG -->
@jens1101
jens1101 / index.html
Created March 30, 2022 12:44
Scaling an SVG shape from the center of the shape
<svg viewbox="0 0 300 300">
<rect id="my-rect" x="50" y="50" width="100" height="80" />
</svg>;
@jens1101
jens1101 / Fix gyp on MacOS.md
Last active March 23, 2023 08:55
Fix "gyp: No Xcode or CLT version" on MacOS

This error happens when the command line tools on MacOS are not installed correctly. Do the following to fix this problem:

  1. Test if the command line tools are working. Run:
    curl -sL https://raw.githubusercontent.com/nodejs/node-gyp/main/macOS_Catalina_acid_test.sh | bash
  2. If the above retruns something like "Command Line Tools not found" then run the following:
    sudo rm -rf $(xcode-select --print-path)

xcode-select --install

@jens1101
jens1101 / Array Filler Generator.js
Created January 30, 2020 07:34
JavaScript create an array of n size and fill it with random numbers
const n = 42
const array = [...Array(n)].map(() => Math.random())
@jens1101
jens1101 / generate-test-data.js
Last active June 26, 2018 05:59
Generate test data from the bacon ipsum API
async function generateTestData (paragraphs = null, columns = 10, addBlanks = true) {
let numParagraphs = parseInt(paragraphs)
if (Number.isNaN(numParagraphs)) {
numParagraphs = Math.floor(Math.random() * 6) + 1
}
const testData = await fetch(`https://baconipsum.com/api/?type=meat-and-filler&paras=${numParagraphs}`)
.then(response => response.json())
.then(data => data.join(' ').split(' ').filter(Boolean))
@jens1101
jens1101 / data-url.js
Created May 22, 2018 08:59
Save Blob as file in JavaScript
// In this file we use a data URL to represent a Blob. This basically base64
// encodes the Blob and puts that string in a URL. This has better compatibility
// with old browsers, but is limited to ~2MB.
const blob = getBlobFromSomewhere()
const reader = new FileReader()
reader.onload = function (event) {
const a = document.createElement('a')
a.href = event.target.result
@jens1101
jens1101 / component.js
Created October 5, 2017 07:29
Optional Angular bindings
var app = angular.module('testModulePleaseIgnore', [])
app.component('legalReferences', {
bindings: {
foo: '&?',
bar: '<?',
baz: '=?',
qux: '@?'
},
controller: function() {