Skip to content

Instantly share code, notes, and snippets.

View Wilfred's full-sized avatar

Wilfred Hughes Wilfred

View GitHub Profile
@Wilfred
Wilfred / Skatol'
Created December 20, 2010 19:39
Eksperimenta ludo
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<p>Hello world</p>
@Wilfred
Wilfred / gfm.py
Created April 4, 2011 14:17 — forked from gasman/gfm.py
"""GitHub flavoured markdown: because normal markdown has some vicious
gotchas.
Further reading on the gotchas:
http://blog.stackoverflow.com/2009/10/markdown-one-year-later/
This is a Python port of GitHub code, taken from
https://gist.github.com/901706
To run the tests, install nose ($ easy_install nose) then:
@Wilfred
Wilfred / dbindexer_crash_on_none.diff
Created December 12, 2011 15:10
Patch for django-dbindexer issue #3
diff -r ae5f7638827e dbindexer/lookups.py
--- a/dbindexer/lookups.py Tue Sep 06 11:07:55 2011 +0200
+++ b/dbindexer/lookups.py Tue Nov 15 17:48:56 2011 +0000
@@ -48,10 +48,11 @@
return lookup_type, value
def convert_value(self, value):
- if isinstance(value, (tuple, list)):
- value = [self._convert_value(val) for val in value]
- else:
@Wilfred
Wilfred / and-let.el
Created June 12, 2012 14:09
and-let* from Scheme implemented in Emacs Lisp
(eval-when-compile (require 'cl)); declare, first, rest
;;;; and-let*, based on Scheme's SRFI 2
;; Contrived usage example:
;; (and-let* ((buffer-path (buffer-file-name))
;; (file-name (file-name-directory)))
;; (message "You are visiting a file called %s in this buffer."
;; file-name))
(defmacro and-let* (varlist &rest body)
"Equivalent to let*, but terminates early and returns nil if
@Wilfred
Wilfred / group_pairs.py
Created December 5, 2012 17:58
grouping pairs using itertools
from itertools import groupby
from operator import itemgetter
def group_pairs(iterable):
"""Given a sorted list of pairs, group by the first element in
each pair.
>>> group_pairs([('a', 1), ('a', 2), ('b', 3)])
[('a', [1, 2]), ('b', [3])]
@Wilfred
Wilfred / FizzBuzz.hs
Created January 5, 2013 20:57
FizzBuzz in Haskell
import Control.Monad(forM_)
main = forM_ (take 100 fizzBuzzes) putStrLn
toFizzBuzz :: Integer -> String
toFizzBuzz x
| x `rem` 15 == 0 = "FizzBuzz"
| x `rem` 5 == 0 = "Buzz"
| x `rem` 3 == 0 = "Fizz"
| otherwise = show x
@Wilfred
Wilfred / gist:4585428
Created January 21, 2013 11:30
using vNEXT in a README with feature branches in git
$ mkdir example_project_2
$ cd example_project_2
$ git init
Initialized empty Git repository in /tmp/example_project_2/.git/
$ nano README.md
$ more README.md
## vNEXT
$ git add README.md
$ git commit -m "initial commit"
[master (root-commit) 0014408] initial commit
@Wilfred
Wilfred / gist:4675002
Created January 30, 2013 17:38
A tidy way of validating forms in Django
from django.shortcuts import redirect, render_to_response
from django.template import RequestContext
from .forms import UserProfileForm
def my_view(request):
if request.method == "POST":
form = UserProfileForm(request.POST)
(defun dwim-at-point ()
"If there's an active selection, return that. Otherwise, get
the symbol at point."
(if (use-region-p)
(buffer-substring-no-properties (region-beginning) (region-end))
(if (symbol-at-point)
(symbol-name (symbol-at-point)))))
;; todo: investigate whether we're reinventing the wheel, since query-replace-history already exists
(defvar query-replace/history nil)
@Wilfred
Wilfred / dash-slice.el
Last active December 14, 2015 03:19
A tentative slice implementation
(defun --slice (list from &optional to)
"Return copy of LIST, starting from index FROM to index TO.
FROM or TO may be negative"
;; to defaults to the end of the list
(setq to (or to (length list)))
;; handle negative indices
(when (< from 0)
(setq from (mod from (length list))))
(when (< to 0)
(setq to (mod to (length list))))