Skip to content

Instantly share code, notes, and snippets.

@mals14
mals14 / how to quote for command line usage - library support in python.md
Last active June 14, 2020 13:40
how to quote for command line usage - library support in python

how to quote for command line usage - library support in python

  • shlex — Simple lexical analysis — Python 3.8.3 documentation Link
@mals14
mals14 / sort dictionaries in python.md
Created June 14, 2020 13:23
sort lists of dictionaries in python

Sorting Lists of Dictionaries

Frequently you want to sort a list of dictionaries, based on some particular key.

Source: SortingListsOfDictionaries - Python Wiki Link

@mals14
mals14 / javascript examples - select based on xpath and extract text value.js
Last active June 13, 2020 14:52
javascript examples - select based on xpath and extract text value
// javascript examples - select based on xpath and extract text value
var getXPath = '//div[contains(@class, "CopyToClipBoardInput")]/input';
var nodes = document.evaluate(getXPath, document, null, XPathResult.ANY_TYPE, null);
var getElem = nodes.iterateNext();
getElem.value // or is it getElem.valueOf
var getXPath = "//div[contains(@class, 'ContactInfoCallModal-phone')]//div";
@mals14
mals14 / xpath examples.md
Last active June 13, 2020 12:13
xpath examples

xpath examples

Example to select using text and then to get following-sibling

  • //*[text()[contains(.,'Days listed')]]
  • //*[text()[contains(.,'Days listed')]]//following-sibling::div
@mals14
mals14 / delete keyboard maestro variables.applescript
Created June 11, 2020 21:55
delete keyboard maestro variables applescript
# applescript script to delete variables
tell application "Keyboard Maestro Engine"
set to_delete to {"my_email", "first_name", "last_name", "my_mobile"}
repeat with my_var in to_delete
setvariable (my_var as text) to "%Delete%"
end repeat
# set value of variables whose name starts with "minst" to "%Delete%"
end tell
@mals14
mals14 / Automating a javascript button click based on element's XPath.js
Last active June 8, 2020 12:37
Automating a javascript button click based on element's XPath
Title: Automating a javascript button click based on element's XPath
Source: https://stackoverflow.com/a/49084290/3973491
html:
<div>
<a href="#" onclick="alert('ok')">
<img src="">
</a>
</div>
@mals14
mals14 / examples find command bash shell.sh
Last active June 7, 2020 21:30
examples find command bash shell
# sourced from: https://alvinalexander.com/unix/edu/examples/find.shtml
find . -type f -maxdepth 2 -name "*.py" -exec grep -l richxerox {} \;
-maxdepth 1 # searches only in the directory specified
basic 'find file' commands
--------------------------
find / -name foo.txt -type f -print # full command
find / -name foo.txt -type f # -print isn't necessary
@mals14
mals14 / applescript resize Finder windows.applescript
Created June 7, 2020 16:54
applescript resize Finder windows.applescript
# ideas from New Finder windows - Questions & Suggestions - Keyboard Maestro Discourse
# https://forum.keyboardmaestro.com/t/new-finder-windows/3048/2
# to merge current windows
(* what is being done here
Check if Finder windows exist.
If two windows exist, then set them to be in bound1 and bound2.
If more than one window exists, then merge them all. Copy the active tab. Close the active tab. Set bounds to bound1.
Then open a new window with active tab path. Set bounds to bound2.
@mals14
mals14 / get date YYYY-MM-DD from string regular expression.py
Last active June 6, 2020 23:38
get date YYYY-MM-DD from string regular expression.py
def get_date_s_from_string(s):
"""extract YYYY-MM-DD from string formatted YYYY-MM-DD_...
Returns:
[type] -- [description]
"""
re_pattern = '\d{4}-\d{2}-\d{2}'
return re.search(re_pattern,s)[0]
@mals14
mals14 / keyboard maestro applescript make variable
Last active June 5, 2020 15:30
keyboard maestro applescript make variable
tell application "Keyboard Maestro Engine"
make variable with properties {name:"TaskNote", value:task_note}
make variable with properties {name:"TaskName", value:task_name}
end tell