Skip to content

Instantly share code, notes, and snippets.

Avatar

Jovica Aleksic loopmode

  • ETECTURE
  • Fulda, Frankfurt
View GitHub Profile
@loopmode
loopmode / gzipped.sh
Created Nov 18, 2021
display gzipped size of files
View gzipped.sh
# 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 Jul 29, 2021
SQL editor with formatting, based on monaco-editor, plus material UI wrapper
View MonacoSqlInput.tsx
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 Mar 18, 2021
react highlight words
View Highlighted.js
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 / example.sh
Created Mar 4, 2021
abs_path for bash
View example.sh
#!/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 / example.js
Last active Feb 16, 2021
Better console.trace
View example.js
// 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 Nov 11, 2020
Bookmarklet: Gitlab Secrets
View gitlab-secrets-bookmarklets.md

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 / hosts
Created Oct 6, 2020
genymotion hosts file
View hosts
10.0.3.2 localhost
@loopmode
loopmode / replace-audio.sh
Created Jul 11, 2020
replace audio in video files without re-encoding
View replace-audio.sh
#!/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 / fullscreen.js
Created Jul 3, 2020
cross-browse rfullscreen utils
View fullscreen.js
// 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 / bp-query-by-json.js
Created Jun 9, 2020
bp query by json field (knex, sqllite vs postgres)
View bp-query-by-json.js
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`))
}