Skip to content

Instantly share code, notes, and snippets.

@tennox
tennox / get-links.js
Last active August 16, 2016 14:25
Phpwcms Backend File Downloader
@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 / 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 / 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 / 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 / object-field-mapper.js
Created June 4, 2020 09:51
JS Object field mapper
import _ from 'lodash'
/**
* Map fields of an object:
*
* ```
* ObjectUtils.mapFields(
* { a: 1, b: 2, c: 3, d: 4 },
* {
* a: num => num + 10,
@tennox
tennox / keybase.md
Created February 14, 2021 15:14
keybase.md

Keybase proof

I hereby claim:

  • I am tennox on github.
  • I am tennox (https://keybase.io/tennox) on keybase.
  • I have a public key ASDT0ovBTBQowbqsJSPKzUTNpf6Dw0-iCRqLAkAuwq1u4Qo

To claim this, I am signing this object:

@tennox
tennox / _castle.md
Last active June 16, 2021 09:33
Can you reach the throne?

Can you reach the throne?

You (brian) are allowed to change the cleaning code, but nothing else.

Can you reach the throne?

JS Fiddle here

@tennox
tennox / gulpfile.js
Created October 2, 2021 16:00
Gulp task to downscale & convert images using sharp
const gulp = require('gulp')
const rename = require('gulp-rename')
const sharp = require('sharp')
var useAsync = require('gulp-use').async
export default function convertImages () {
return gulp
.src('static/original/uploads/*.*')
.pipe(useAsync(async function (file, next) {
try {
@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"