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2SRJS36T7VUV7ZCRWADJYNVIJ2OJYNQC
PNSLB3HLQELG4BZJYQB2T2R4ZFYQVPZHQZXAEOBCR4ZVMJ36LYNAC
62NYOA53SKXX2LYBVUZWGQ2HW4WH3BZBC62ODHQPJEYOYKRVWPVQC
PDGOEBKHWX4BPJZIU2HMZLL3347XWKQRRFTYBVEG6QR5FY5VTB6QC
H6LVUWP3WKFL7KDNKUEZYJQONP3NZ2IUUTK4TCWQ6ULUZRZ5MBDQC
SDVKYDKG2CRKVGOBU5YE3KVAXYIQR6364NHDDGER44YLJD4WXYVAC
AW3W3OJBWKKEZRGQ3C6JRLVIH7ZGEUUI2UTD4MBSSGGNVIBYEDIQC
N4VDX3LQ3WIK7KCML7ZVZHTPUYVWJKQS6Z5HAMB4BAIE6FEAMKJAC
ROOBNGQ44S6WTT3KZ3MHOXLETZSJA4UGL3OBWMSBHNYNC5GNL5FQC
O3777TK2IVZ6LQATEWWIICGJY3GXO4MOUHZ73ENZFSY3VW4Q2DQAC
7Y3XBGQLPUDJFP2NXN53AOUHR5W2NJRK2F66BUNT4BAWIKSHXC3QC
Z3ALV46TWXGAUOXZXRFE6RCH66NCJ7GVNS43TYWXWN24TA5JVHCQC
NFFSOAPSTHSEL3ZQ6LCH4HKW54HUGTG67CW4HOSV6MH4FHP235BAC
IOVPOFAVXEQIZ7BCFVVAWFW3RYFXPK2GOILDWA6N6QHQHLAJ4XTAC
VVLGOC2NYNBINOTTPFUI46A5O4LXBHBROAYUPK7URDLMQHLEQL5AC
GP2LT7E5AF72ATQJSXY56ZJ3DM5KSV4SKOBJ3HWADBE3AZ3ACQAAC
YXDBKG5MWREH25GV2RUUW7ZI4P2XBNMZSB77WND3A6LUAL4NN63QC
__license__ = '''\
# Copyright (c) 2011 Edward Langley
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# Neither the name of the project's author nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.'''
import re
import functools
import os.path
import inspect
def inst(x): return x()
@inst
class __Null(object): pass
def getTerminalSize():
def ioctl_GWINSZ(fd):
try:
import fcntl, termios, struct, os
cr = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))
except:
return None
return cr
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
if not cr:
try:
fd = os.open(os.ctermid(), os.O_RDONLY)
cr = ioctl_GWINSZ(fd)
os.close(fd)
except:
pass
if not cr:
try:
cr = (env['LINES'], env['COLUMNS'])
except:
cr = (25, 80)
return int(cr[1]), int(cr[0])
def cmp(a,b): return (a > b) - (a < b)
def sort_(nms):
return sorted(nms, key = functools.cmp_to_key(lambda x,y: cmp(x.lower().lstrip('_').rpartition('__')[2], y.lower().lstrip('_').rpartition('__')[2])))
def sort_decorator(func):
@functools.wraps(func)
def _inner(*a, **kw):
result = func(*a, **kw)
return sort_(result)
return _inner
def pprint_decorator(func):
@functools.wraps(func)
def _inner(*args, **kwargs):
result = func(*args, **kwargs)
return pprint(result)
return _inner
def dir_decorator(func):
@functools.wraps(func)
def _inner(nm=__Null, match=__Null):
# print(get_interpframe())
result = None
if nm is __Null: result = get_interpframe().f_globals.keys()
else:
result = func(nm)
if match is not __Null:
x = [x for x in result if x.startswith(match)]
if x: result = x
else:
x = [x for x in result if x.endswith(match)]
if x: result = x
else:
omatch = match
if not hasattr(match, 'match'): match = re.compile(match)
x = [x for x in result if match.match(x)]
if x: result = x
else:
raise ValueError('No symbols match %s' % omatch)
if x: result = x
return result
return _inner
def _pprint(nms):
length = max(len(s) for s in nms)
count = 0
cc = 1
while (cc*length) < ((getTerminalSize()[0])-2*cc):
cc+=1
cc -= 1
if cc <= 0: cc = 1
final_newline = False
for v, c in enumerate(nms):
final_newline = False
print(c.strip().ljust(length),end='')
if v % cc == cc-1:
final_newline = True
print()
if not final_newline:
print()
pprint = _pprint
try:
__builtins__['pdir'] = pprint_decorator(sort_decorator(dir_decorator(dir)))
__builtins__['fwprint'] = pprint
except:
__builtins__.pdir = pprint_decorator(sort_decorator(dir_decorator(dir)))
__builtins__.fwprint = pprint
try:
import rlcompleter
import readline
except ImportError:
pass
readline.parse_and_bind ("tab complete")
import tempfile, subprocess
def get_interpframe(): return inspect.getouterframes(inspect.currentframe())[-1][0]
def e(name=None):
def load_file():
result = tempfile.NamedTemporaryFile(delete=False, dir=os.path.join(os.environ['HOME'], 'sandbox','unsorted'), prefix='pythonsnippets_', suffix='.py')
print(__license__.encode(), '\n\n'.encode(), file=result)
result.flush()
return result
if name is not None:
def load_file():
existed = True
nm = os.path.join(os.environ['HOME'], 'sandbox', '%s.py' % name)
mode = 'r+'
if not os.path.exists(nm):
mode = 'w'
existed = False
result = open(nm, mode)
if not existed:
print(__license__.encode(), '\n\n'.encode(), file=result)
result.flush()
return result
f = load_file()
print ('editing %s, press Enter to continue...' % f.name)
try:
try: subprocess.call(['vim', '+31', r'+start', f.name])
except Exception as e: print (e)
f.close()
f = open(f.name)
a = f.read()
exec (a in get_interpframe().f_globals)
finally:
f.close()
def ls(name):
load_file = lambda: open('/Users/edwlan/sandbox/unsorted/pythonsnippets_%s.py' % name)
try:
f = load_file()
except IOError:
load_file = lambda: open('/Users/edwlan/sandbox/%s.py' % name)
f = load_file()
raw_input('loading %s, press Enter to continue...' % f.name)
try:
exec (f.read() in get_interpframe().f_globals)
finally:
f.close()
try:
__builtins__['e'] = e
__builtins__['ls'] = ls
except:
__builtins__.e = e
__builtins__.ls = ls
#histfile = os.path.join(os.environ["HOME"], ".pyhist2.7")
#try: readline.read_history_file(histfile)
#except IOError: pass
try:
import pip
try:
def ip(name):
try: pip.main(['install', name])
except SystemExit: pass
__builtins__['ip'] = ip
except:
__builtins__.ip = ip
except ImportError:
pass
#import atexit
#atexit.register(readline.write_history_file, histfile)
return sorted(nms, cmp = lambda x,y: cmp(x.lower().lstrip('_').rpartition('__')[2], y.lower().lstrip('_').rpartition('__')[2]))
return sorted(nms, key = cmp_to_key(lambda x,y: cmp(x.lower().lstrip('_').rpartition('__')[2], y.lower().lstrip('_').rpartition('__')[2])))
@functools.wraps(func)
def _inner(nm=__Null, match=__Null):
print get_interpframe()
result = None
if nm is __Null: result = get_interpframe().f_globals.keys()
else:
result = func(nm)
if match is not __Null:
x = [x for x in result if x.startswith(match)]
if x: result = x
else:
x = [x for x in result if x.endswith(match)]
if x: result = x
else:
omatch = match
if not hasattr(match, 'match'): match = re.compile(match)
x = [x for x in result if match.match(x)]
if x: result = x
else:
raise ValueError('No symbols match %s' % omatch)
@functools.wraps(func)
def _inner(nm=__Null, match=__Null):
print(get_interpframe())
result = None
if nm is __Null: result = get_interpframe().f_globals.keys()
else:
result = func(nm)
if match is not __Null:
x = [x for x in result if x.startswith(match)]
if x: result = x
else:
x = [x for x in result if x.endswith(match)]
if x: result = x
else:
omatch = match
if not hasattr(match, 'match'): match = re.compile(match)
x = [x for x in result if match.match(x)]
if x: result = x
else:
raise ValueError('No symbols match %s' % omatch)
if x: result = x
return result
return _inner
(uiop:run-program (format nil
"gnuplot -e \"~:[~*~;set xrange [~{~f~^:~}];~]~:[~*~;set yrange [~{~f~^:~}];~]set terminal svg font 'Alegreya,14' enhanced background '~a'; set border lw 3 lc rgb '~a'; plot '< cat -' lt rgb '~a' notitle ~:[~;with lines~]\""
xrange-p xrange
yrange-p yrange
background
line-color
frame-color
lines)
(uiop:run-program (with-output-to-string (s)
(format (make-broadcast-stream s *error-output*)
"gnuplot -e \"~:[~*~;set xrange [~{~f~^:~}];~]~:[~*~;set yrange [~{~f~^:~}];~]set terminal svg font 'Alegreya,14' enhanced background '~a'; set border lw 3 lc rgb '~a'; plot '< cat' lt rgb '~a' notitle ~:[~;with linespoint~]\""
xrange-p xrange
yrange-p yrange
background
line-color
frame-color
lines))
#+(or)
(defun wi (fn)
(swank::send-to-emacs (list :write-image fn " ")))
(export
(defun dl (&optional (*default-pathname-defaults* *default-pathname-defaults*))
(let ((files (funcall (data-lens:exclude (data-lens:on (data-lens:regex-match "^[.]")
'pathname-name))
(directory "*.asd"))))
(values (mapcar 'load-asd files)
files))))
;; (sb-ext:set-sbcl-source-location
;; (merge-pathnames (make-pathname :directory '(:relative "sbcl-source")
;; :defaults #1=(user-homedir-pathname))
;; #1#))
#+(or)
(sb-ext:set-sbcl-source-location
(merge-pathnames (make-pathname :directory '(:relative "sbcl-source")
:defaults #1=(user-homedir-pathname))
#1#))
(defun fwoar::spotlight-validate-or-make-dummy-process (input)
(cond
((< (length input) helm-rg-input-min-search-chars)
(helm-rg--make-dummy-process
input
(format "must be at least %d characters" helm-rg-input-min-search-chars)))
(t t)))
(defun fwoar::spotlight-search (s)
(s-split "\n" (shell-command-to-string
(format "mdfind %s"
(shell-quote-argument s)))))
(defun fwoar::spotlight-search ()
"Invoke ripgrep in `helm-rg--current-dir' with `helm-pattern'.
Make a dummy process if the input is empty with a clear message to the user."
(let* ((input helm-pattern))
(pcase-exhaustive (fwoar::spotlight-validate-or-make-dummy-process input)
((and (pred processp) x)
(setq helm-rg--last-argv nil)
x)
(`t
(let* ((rg-regexp (helm-rg--helm-pattern-to-ripgrep-regexp input))
(argv (helm-rg--construct-argv rg-regexp))
(real-proc (helm-rg--make-process-from-argv argv)))
(setq helm-rg--last-argv argv)
real-proc)))))
(defvar *fwoar::spotlight-source*
(helm-build-async-source
"find files with spotlight"
:candidates-process 'fwoar::spotlight-search
:action (helm-make-actions
"Open" #'find-file)
))
(defun fwoar:spotlight-search ()
(interactive)
(helm (list )
:input ":write-image"
:prompt "Spotlight expression: "
))