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 / windows-kill.bashrc
Last active November 8, 2022 08:23
"kill" function for git bash on windows
kill() {
local name="${1}"
if [ -z "$name" ];
then
echo ">> Enter a process name and press [ENTER] (partial matching)"
read name
fi
wmic process where "name like '%$name%'" delete
}
@loopmode
loopmode / get-dev-dependencies.js
Last active November 11, 2019 06:45
Node.js function to get the names of all devDependencies in a yarn or lerna workspace
module.exports = async function getDevDependencies(globs = ['package.json', 'packages/*/*.json']) {
const globby = require('globby');
const packageFiles = await globby(globs, { absolute: true });
return packageFiles.reduce((result, file) => {
const pkg = require(file);
if (pkg.devDependencies) {
const names = Object.keys(pkg.devDependencies);
return result.concat(names.filter(name => !result.includes(name)));
}
@loopmode
loopmode / renameObjKeys.js
Last active August 6, 2019 06:43
A JS function for renaming properties of an object while maintaining the original iteration order
export function renameObjKeys(obj, mapping) {
// based on https://stackoverflow.com/a/48110891/368254
const renameObjKey = (obj, { oldKey, newKey }) => {
const keys = Object.keys(obj);
const newObj = keys.reduce((acc, val) => {
if (val === oldKey) {
acc[newKey] = obj[oldKey];
} else {
acc[val] = obj[val];
}
@loopmode
loopmode / getGitlabSecrets.console.js
Last active August 21, 2019 12:09
printing Gitlab CI/CD variables as key/value pairs.
(function getGitlabSecrets() {
const secrets = [
...document.querySelectorAll('.ci-variable-row-body'),
].reduce((result, row) => {
const key = row.querySelector(
'[name="variables[variables_attributes][][key]"]',
).value;
const value = row.querySelector(
'[name="variables[variables_attributes][][secret_value]"]',
).value;
@loopmode
loopmode / dockerized-shell.bashrc
Last active November 8, 2022 08:22
dockerized ubuntu shell
dockerized-ubuntu() { dockerized ubuntu ubuntu:latest /bin/bash bash }
dockerized-curl() { dockerized curl pstauffer/curl:latest /bin/sh sh }
# based on https://stackoverflow.com/a/56690087/368254
dockerized()
{
name=$1
image=$2
containercmd=$3
runcmd=$4
// ----
// libsass (v3.5.4)
// ----
@mixin spacing-helpers(
$style,
$sizes: (0, 5, 10, 15, 20, 25, 30, 50),
$positions: ('', 'top', 'left', 'bottom', 'right')
) {
@each $size in $sizes {
@loopmode
loopmode / _variate.scss
Last active September 26, 2019 23:37
Sass mixin for creating margin and padding utils
// ------------------------------------------------------------------------
//
// @mixin variate($style, $sizes, $variations, $withUnits)
//
// creates a list of shortcut utitlity classes, with variations for each side
//
// Usage:
//
// variate(margin);
// variate(margin, (0em, 6em, 12em, 24em, 48em));
@loopmode
loopmode / use-context-menu.ts
Created October 19, 2019 08:21
Hook for displaying electron context menu for an element
import {
remote,
MenuItemConstructorOptions,
ContextMenuParams,
Event as ElectronEvent
} from 'electron';
import contextMenu from 'electron-context-menu';
import React from 'react';
@loopmode
loopmode / nuke.bashrc
Last active September 28, 2023 09:11
nuke: getting rid of stuff
# just delete all node_modules recursively without reinstalling
alias delete-node-modules='find . -name node_modules -type d -exec rm -rf "{}" + '
# delete all node_modules and reinstall via npm
nuke-npm() {
if [ "$1" == "-f" ]; then
rm -f package-lock.json
fi
find . -name node_modules -type d -exec rm -rf "{}" +
npm install
@loopmode
loopmode / machine.js
Last active March 16, 2020 07:35
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)