Skip to content

Instantly share code, notes, and snippets.

@maphew
maphew / find-leo-lib-using-leo.py
Last active February 28, 2019 06:37
Snippets for finding Leo's library path (ie: ./leo-editor/leo or PYTHONHOME/Lib/site-packages/leo)
# import pdb ; pdb = pdb.set_trace
import os
import sys
# Partial fix for #541.
# See https://stackoverflow.com/questions/24835155/pyw-and-pythonw-does-not-run-under-windows-7/30310192#30310192
if sys.executable.endswith("pythonw.exe"):
sys.stdout = open(os.devnull, "w");
sys.stderr = open(
os.path.join(os.getenv("TEMP"),
"stderr-"+os.path.basename(sys.argv[0])),
@maphew
maphew / win10-start-remove-internet-results.reg
Last active December 28, 2024 04:41
Disable internet search results in Win 10 Start Menu
Windows Registry Editor Version 5.00
;
; How to disable internet search results in start menu post Creators Update?
; https://superuser.com/questions/1196618/how-to-disable-internet-search-results-in-start-menu-post-creators-update
;
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Search]
"BingSearchEnabled"=dword:00000000
"AllowSearchToUseLocation"=dword:00000000
"CortanaConsent"=dword:00000000
;
@maphew
maphew / tb-edit.html
Created April 19, 2019 06:27
trumbowyg editor via cdn test
<html>
<head>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/Trumbowyg/2.15.2/ui/trumbowyg.min.css">
</head>
<body>
<div id="editor">
$('#trumbowyg-demo').trumbowyg();
</div>
Adapted from https://alex-d.github.io/Trumbowyg/documentation/
$ pip uninstall shortcutter
Uninstalling shortcutter-0.1.20:
Would remove:
c:\tools\miniconda3\envs\test\lib\site-packages\shortcutter-0.1.20.dist-info\*
c:\tools\miniconda3\envs\test\lib\site-packages\shortcutter\*
c:\tools\miniconda3\envs\test\scripts\shortcutter.exe
c:\users\me\appdata\roaming\microsoft\windows\start menu\programs\shortcutter.lnk
d:\test-link.lnk
Proceed (y/n)? y
ERROR: Exception:
@maphew
maphew / snips-windows.py
Created August 28, 2019 19:54
Windows python snippets
def get_exe_types():
'''Return list of valid executable file extensions [.com, .exe, ...]'''
exetypes = [ext.lower() for ext in os.environ['PATHEXT'].split(os.pathsep)]
return exetypes
@maphew
maphew / list-user-special-folders.py
Last active September 7, 2019 05:16
Windows user "special folders" (Desktop, Start Menu, Documents, ...) info by enumerating constants from MS published list
'''List all User Shell Folders via ID number.
An alternative to the usual
objShell = win32com.client.Dispatch("WScript.Shell")
allUserProgramsMenu = objShell.SpecialFolders("AllUsersPrograms")
because "These special folders do not work in all language locales, a preferred
method is to query the value from User Shell folders"
@maphew
maphew / add-recent-branches-list.sh
Last active November 19, 2019 17:43
Git shallow clone: only branches with recent activity, as determined by Github
# from https://stackoverflow.com/questions/58702233/git-shallow-clone-only-branches-with-activity-last-x-months
export URL=https://github.com/leo-editor/leo-editor/branches/active
curl $URL > x.html
printf '\n-- Commands to add the remote branches to the fetch list:\n'
grep 'data-branch-name' x.html | sed -r 's/^.*data-branch-name="(.*?)"(.*$)/git remote set-branches --add origin \1/'
printf '\n-- Modification dates for these branches:\n'
grep 'time-ago' x.html | sed -r 's/^.*datetime="(....-..-..).*$/\1/'
@maphew
maphew / arcpy-overhead.py
Last active March 11, 2020 13:00
What is your "import arcpy" overhead?
'''Measure and report the time it takes to simply `import arcpy`
Part of https://community.esri.com/message/914048-re-what-is-your-import-arcpy-overhead?
'''
from timeit import default_timer as timer
start = timer()
from datetime import datetime, timedelta
from uuid import uuid4
eventid = datetime.now().strftime('%Y%m-%d%H-%M%S-') + str(uuid4())
@maphew
maphew / console-log.md
Last active March 17, 2020 04:53
Leo scripts to manage History Tracer plugin daemon

An edited excerpt from the console which started Leo

don't forget to launch leo-ver-serv!!!
==== @int history-tracer-port=8088 ====
Looking for 'leo-ver-serv' processes...
   PID   Name                   Status    
  3815   leo-ver-serv           sleeping  
========================================

This is just after Leo startup.

@maphew
maphew / History Tracer.xml
Last active July 11, 2020 08:23
WIP: management scripts for History Tracer plugin for Leo
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo: http://leoeditor.com/leo_toc.html -->
<leo_file xmlns:leo="http://leoeditor.com/namespaces/leo-python-editor/1.1" >
<leo_header file_format="2"/>
<vnodes>
<v t="mhw.20200710235109.1"><vh>History Tracer</vh>
<v t="mhw.20200308223025.1"><vh>@int history-tracer-port=8088</vh></v>
<v t="mhw.20200710235122.1"><vh>@button leo-ver-serv-start</vh></v>
<v t="mhw.20200710235134.1"><vh>@button leo-ver-serv-list</vh></v>
<v t="mhw.20200710235410.1"><vh>@button leo-ver-serv-stop</vh></v>