Skip to content

Instantly share code, notes, and snippets.

View sneeu's full-sized avatar
🦀
Hi

John Sutherland sneeu

🦀
Hi
View GitHub Profile
from django.shortcuts import get_object_or_404, render
from articles.forms import ArticleForm
from articles.models import Article
def article_edit(request, article_id):
article = get_object_or_404(Article, pk=article_id)
if request.method == 'POST':
@sneeu
sneeu / gist:3144246
Created July 19, 2012 14:17
Currently playing in Spotify
tell application "System Events"
-- Checks that an instance of Spotify is running
set isRunning to (count of (every process whose name is "Spotify")) > 0
end tell
if isRunning then
tell application "Spotify"
set theTitle to name of the current track
set theArtist to artist of the current track
set theStarred to starred of the current track
autocmd FileType css setlocal ts=4 sts=4 sw=4 noexpandtab
autocmd FileType html setlocal ts=4 sts=4 sw=4 noexpandtab
autocmd FileType htmldjango setlocal ts=4 sts=4 sw=4 noexpandtab
autocmd FileType mustache setlocal ts=4 sts=4 sw=4 noexpandtab
autocmd FileType markdown setlocal ts=4 sts=4 sw=4 expandtab
autocmd FileType php setlocal ts=4 sts=4 sw=4 noexpandtab
autocmd FileType less setlocal ts=4 sts=4 sw=4 noexpandtab
autocmd FileType javascript setlocal ts=4 sts=4 sw=4 noexpandtab
autocmd FileType ruby setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType haskell setlocal ts=2 sts=2 sw=2 expandtab
fizzBuzz :: Int -> (Int, String)
fizzBuzz a
| a `mod` 15 == 0 = (a, "FizzBuzz")
| a `mod` 3 == 0 = (a, "Fizz")
| a `mod` 5 == 0 = (a, "Buzz")
| otherwise = (a, "")
fizzBuzz' :: [Int] -> [(Int, String)]
fizzBuzz' [] = []
[alias]
st = status -s
ci = commit
co = checkout
di = diff
br = branch
lg = log --graph --decorate --pretty=oneline --abbrev-commit --color --all
amend = commit --amend

With tmux, you can replace both:

tmux new -s project
tmux attach -t project

with:

def dict_path(from_object, path):
"""
>>> dict_path({'a': {'b': {'c': 123}}}, ['a', 'b'])
{'c': 123}
"""
if path == []:
return from_object
return dict_path(from_object[path[0]], path[1:])
def enum(name, attrs):
"""
>>> Fruit = enum('Fruit', 'apple banana cranberry')
>>> Fruit.apple #doctest: +ELLIPSIS
<object object at 0x...>
>>> Fruit.apple == Fruit.banana
False
>>> Animal = enum('Animal', 'cat dog elephant')
>>> Animal.cat #doctest: +ELLIPSIS
<object object at 0x...>
john=# EXPLAIN SELECT id FROM users WHERE id = id = xyz;
ERROR: operator does not exist: integer = boolean
LINE 1: EXPLAIN SELECT id FROM users WHERE id = id = xyz;
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
@sneeu
sneeu / -
Created November 14, 2013 10:37
artii (2.0.3)
asciiart (0.0.5)
CFPropertyList (2.2.0)
libxml-ruby (2.6.0)
lolcat (42.0.99)
nokogiri (1.5.6)
paint (0.8.6)
rainbow (1.1.4)
redcarpet (3.0.0)
rmagick (2.13.2)