Skip to content

Instantly share code, notes, and snippets.

View felixhaeberle's full-sized avatar
🫖
I like tea

Felix Häberle felixhaeberle

🫖
I like tea
View GitHub Profile
@felixhaeberle
felixhaeberle / merge.js
Created October 10, 2023 12:36
Merge languages files (JSON) to inlang message format
// Execute with `node merge.js`
// WARNING: This script does currently not support VariableReferences / variables in your text
import fs from "node:fs"
import path from "node:path"
const inputDirectory = "./" // Replace with your actual directory path
const outputFile = "messages.json"
const messages = {
@felixhaeberle
felixhaeberle / timeAgo.ts
Last active July 13, 2023 13:56
TypeScript: Get time distance as human readable string
// takes either a unix time number, string or a Date object and returns time string
export const timeAgo = (time: number | string | Date) => {
switch (typeof time) {
case "number":
break;
case "string":
time = +new Date(time);
break;
case "object":
@felixhaeberle
felixhaeberle / getPolarAngle.ts
Created June 9, 2022 14:09
JavaScript: Calculate polar angle in degree (φ) from a cursor position and a midpoint center
// Read this article for full understanding: https://de.serlo.org/mathe/45643/polarkoordinaten
// We need two coordinates for this calculation: the cursor coordinate and midpoint coordinate.
// How the sricpt works:
// 1. It calculates the distance between the points
// 2. It calculates the polar angle (in degree)
// 3. If the coordinates are overlapping, it calculates the edge cases also.
// It returns the polar angle as a number
<!--
- 1. Preemptively warm up the fonts’ origin.
-
- 2. Initiate a high-priority, asynchronous fetch for the CSS file. Works in
- most modern browsers.
-
- 3. Initiate a low-priority, asynchronous fetch that gets applied to the page
- only after it’s arrived. Works in all browsers with JavaScript enabled.
-
- 4. In the unlikely event that a visitor has intentionally disabled
@felixhaeberle
felixhaeberle / age.twig
Created January 24, 2020 00:11
Twig calculate age based on birthday date
{% set age = date().diff(date(item.birthday)).y %}
@felixhaeberle
felixhaeberle / d8-drush-css-js-aggregation-turn-on-off.sh
Created May 18, 2018 14:09
Drupal 8 drush css js aggregation turn on off
# Drupal 8
# Turn off CSS aggregation
drush -y config-set system.performance css.preprocess 0
# Turn on CSS aggregation
drush -y config-set system.performance css.preprocess 1
# Turn off JS aggregation
drush -y config-set system.performance js.preprocess 0
@felixhaeberle
felixhaeberle / d7-drush-css-js-aggregation-turn-on-off.sh
Last active May 18, 2018 14:11
Drupal 7 drush css aggregation turn on off
# Drupal 7
# Turn on JS Aggregation
drush vset preprocess_js 1 --yes
# Turn off JS Aggregation
drush vset preprocess_js 0 --yes
# Turn on CSS Aggregation
drush vset preprocess_css 1 --yes
@felixhaeberle
felixhaeberle / .gitignore
Created May 2, 2018 09:04
Drupal 8.x .gitignore
# Ignore configuration files that may contain sensitive information.
sites/*/*settings*.php
# Ignore paths that contain generated content.
files/
sites/*/files
sites/*/private
# Ignore default text files
robots.txt
@felixhaeberle
felixhaeberle / .gitignore
Created May 2, 2018 08:52
Drupal 7.x .gitignore
# Ignore configuration files that may contain sensitive information.
*/sites/*/settings*.php
*/sites/*/*.settings.php
*/sites/local.sites.php
# Ignore paths that contain user-generated content.
*/sites/*/files
*/sites/*/private
# Ignore editor specific files.
@felixhaeberle
felixhaeberle / keybase.md
Created December 30, 2017 11:18
keybase.md

Keybase proof

I hereby claim:

  • I am felixhaeberle on github.
  • I am fhaeberle (https://keybase.io/fhaeberle) on keybase.
  • I have a public key whose fingerprint is A14E 6530 ABAA CB23 6F9B 9B29 FF27 F971 A214 516B

To claim this, I am signing this object: