Skip to content

Instantly share code, notes, and snippets.

@Sheeprider
Sheeprider / forms.py
Last active December 31, 2015 15:59
Django forms to create payments with Systempay, and a model to save and validate them.
"""
Forms to create payments with Systempay.
Most code comes from https://github.com/dulaccc/django-oscar-systempay .
With the following licence :
Copyright (c) 2012 Pierre Dulac
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAG
@Sheeprider
Sheeprider / fields.py
Created December 3, 2013 15:44
Django form field for multiple urls.
import re
from django import forms
from django.contrib.sites.models import Site
from django.utils.safestring import mark_safe
class UrlWidget(forms.TextInput):
def render(self, name, value, attrs=None):
html = super(UrlWidget, self).render(name, value, attrs)
@Sheeprider
Sheeprider / gist:6527697
Created September 11, 2013 18:26
django get_error_message from form field
def get_error_message(form, field, message='required'):
"""Return an error message for a specific field on a form."""
return unicode(form.base_fields.get(field).error_messages[message])
@Sheeprider
Sheeprider / README.md
Last active December 14, 2015 16:38 — forked from agnoster/README.md

agnoster.zsh-theme

A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

For Mac users, I highly recommend iTerm 2 + Solarized Dark

@Sheeprider
Sheeprider / villes_et_codes_postaux_français_par_departement.json
Created September 26, 2012 17:33
Villes françaises, avec leur code postal, ainsi que leur département.
This file has been truncated, but you can view the full file.
[
{
"department": {
"name": "Aisne",
"number": "02"
},
"postal_code": "02160",
"name": "Œuilly"
},
@Sheeprider
Sheeprider / test.sh
Created September 11, 2012 09:17
notify if test does not pass
#! /bin/bash
export PATH="$PATH:/usr/local/bin:/"
logger "test launched"
casperjs test "$1" > "$2" &
wait $!
fail=$(grep -c "passed, 0 failed." $2)
if [ $fail -eq 1 ]; then
growlnotify "PASS" -m "casperjs"
logger "test passed"
else
@Sheeprider
Sheeprider / uri.js
Created July 14, 2012 13:59 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@Sheeprider
Sheeprider / gist:3110544
Created July 14, 2012 10:52 — forked from evansolomon/gist:3108240
Command line one liner to find and open function definitions in Sublime Text 2
# Alias ST2's command line tool for a shorter (easier-to-remember) name
alias st="/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl"
# Search for an open Sublime Text to a function definition
function fx() {
ack "function &?$1\(" | awk {'print $1'} | xargs st
}
# Example usage from the root of a WordPress repository
@Sheeprider
Sheeprider / gfm.rb
Created November 25, 2011 14:14 — forked from mojombo/gfm.rb
require 'digest/md5'
def gfm(text)
# Extract pre blocks
extractions = {}
text.gsub!(%r{<pre>.*?</pre>}m) do |match|
md5 = Digest::MD5.hexdigest(match)
extractions[md5] = match
"{gfm-extraction-#{md5}}"
end