Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / example of how to insert a dictionary into sqlite database.py
Created June 14, 2020 16:15
example of how to insert a dictionary into sqlite database python
# example of how to insert a dictionary into sqlite database
# suorce - https://stackoverflow.com/questions/10913080/python-how-to-insert-a-dictionary-to-a-sqlite-database
def post_row(conn, tablename, rec):
keys = ','.join(rec.keys())
question_marks = ','.join(list('?'*len(rec)))
values = tuple(rec.values())
conn.execute('INSERT INTO '+tablename+' ('+keys+') VALUES ('+question_marks+')', values)
@mals14
mals14 / sleep pause capability in javascript.md
Last active June 19, 2020 02:33
sleep pause capability in javascript.md

sourced from: What is the JavaScript version of sleep()? - Stack Overflow Link

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

async function demo() {
  console.log('Taking a break...');
  await sleep(2000);
 console.log('Two seconds later, showing sleep in a loop...');