Skip to content

Instantly share code, notes, and snippets.

@tennox
tennox / main.js
Last active May 21, 2020 12:01
Currency.js override with custom defaults
import currency from 'currency.js';
// Library docs: https://currency.js.org/
// We create a custom constructor with custom config here
export function customCurrency(value, options) {
if (value === null || value === undefined) return value; // I don't like that it returns 0.00
if (!(this instanceof customCurrency)) { // this enables calling the function without 'new'
return new customCurrency(value, options);
@tennox
tennox / deepDiffObj.js
Last active September 15, 2022 02:30 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
import _ from 'lodash';
/**
* Deep diff between two objects - i.e. an object with the new value of new & changed fields.
* Removed fields will be set as undefined on the result.
* Only plain objects will be deeply compared (@see _.isPlainObject)
*
* Inspired by: https://gist.github.com/Yimiprod/7ee176597fef230d1451#gistcomment-2565071
* This fork: https://gist.github.com/TeNNoX/5125ab5770ba287012316dd62231b764/
*
@tennox
tennox / gitlab-ci_script-from-variable.yml
Last active November 23, 2021 05:58
Use code from GitLab environment variable safely in bash and remote SSH
.ssh_deploy_template: &ssh_deploy_template
# TEMPLATE - see https://docs.gitlab.com/ee/ci/yaml/README.html#anchors
# ...
# Here's the magic to get the code from the GitLab variable into a bash variable and then even executed on an SSH session
script:
# Put gitlab variable into shell variable to improve quote handling
- CMD=$SCRIPT_CMD
# Print for debugging
- echo -e "Executing:\n$CMD"
@tennox
tennox / test-meteor-db-migration-against-ref.sh
Created October 3, 2019 22:53
Reset and initialize Meteor DB on a git ref and start the app again afterwards
#!/bin/bash
set -e
#################################################
if [[ $# -ne 1 ]]; then
echo "This script:"
echo "1. resets and initializes the DB on the specified commit/branch"
echo "2. goes back to the codebase you ran this script from"
echo "3. runs the app again"
echo
@tennox
tennox / TestResourceLoad.java
Last active December 6, 2018 11:21
Spring load file from resources or from file system
public void testResourceLoad(ResourceLoader resourceLoader) {
System.out.println("resourceLoader k:" + resourceLoader.getResource("keycloak.json").exists());
System.out.println("resourceLoader /k:" + resourceLoader.getResource("/keycloak.json").exists());
System.out.println("resourceLoader c:k:" + resourceLoader.getResource("classpath:keycloak.json").exists()); // dev
System.out.println("resourceLoader c:/k:" + resourceLoader.getResource("classpath:/keycloak.json").exists()); // dev
System.out.println("resourceLoader f:k:" + resourceLoader.getResource("file:keycloak.json").exists()); // jar
System.out.println("resourceLoader f:/k:" + resourceLoader.getResource("file:/keycloak.json").exists());
System.out.println("getClass() k:" + getClass().getResource("keycloak.json"));
System.out.println("getClass() /k:" + getClass().getResource("/keycloak.json")); // dev
System.out.println("getClass() c:k:" + getClass().getResource("classpath:keycloak.json"));
@tennox
tennox / elementary-fish-task-completion-notification.fish
Last active October 3, 2019 23:39
Elementary OS Loki Task complete notification for fish shell
# ! install xdotool first - it is needed to check if the terminal is in foreground (or disable that if you don't want)
# then append this to ~/.config/fish/config.fish (create it if not existent)
function alert_cmd_done --on-event fish_postexec
set status_code $status # save for later
set active_window (ps -p (xdotool getwindowpid (xdotool getactivewindow)) -o comm=) # get the process name of the currently active window
if status --is-interactive # Check for interactive session (keyboard attached)
if [ $active_window != "pantheon-termin" -a \
$CMD_DURATION -a \
$CMD_DURATION -gt (math "1000 * 5") ] # in background, after a job longer than 5 seconds
@tennox
tennox / get-links.js
Last active August 16, 2016 14:25
Phpwcms Backend File Downloader