Skip to content

Instantly share code, notes, and snippets.

View tommorris's full-sized avatar

Tom Morris tommorris

View GitHub Profile
@tommorris
tommorris / tom.editorconfig
Created March 29, 2016 12:45
My evolving default .editorconfig
# EditorConfig is awesome: http://EditorConfig.org
# My evolving default .editorconfig
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
import twitter
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in xrange(0, len(l), n):
yield l[i:i+n]
def put_friends_on_list(oauth_creds, username, list_name):
t = Twitter(auth=OAuth(*oauth_creds)
res = t.friends.ids()
@tommorris
tommorris / gist:91538461e31d342a5279
Created December 9, 2015 13:55
Bullshit detector sample sentence
To improve our ability to deliver award-winning strategic outcomes and change making going forward, we sought to progress the conversation to drill down into key action issues with our B2C stakeholders, leveraging their many dynamic competencies, before taking it off-line and sunsetting your favourite bookmarking tool.
@tommorris
tommorris / gist:c6d5806646ba70b7bf25
Created October 17, 2015 16:45
npm cares about your current working directory even if you are installing a global module. Apparently that matters. This kind of stupid shit shit is why I fucking abhor Node.
$ pwd
/Volumes/NO NAME/
# This volume is not mounted.
$ sudo npm install -g eslint
Password:
node.js:720
var cwd = process.cwd();
^
@tommorris
tommorris / tests.py
Last active August 26, 2021 04:04
Django admin testing
from django.test import TestCase, Client
from django.contrib.auth.models import User
class TestAdminPanel(TestCase):
def create_user(self):
self.username = "test_admin"
self.password = User.objects.make_random_password()
user, created = User.objects.get_or_create(username=self.username)
user.set_password(self.password)
def change_filename fn
matcher = /Statement--(\d{6})-\d+--(\d{2})-(\d{2})-(\d{4})-(\d{2})-(\d{2})-(\d{4}).pdf/
return fn.gsub(matcher, '\4-\3-\2 - \7-\6-\5.pdf')
end
`ls | grep Statement`.split("\n").each do |fn|
`mv "#{fn}" "#{change_filename(fn)}"`
end
# MIT licensed
@tommorris
tommorris / examples.mkd
Last active March 29, 2025 22:12
OSA JavaScript recipes

For a while, you've been able to script Mac OS using JavaScript using JavaScript for Open Scripting Architecture (JSOSA). This is a huge improvement on AppleScript. Why? JavaScript isn't a great language, but it broadly follows the conventions that programming languages of the C/ALGOL family have followed for decades. AppleScript is a horrendous mess that should never have come into being.

Let's compare.

set x to 0
set taskName to the name of task
Offline apps notes (draft)
Rating:
5/5 all essential functionality available offline by default, works reliably
4/5 most key functionality available offline by default, mostly works
3/5 some functionality available, may require configuration or manual faff
2/5 minimally functional when offline, considerable configuration or manual faff required
1/5 barely functional offline, complex configuration or effort required to use
0/5 not functional without an Internet connection
try:
# Python 3
from urllib.parse import urlparse
except ImportError:
# Python 2.x
from urlparse import urlparse
def evernote_url_to_ios_url(url):
parsed = urlparse(url)
assert parsed.netloc == "www.evernote.com" or parsed.netloc == "sandbox.evernote.com
URL="http://tantek.com/2015/178/t1/lovewins-css3-pride-rainbow-background"
BITRATES=(19 20 21 22 23 24 25 26)
for BITRATE in ${BITRATES[@]}
do
hashcash -v -mb${BITRATE} "$URL" 2>&1
hashcash -p now
echo ""
done