Skip to content

Instantly share code, notes, and snippets.

View loopmode's full-sized avatar

Jovica Aleksic loopmode

  • ETECTURE
  • Fulda, Frankfurt
View GitHub Profile
@loopmode
loopmode / App.tsx
Created April 15, 2020 10:06
use-electron-context-menu
/**
* example of making inspector menu item available on everything from the "root" component
*/
import { hot } from 'react-hot-loader/root';
import React from 'react';
import useContextMenu from './hooks/use-context-menu';
const App: React.FC = React.memo(() => {
@loopmode
loopmode / propellerhead-reason-junctions.bat
Last active November 8, 2022 08:21
Moving Propellerhead Reason to another disk to free space
# Reason 11 eats up lots of space for content files
# An easy solution is to move the contents to another drive and create symlinks to the new locations
# --- These steps/commands are for Windows ---
mkdir D:\Reason\_symlinks\AppData
mkdir D:\Reason\_symlinks\ProgramData
mkdir D:\Reason\_symlinks\UserData
mv "%USERPROFILE%\AppData\Roaming\Propellerhead Software" "D:\Reason\_symlinks\AppData"
mv "%USERPROFILE%\Music\Propellerhead Content" "D:\Reason\_symlinks\UserData"
@loopmode
loopmode / find_packages.sh
Last active May 25, 2020 12:35
Bash script to find folder paths of installed node packages by name
#!/bin/sh
# finds node packages installed in a given directory
# - takes a directory path and one or more package names
# - finds all package.json files in the directory that have a matching name
# - returns the paths to the package folders
#
# Usage example:
#
# $ find_installed_packages.sh ./project/.cache/ foo foo-utils
@loopmode
loopmode / botpress-query-by-json.js
Last active November 8, 2022 08:20
botpress query by json field (knex, sqllite vs postgres)
let query = bp.database('web_messages')
if (bp.database.isLite) {
query
.where('attr_fookey', 'like', `%foo_value%`)
.select(bp.database.raw(`web_messages.id, json_extract(web_messages.payload, '$.foo') as attr_fookey`))
} else {
query.whereRaw(`web_messages.payload ->>'foo' like '%foo_value%'`)
query.select(this.knex.raw(`web_messages.id`))
}
@loopmode
loopmode / fullscreen.js
Last active November 8, 2022 08:19
cross-browser fullscreen utils
// see https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API
/** @private */
const ERR_NO_API = 'The Fullscreen API not supported on this device';
export function requestFullscreen(elem) {
if (elem.requestFullscreen) {
elem.requestFullscreen();
} else if (elem.msRequestFullscreen) {
elem.msRequestFullscreen();
@loopmode
loopmode / replace-audio.sh
Created July 11, 2020 08:24
replace audio in video files without re-encoding
#!/bin/sh
# replace audio in a video file without re-encoding the video
# based on https://superuser.com/a/1096239
# CLI usage: ./replace-audio.sh video.mp4 audio.mp4 output.mp4
# interactive usage: run script, enter filenames when asked, confirm with ENTER
function run() {
@loopmode
loopmode / gitlab-secrets-bookmarklets.md
Last active November 11, 2020 20:06
Bookmarklet: Gitlab Secrets

gitlab secrets bookmarklets

Helper bookmarklets to display all keys and values of a gitlab secrets page in a single element. This way, you can copy them all in one go.

gitlab_secrets_bookmarklets

Why? Because otherwise, you'd have to select, copy and paste each key and value manually, which is tedious.

Not a common use case, but I needed this several times, e.g. when requested by project managers, or when you need to replicate deployments or builds on a different system or locally.

@loopmode
loopmode / console-trace-example.js
Last active November 8, 2022 08:19
Better console.trace
// Using console.trace in several places when debugging can be quite the PITA because it prints the entire
// stack directly to the output and makes it difficult to find and read other log messages
//
// this variant will print a neatly collapsed object with a "stack" property that you can manually expand when needed
console.log('>>', { trace: new Error().stack?.slice(12).split('\n') });
@loopmode
loopmode / macos-realpath.sh
Last active November 8, 2022 08:17
abs_path for bash
#!/bin/bash
# realpath is not available on mac os
# this might be a useful alternative
abs_path () {
echo "$(cd $(dirname "$1");pwd)/$(basename "$1")"
}
echo $(abs_path .)
@loopmode
loopmode / Highlighted.js
Created March 18, 2021 06:47
react highlight words
import React from 'react';
import escapeRegExp from 'lodash.escaperegexp';
// based on https://stackoverflow.com/a/47803998/368254
export function Highlighted({ children: text = '', highlight = '' }) {
if (!highlight.trim()) {
return <span>{text}</span>;
}
const regex = new RegExp(`(${escapeRegExp(highlight)})`, 'gi');