Skip to content

Instantly share code, notes, and snippets.

View tennox's full-sized avatar
💭
mainly on gitlab.com/txlab

Manuel tennox

💭
mainly on gitlab.com/txlab
View GitHub Profile
@tennox
tennox / sanitize.js
Created November 29, 2021 14:43
Sanitize string & filename
const _ = require('lodash')
const sanitize = str => _.chain(str)
.replace(/[^A-Za-z0-9&.-]/g, '-') // sanitise via whitelist of characters
.replace(/-(?=-)/g, '') // remove repeated dashes - https://regexr.com/6ag8h
.trim('-') // trim any leading/trailing dashes
.truncate({
length: 40, // max length
omission: '-' // when the string ends with '-', you'll know it was truncated
})
@tennox
tennox / basic_cmd.sh
Last active January 21, 2022 04:10
Github latest release download
# basic bash command
wget $(curl -s https://api.github.com/repos/filiph/linkcheck/releases/latest \
| jq -r '.assets | .[] | select(.name|contains("linux-x64.tar.gz")) | .browser_download_url')
@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 / _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 / 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 / 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 / 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 June 26, 2024 19:52
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