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 / tools.md
Last active February 6, 2024 14:12
Various free tools to get some jobs done...
@loopmode
loopmode / .zshenv
Last active September 28, 2023 14:15
nuke-ios - reset the ios workspace of a react-native project
# put this where you keep custom aliases and functions (e.g. ~/.bashrc or ~/.zshenv)
function nuke-ios() {
for arg in "$@"; do
if [[ "$arg" == "--help" ]] || [[ "$arg" == "-h" ]]; then
echo "nuke-ios: Resets the iOS workspace of a react-native project by deleting temporary artifacts."
echo
echo "Usage:"
echo " nuke-ios [options]"
echo
echo "Options:"
@loopmode
loopmode / inject-version.sh
Last active May 15, 2023 08:29
prepends a comment with version info, timestamp and git commit hash
#!/bin/sh
# prepends a comment with version info, timestamp and git commit hash
file="./build/embed.js"
timestamp=$(date '+%Y-%m-%d %H:%m:%S')
commithash=$(git rev-parse --short HEAD)
version=$(cat ./package.json | grep version -m 1 | sed 's/"version": "//' | sed 's/",//' | xargs)
buildinfo="$version $timestamp $commithash"
@loopmode
loopmode / get-version.sh
Last active February 9, 2024 10:43
some bash/sed helpers for getting version strings
# local: package version
package_version=$(cat package.json | grep version -m 1 | sed 's/"version": "//' | sed 's/",//' | xargs)
# git: package version
git_package_version=$(git show HEAD^^^:package.json | grep version -m 1 | sed 's/"version": "//' | sed 's/",//' | xargs)
# react-native: current android version
android_version=$(cat android/app/build.gradle | grep versionName | sed 's/versionName "//' | sed 's/"//' | xargs)
android_build=$(awk '/versionCode/ && !/versionCodes/ && /[0-9]+/ {gsub(/[^0-9]/, "", $2); print $2}' android/app/build.gradle)
@loopmode
loopmode / gzipped.sh
Created November 18, 2021 20:40
display gzipped size of files
# put this in your ~/.bashrc
gzipped() {
if [ -z $1 ]; then
echo "No file specified"
else
b=$(gzip -c $1 | wc -c)
echo "$b B"
KB=$(awk "BEGIN {printf \"%.2f\n\", $b/1024}")
echo "$KB KB"
MB=$(awk "BEGIN {printf \"%.2f\n\", $b/1024/1024}")
@loopmode
loopmode / MonacoSqlInput.tsx
Last active July 29, 2021 12:34
SQL editor with formatting, based on monaco-editor, plus material UI wrapper
import React from 'react';
import Editor from '@monaco-editor/react';
import { format } from 'sql-formatter';
export type InputEvent = { target: { name: string; value: string } };
export default function MonacoSqlInput({
value,
name = '',
height = 500,
@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');
@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 / 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 / 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.