Skip to content

Instantly share code, notes, and snippets.

@mevanlc
mevanlc / gist:948d5277e85575def5bd1800a5603de6
Last active January 1, 2024 11:17
EBNF for broken `::` comments in dosbatch (SSCCE)
<file> ::= ( <statement> | <comment> | <block> )+
<statement> ::= <anytext>+ "\n"+
<comment> ::= "::" <anytext>+ "\n"+
<block> ::= "(" "\n"+ ( <comment> <statement> | <statement> | <block> )+ ")" "\n"+
<anytext> ::= #"[a-z0-9 ]"
<blockerror> ::= "{" "\n"+ ( <comment> <statement> | <statement> | <block> )+ "}" "\n"+

see https://mdkrajnak.github.io/ebnftest/

@mevanlc
mevanlc / global_local_inner_outer.sh
Created December 20, 2023 09:48
Testing the usage of global and local variables inside and outside functions in a number of combinations
#!/bin/sh
decl_outside="assigned outside a function"
echo "printing from outside: \$decl_outside: value before assignment INSIDE a function: [$decl_outside]"
INSIDE1() {
echo "printing from INSIDE1(): \$decl_outside: value before assignment by INSIDE1(): [$decl_outside]"
decl_outside="assigned by INSIDE1()"
echo "printing from INSIDE1(): \$decl_outside: value after assignment by INSIDE1(): [$decl_outside]"
@mevanlc
mevanlc / install_z_sh.sh
Last active February 24, 2024 11:23
Helper script to install z.sh (jump around) - https://github.com/rupa/z
#!/bin/sh
SOURCE_URL="https://raw.githubusercontent.com/rupa/z/master/z.sh"
OUTPUT_LOC="$HOME/.z.sh"
usage_doc="Usage: $0 [-h] [-u url] [-o file]
-h this help
-u <url> download from <url>
default: $SOURCE_URL
-o <file> download to <file>
@mevanlc
mevanlc / cmdhere.reg
Last active May 8, 2019 22:20
Add "Cmd Here" context-menu entry to Windows Explorer. Mnemonic hotkey is spacebar.
Windows Registry Editor Version 5.00
; After right-clicking on a folder in Windows Explorer,
; you can press spacebar to immediately execute Cmd Here and open a cmd prompt.
[HKEY_CLASSES_ROOT\Folder\shell\cmdhere]
@="Cmd& Here"
; By using pushd, we are able to open a cmd prompt on \\network\shares as an automatically mapped temporary drive letter.
; Make sure to use the "exit" command to close the command prompt, to automatically unmap the temporary drive.
[HKEY_CLASSES_ROOT\Folder\shell\cmdhere\command]
@="cmd /k \"cls&pushd \"%l\"\""
@mevanlc
mevanlc / winrenice.py
Last active May 9, 2019 08:28
In liu of a 'renice' cmdline utility on Windows. Requires Python and the https://github.com/giampaolo/psutil library.
#!/usr/bin/env python
# Copyright (c) 2019, Giampaolo Rodola', Michael Clark. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# https://github.com/giampaolo/psutil/blob/master/LICENSE
"""
In liu of a 'renice' cmdline utility on Windows.
$ winrenice chrome.exe below
@mevanlc
mevanlc / gpg_agent_daemon_bashrc.sh
Last active May 8, 2019 16:10
Reusing gpg-agent across login sessions (bashrc) on a headless server
# Run:
# sudo apt-get install gnupg-agent
# sudo apt-get install pinentry-curses
# Edit:
# $HOME/.gnupg/gpg-agent.conf:
# pinentry-program /usr/bin/pinentry-curses
# default-cache-ttl 28800000
# max-cache-ttl 28800000
# Edit:
# $HOME/.subversion/config:
@mevanlc
mevanlc / search_and_replace.jse
Created May 15, 2018 22:07
Microsoft JScript - Search and replace in a text file using regex
try
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var shell = new ActiveXObject("WScript.Shell");
var READ = 1, WRITE = 2, APPEND = 8;
var TEXT_DEFAULT = -2, TEXT_UNICODE = -1, TEXT_ANSI = 0;
var argc = WScript.Arguments.Count();
if (argc < 4)
{