Skip to content

Instantly share code, notes, and snippets.

@izimbra
izimbra / gist:03b95637570019b082edadc70b545ed6
Last active August 9, 2021 12:49
Export YAML values as environment variables
# ignore comments and empty lines
sed '/^#/d;/^\s/d;s/: /=/g'
@izimbra
izimbra / migrate_cucm_phone_records.py
Last active September 28, 2016 06:59
Converts phone records between different versions of CUCM (tested with 10.5 and 11.0). 'source.csv' - phone records exported from initial CUCM, 'dest.csv' - phone record template exported from the new CUCM (should contain field names). Data from 'source.csv' is copied to 'dest.csv' with deprecated fields being deleted, and new fields left empty.…
src = open('source.csv', 'r')
dest = open('dest.csv', 'a+')
# 2 arrays to represent CUCM phone records
cucm10 = src.readline().rstrip().split(',')
cucm11 = dest.readline().rstrip().split(',') #map(lambda s: s.rstrip(),
# fields that were added in CUCM 11
new = set(cucm11) - set(cucm10)
@izimbra
izimbra / Network drive access for elevated apps
Last active September 28, 2016 06:49
Allow access to mapped network drives from elevated apps (Windows Vista and later) #win #uac #network
reg add «HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System» /v «EnableLinkedConnections» /t REG_DWORD /d 0x00000001 /f
@izimbra
izimbra / Default CMD folder in admin mode
Created May 12, 2016 12:14
Set default folder for CMD run in administrator mode #win #cmd
REG ADD "HKCU\SOFTWARE\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "CD /D C:\Path\To\Folder"
@izimbra
izimbra / delayedexp.cmd
Last active September 28, 2016 06:50
Set variable values inside for-loop.
@echo off
:: enable delayed expansion to set variable values inside for-loop
:: usual %VAR% syntax won't work, use !VAR! instead
setlocal EnableDelayedExpansion
for %%A in (%*) do (
set _PARAM=%%A
set _PREFIX=!_PARAM:~0,3!
if /i !_PREFIX!==SearchString (
set LIST_VAR=!LIST_VAR! !_PARAM!
@izimbra
izimbra / Replace first occurrence of a string with sed
Created October 26, 2013 11:37
Replaces first occurrence of a string in a file using sed. This was tried and worked in OS X 10.9. #osx #shell #sed
sed '1,/string/ s/string/replacement/' file
@izimbra
izimbra / Replace quoted string in a file with sed
Created October 26, 2013 11:32
Globally replaces a quoted string (preceded with SOMETHING=) in a file1 using sed. The result is saved in file2. This was tried and worked in OS X 10.9. #sed #osx #shell
sed 's/SOMETHING="[^"]*"/SOMETHING="XXX"/g' file1 > file2
@izimbra
izimbra / Kill processes by name in Win command prompt
Created August 20, 2013 14:27
Kills all running processes with the specified name. This was tried in Windows 7. #win #batch #wa
taskkill /F /IM SomeExecutable.exe
@izimbra
izimbra / Toggle OS X desktop icons
Last active December 18, 2015 22:59
This toggles visibility of desktop icons in OS X. #osx #shell
defaults write com.apple.finder CreateDesktop -bool false | true
killall Finder
@izimbra
izimbra / Print HTTP request parameters
Created May 31, 2013 11:50
Prints out names and values of parameters of a HTTP request. Useful for using in conditional breakpoints in Eclipse. Since 'false' is returned, this code will only print values, but will not suspend execution. #java #eclipse #http
System.out.println("Request params:");
java.util.Enumeration paramNames = request.getAttributeNames();
while (paramNames.hasMoreElements()) {
java.lang.String name = (java.lang.String) paramNames.nextElement();
java.lang.Object values = request.getAttribute(name);
System.out.println("\t" + name + ": " + values);
}
return false;