Skip to content

Instantly share code, notes, and snippets.

Avatar

szabolcs kurdi szkrd

View GitHub Profile
@szkrd
szkrd / test-utils-json.js
Created Sep 17, 2020
Make json snapshots less painful: replace functions/classes with their names (if possible), convert dates to numbers, remove undefined enumerable properties
View test-utils-json.js
function logObject(obj) {
let result = JSON.stringify(obj, null, 2);
let hr = '';
for (let i = 0; i < 80; i++) { hr += '-'; }
const lines = result.split('\n');
result = lines.map(line => line.replace(/^(\s+)"([a-zA-Z0-9_$]*)"/, '$1$2')).join('\n');
console.log(`${hr}{{{\n${result}\n}}}${hr}`);
}
function stringifyComplexObjects(obj) {
@szkrd
szkrd / huskify.sh
Last active Jul 14, 2020
force install husky (probably v4.x only)
View huskify.sh
#!/usr/bin/env bash
function addHook() {
echo -e "#!/bin/sh\n# husky" > .git/hooks/$1
echo '. "$(dirname "$0")/husky.sh"' >> .git/hooks/$1
chmod +x .git/hooks/$1
}
DIRNAME="$(basename "${PWD}")"
if [ "${DIRNAME}" = 'server' ] || [ "${DIRNAME}" = 'client' ]; then echo "Do not run this script in the server/client subdir!"; exit 1; fi
if [ ! -f ./node_modules/husky/package.json ]; then echo "Project has no husky?"; exit 2; fi
@szkrd
szkrd / downgrade-all-to-128k-mp3.sh
Created Jul 4, 2020
convert all music files recursively to 128k mp3 (and then use cloudbeats or evermusic to stream them)
View downgrade-all-to-128k-mp3.sh
#!/usr/bin/env bash
read -p "This will RECURSIVELY process all music files and downgrade them; are you sure? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1
fi
shopt -s nullglob
# recursively find all music files and then convert them one by one to 128k mp3
find . -type f -iname "*.mp3" -o -iname "*.flac" -o -iname "*.mpc" -o -iname "*.ogg" | while read file; do
cd "$(dirname "${file}")"
@szkrd
szkrd / checkLocaleJsonValidity.js
Created Mar 2, 2020
check if locale json file is valid or not (parsable and has unique jeys only) - since git merge may cause headaches
View checkLocaleJsonValidity.js
const fs = require('fs');
const path = require('path');
const dir = path.join(__dirname, '/../locales');
fs.readdir(dir, (err, files) => {
files.filter(fn => /\.json$/.test(fn)).forEach(fn => {
fs.readFile(path.join(dir, fn), (err, s) => {
s = s + '';
let lang = {};
try {
lang = JSON.parse(s);
@szkrd
szkrd / record-screen.sh
Created Feb 19, 2020
record window on x11 using ffmpeg
View record-screen.sh
#!/usr/bin/env bash
NOCOLOR='\e[0m'
RED='\e[0;31m'
GREEN='\e[0;32m'
YELLOW='\e[1;33m'
CYAN='\e[0;36m'
command -v ffmpeg >/dev/null 2>&1 || { echo >&2 "${RED}ffmpeg not installed!${NOCOLOR}"; exit 1; }
echo -e "You can select a window for ${CYAN}fixed coordinates${NOCOLOR} in 3 seconds."
sleep 3
echo "Select window!"
@szkrd
szkrd / i18nForTests.js
Last active Oct 17, 2019
react-i18next detect missing keys during test
View i18nForTests.js
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import resources from '../locales/translations.json';
// we disable the translation texts for dev mode so that the
// tests would only break if an ID is missing but not
// if the translation has been changed by the translators.
const devTranslations = Object.keys(resources['en-US'].translation).reduce((acc, key) => {
acc[key] = key;
return acc;
@szkrd
szkrd / init-standard.sh
Created Jul 28, 2019
node standard seed (standard, eslint, prettier)
View init-standard.sh
#!/usr/bin/env bash
# EDITORCONFIG
# ============
echo "\
root = true
[*]
indent_style = space
@szkrd
szkrd / bandcamp-pls.js
Last active Jul 30, 2019
save bandcamp album tracks to a pls playlist
View bandcamp-pls.js
// save bandcamp album tracks to a pls playlist;
// mp3 file urls are protected by a token, so these playlist
// will "expire", but at least one can use a native player;
// still, please do read http://bandcamp.com/help/audio_basics#steal
// and http://bandcamp.com/terms_of_use
//
// ```
// mkdir bandcamp-pls && \
// cd bandcamp-pls && \
// npm init --yes && \
@szkrd
szkrd / ikbcf87.md
Last active Jan 1, 2020
IKBC F87 Backlit Keyboard Instruction
View ikbcf87.md

IKBC F87 Backlit Keyboard Instruction

  1. Time countdown with one key
  2. Different backlighting modes
  3. TKL 87 ANSI layout
  4. Double shot backlit keycaps
  5. Integrated with three layouts (QWERTY, DVORAK, COLEMAK)

Time countdown key modes

@szkrd
szkrd / autoConnect.ts
Last active Jul 19, 2020
react redux typescript fancy connect (with IDE code completion)
View autoConnect.ts
import store, { IState } from '../../actions'
import { connect } from 'react-redux'
const isFunc = (item) => typeof item === 'function'
const isNotFunc = (item) => !isFunc(item)
const filter = (obj, comp) => {
return Object.keys(obj).reduce((acc, key) => {
if (comp(obj[key])) {
acc[key] = obj[key]
}
You can’t perform that action at this time.