Skip to content

Instantly share code, notes, and snippets.

View dominikkaegi's full-sized avatar
🎯
Focusing

Dominik Kaegi dominikkaegi

🎯
Focusing
View GitHub Profile
// A simple Bookmarklet which calculates the time you have worked at a given day
// 1. Go to https://zeitplan.hcweb.ch
// 2. Log in and select the day you want to evaluate
// 3. Click on the Bookmarklet you created with the code below
// To pulish, first minify / uglify it before you throw it into the book
// marklet create:
// 1. Uglify https://skalman.github.io/UglifyJS-online/
// 2. Bokkmarkify: https://mrcoles.com/bookmarklet/
@dominikkaegi
dominikkaegi / eventloopQueuePrioritisation.js
Last active February 12, 2019 14:57
This gist showcases the prioritisation of the Microtask Queue over the Task Queue
/**
* Microtask Queue vs Task Queue
* Prioritisation between Microtask Queue (also named Job Queue) and Task Queue
*
* There are two queues for executing asynchronous javascript. The Micro Task queue has priority over the Task Queue.
* If you would keep on filling the micro task queue, you would block the code on the task queue.
* Asynchronous code which returns objects (like promises) are getting added to the Micro Task Queue.
* Asynchronous code which leave no trace (like setTimeout()) are getting added to the Task Queue.
*/
@dominikkaegi
dominikkaegi / Bash_Port_Utilities
Last active February 23, 2019 15:03
Utilities function to find and kill a process on a port easily
# Implemented and tested on MacOS
# Add utilties to ~./bash_profile to make them usable in your terminal
# ------------------- PORT UTILTIES ----------------------
# Find PID of process on a specific port
# param portNumber
# example: "findPortProcess 8080"
findPortProcess() {
portProcess="$(lsof -n -i4TCP:$1 | grep LISTEN)"
if [ "$portProcess" ]
PS1="🐑💨 \W doka$ "
# --------- GIT compleition ----------
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
# --------------- PYTHON ---------------
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
@dominikkaegi
dominikkaegi / Arrowfunction_Static_Binding.js
Last active February 21, 2019 11:36
This gist showcases the difference between the static binding of the `this context` with ES6 arrow functions and dynamic binding with declarative functions
// ES 6 Arrow Function vs Function
// showcases the difference between the static binding of the `this context`
// with ES 6 Arrow Function and dynamic binding with normal Functions
var obj = {
dynamicBinding() {
console.log('Dynamic Context: ', this)
window.setTimeout(function() {
console.log('T Dynamic Context: ', this),
0
@dominikkaegi
dominikkaegi / destructering.js
Last active February 14, 2020 22:36
An overview of destructing objects and arrays
// -----------------------------------------------------
// --------------- DESTRUCTERING ---------------
// -----------------------------------------------------
// ------- NON-NESTED ARRAYS ---------------
// Simple Destructering
function foo() {
return [1, 2, 3]
}
@dominikkaegi
dominikkaegi / Chaining_async_await.js
Created April 1, 2019 07:22
Structuring a class so that you can call async chained functions on the instantiation of it.
// Something to think about from this post :)
// https://stackoverflow.com/questions/55413162/how-to-use-function-chaining-with-async-function?noredirect=1#comment97547907_55413162
class Walker {
constructor(t) {
this.t = t;
// set up a task queue for chaining
this.task = Promise.resolve();
}
@dominikkaegi
dominikkaegi / TimeframeCreator.js
Created October 18, 2019 09:04
Creates a consecutive list of dates with a certain duration.
const AMOUNT_OF_DATES = 10;
const DURATION = 30;
var timeframes = []
var startDate = new Date("Fri Oct 18 2019 10:00:00 GMT+0200 (Central European Summer Time)")
for(let i = 0; i < AMOUNT_OF_DATES; i++) {
let timeframe = {
start: addMinutes(startDate, DURATION * i),
duration: DURATION
}
@dominikkaegi
dominikkaegi / jsObjectToJSON.js
Created November 8, 2019 12:47
Takes a JS Object and Turns it into a JSON object and writes it into a specified file.
const fs = require('fs');
function jsObjectToJSON(filename, data) {
const formattedString =JSON.stringify(data, null, 2)
fs.writeFile(filename, formattedString, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
@dominikkaegi
dominikkaegi / logTestIds.js
Last active November 12, 2019 16:33
Logs all data test ids with console.group. Within a group the reference to the element is available.
function logIds() {
function getDataTestIdElements() {
return document.querySelectorAll('[data-test-id]')
}
function toArray(elementList) {
return Array.from(elementList)
}
function toTagTestIdPair(item) {
return {
ref: item,