Skip to content

Instantly share code, notes, and snippets.

@maphew
maphew / create_hardlink.py
Last active December 16, 2015 06:19
Create file hardlinks in python in a platform independent way. [untested] Courtesy of Dieter Deyke, http://www.gossamer-threads.com/lists/python/python/517542#517542
@maphew
maphew / install-pip.py
Last active December 16, 2015 06:49
A pure python script to download and install the distribute_setup and pip utilities. Tested on Windows 7, Python 3.2.
"""
pip-install.py
A pure python script to download and install the distribute_setup and
pip utilities
Adapted from:
http://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows/15294806#15294806
http://stackoverflow.com/questions/2792650/python3-error-import-error-no-module-name-urllib
http://stackoverflow.com/questions/1093322/how-do-i-check-what-version-of-python-is-running-my-script
@maphew
maphew / push_to_gist.py
Last active April 19, 2020 16:34 — forked from anonymous/push_to_Gist.txt
=== Leo editor script to publish from a node to Gist === At present everything is done anonymously, so there's no way to delete an old push, or make the next a push a revision to a previous one. In other words it's trivial to create **many** duplicates. So I wouldn't actually use this yet; it's just proof of concept (and wickedly easy!).
import requests
import json
description = "published from Leo" # todo: derive from docstring, if present, otherwise 1st para
public = True
filename = p.h # node headline
content = p.b # node body
api_url = 'https://api.github.com/gists'
@maphew
maphew / Run Elevated.xml
Last active December 18, 2015 05:39
An experimental Leo button which executes the currently selected node as a python script after invoking User Account Control (UAC). Not fully functional yet -- and dangerous. You could easily bork all your data or even your computer with this: it runs code with admin privileges, no sanity checking, and very limited feedback. Tracebacks etc. are …
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo (http://webpages.charter.net/edreamleo/front.html) -->
<?xml-stylesheet ekr_test?>
<leo_file xmlns:leo="http://www.leo-editor.org/2011/leo" >
<leo_header file_format="2"/>
<vnodes>
<v t="maphew.20130607222534.1739" a="E"><vh>@button Run Elevated</vh>
<v t="maphew.20130608014320.1983"><vh>docstring</vh></v>
<v t="maphew.20130608014320.1743"><vh>imports</vh></v>
<v t="maphew.20130608014320.1744"><vh>Leo preparation</vh></v>
@maphew
maphew / RunElevated-test.xml
Created June 10, 2013 07:36
a test node for Run Elevated leo button script -- https://gist.github.com/maphew/5734699
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo (http://webpages.charter.net/edreamleo/front.html) -->
<?xml-stylesheet ekr_test?>
<leo_file xmlns:leo="http://www.leo-editor.org/2011/leo" >
<leo_header file_format="2"/>
<vnodes>
<v t="maphew.20130608014320.1741"><vh>Run Elevated test</vh></v>
</vnodes>
<tnodes>
<t tx="maphew.20130608014320.1741">import os, sys
@maphew
maphew / rst-tutorial-example
Created October 31, 2013 21:29
An expanded version of the example used in the Leo RST tutorial, http://leoeditor.com/tutorial-rst3.html. You can open it via CheatSheet.leo from Leo’s help menu.
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo (http://leoeditor.com/leo_toc.html) -->
<?xml-stylesheet ekr_test?>
<leo_file xmlns:leo="http://www.leo-editor.org/2011/leo" >
<leo_header file_format="2" tnodes="0" max_tnode_index="0" clone_windows="0"/>
<globals body_outline_ratio="0.5" body_secondary_ratio="0.5">
<global_window_position top="50" left="50" height="500" width="700"/>
<global_log_window_position top="0" left="0" height="0" width="0"/>
</globals>
<preferences/>
@maphew
maphew / simple_tissot.topojson
Created December 21, 2013 00:13
Tissot error ellipses (simple kind, not accurate)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
; 2014-Feb-27: as seen at http://www.autohotkey.com/board/topic/102227-gmailkeys-for-outlook-2013/
;*******************************************************************************
; Information
;*******************************************************************************
; AutoHotkey Version: 3.x
; Language: English
; Platform: XP/Vista/7
; Updated by: Toby Garcia
; Previously updated by: Ty Myrick
@maphew
maphew / apt-dev_2014-Nov-01.leo
Created November 4, 2014 18:12
apt-dev.leo 2014 Oct-31 and Nov-01
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo: http://leoeditor.com/leo_toc.html -->
<?xml-stylesheet ekr_test?>
<leo_file xmlns:leo="http://leoeditor.com/namespaces/leo-python-editor/1.1" >
<leo_header file_format="2" tnodes="0" max_tnode_index="0" clone_windows="0"/>
<globals body_outline_ratio="0.5" body_secondary_ratio="0.5">
<global_window_position top="50" left="50" height="500" width="700"/>
<global_log_window_position top="0" left="0" height="0" width="0"/>
</globals>
<preferences/>
import sys
debug = True
def exceptionHandler(exception_type, exception, traceback, debug_hook=sys.excepthook):
'''Print user friendly error messages normally, full traceback if DEBUG on.
Adapted from http://stackoverflow.com/questions/27674602/hide-traceback-unless-a-debug-flag-is-set
'''
if debug:
print '\n*** Error:'
# raise