Skip to content

Instantly share code, notes, and snippets.

@msabramo
msabramo / pyval.sh
Created December 18, 2010 15:14
Bash function and alias for evaluating Python expressions from the Bash command-line
_pyval() {
local python_cmd="print $@"
python -c "${python_cmd}"
case "$shopts" in
*noglob*) ;;
*) set +f;;
esac
unset shopts
@msabramo
msabramo / Python Evaluator.applescript
Created December 21, 2010 17:22
Simple Python expression evaluator
property defaultPythonExpression : "' '.join([word.capitalize() for word in 'the green mile'.capitalize().split()])"
to getPythonExpressionFromUser given defaultExpresion:defaultExpression
return text returned of ¬
(display dialog "Enter a Python expression:" with title "Python Evaluator Expression" default answer defaultExpression)
end getPythonExpressionFromUser
to getResult from pythonExpression
return (do shell script "python -c \"print " & pythonExpression & "\"")
end getResult
title quantity price image1
1960s or 70s MOD WALLPAPER 113 ID CIGARETTE CASE WALLET 1 9.99 cig6100.jpg
Some other item 2 10.99 cig6101.jpg
And yet another item 3 11.99 cig6102.jpg
@msabramo
msabramo / pastebin.workflow.applescript
Created January 1, 2011 01:33
Create a service workflow in Automator with a "Run AppleScript" action with this for an easy shortcut for posting to pastebin.com (See http://marc-abramowitz.com/archives/2011/01/02/os-x-service-for-posting-text-to-pastebin-com/)
-- pastebin.workflow.applescript
--
-- An automator workflow to copy selected text to pastebin.com
--
-- Created by Marc Abramowitz
-- December 5, 2010
-- version 1.0
on run {input}
@msabramo
msabramo / new_gist.py
Created January 3, 2011 06:42
Take input from stdin and create a new public gist with it
#!/usr/bin/env python
import getpass, mechanize, optparse, os.path, sys
parser = optparse.OptionParser()
parser.add_option('--login')
parser.add_option('--password')
parser.add_option('--filename')
parser.add_option('--description')
parser.add_option('--private', action='store_true', default=False)
@msabramo
msabramo / githash.py
Created January 3, 2011 07:09
Python code to generate git SHA-1 hashes
#!/usr/bin/env python
from sys import argv
from hashlib import sha1
from cStringIO import StringIO
class githash(object):
def __init__(self):
self.buf = StringIO()
@msabramo
msabramo / rebuild_services_menu.sh
Created January 4, 2011 02:06
How to force the OS X Services menu to rebuild itself; a good thing to try if your Services menu is stuck saying "Building..."
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user
# - or -
launchctl stop com.apple.pbs
@msabramo
msabramo / lesspipe-1.71-bsd_ls.patch
Created January 27, 2011 07:20
This patch allows lesspipe.sh's color directory viewing to work with the ls in BSDs, including OS X
diff --git a/lesspipe.sh.in b/lesspipe.sh.in
index 00b40fc..2e620f4 100755
--- a/lesspipe.sh.in
+++ b/lesspipe.sh.in
@@ -506,13 +506,20 @@ isfinal() {
exit 1
elif [[ "$1" = *directory* ]]; then
echo "==> This is a directory, showing the output of"
- echo "ls -lA $2"
# color requires -r or -R when calling less, not recommended
@msabramo
msabramo / dict_test.py
Created March 15, 2011 18:04
A demonstration of the difference between a regular (unordered) dictionary and collections.OrderedDict
#!/usr/bin/env python
# A demonstration of the difference between a regular (unordered) dictionary
# and collections.OrderedDict
# See http://docs.python.org/library/collections.html#collections.OrderedDict
from collections import OrderedDict
def unordered_dict(dict_type):
d = dict_type()
@msabramo
msabramo / load_optional_django_apps.py
Created April 27, 2011 22:48
How to load (optional) Django apps only if they're present (from http://blog.jupo.org/post/586256417/optional-django-apps)
LOAD_OPTIONAL_APPS = True
if LOAD_OPTIONAL_APPS:
# <copypaste from="http://blog.jupo.org/post/586256417/optional-django-apps">
# Define any settings specific to each of the optional apps.
#
import sys
USE_SOUTH = not (len(sys.argv) > 1 and sys.argv[1] == "test")
DEBUG_TOOLBAR_CONFIG = {"INTERCEPT_REDIRECTS": True}