Skip to content

Instantly share code, notes, and snippets.

View julianwachholz's full-sized avatar
🤓

Julian Wachholz julianwachholz

🤓
View GitHub Profile
class ImageQuerysetMixin(object):
"""
Make sure to use the correct arguments for getting a single image.
With this mixin it's not possible to request an image just by its
primary key, we'll also need the correct username.
"""
def get_queryset(self):
return self.model.objects.filter(
@julianwachholz
julianwachholz / product.php
Created July 2, 2013 15:12
Lovely ancient jQuery code.
function remove(obj){
if( $(obj).parent().parent().hasClass('unstored') ){
$(obj).parent().parent().remove();
}else{
$(obj).parent().parent().find('input[type="text"], textarea').val('');
$(obj).parent().parent().hide();
}
return false;
}
https://speakerdeck.com/mdo/frameworks-of-tomorrow
# Today
- Bootstrap
- Foundation
- Gumby
- tuktuk
- Pure (Adobe)
@julianwachholz
julianwachholz / fields.py
Created September 26, 2013 19:21
Easy single `<input>` month/year form field for Django.
class CreditCardExpirationField(forms.DateField):
default_error_messages = {
'min_value': _("This card has expired."),
'invalid': _("Please specify a valid expiration date.")
}
widget = forms.DateInput(format='%m/%Y')
input_formats = ('%m/%Y', '%m/%y')
default_validators = [
MinValueValidator(now().date()),
]
%% Erlang Programming, exercise 4-2
%%
%% A variant where the message is passed M times around.
%%
-module (ring).
-compile(export_all).
%% N processes in a ring pass around Message a total of M times.
start(N, Message, M) ->
@julianwachholz
julianwachholz / chroot.sh
Created December 12, 2014 10:42
Autoinstall ArchLinux on a existing OS
#!/bin/sh -e
ARCH_VERSION="2014.12.01"
ARCH_FILE="archlinux-bootstrap-$ARCH_VERSION-x86_64.tar.gz"
ARCH_BOOTSTRAP="http://archlinux.mirrors.ovh.net/archlinux/iso/$ARCH_VERSION/$ARCH_FILE"
ARCH_SUMS="http://archlinux.mirrors.ovh.net/archlinux/iso/$ARCH_VERSION/sha1sums.txt"
# download bootstrap image
cd /tmp
wget $ARCH_BOOTSTRAP
jwa ~> dig A ju.io
; <<>> DiG 9.8.3-P1 <<>> A ju.io
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39104
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;ju.io. IN A
@julianwachholz
julianwachholz / int2bytes.coffee
Created January 29, 2015 14:56
Ever needed to convert integers to bytes and back in javascript?
INT_BYTES = 8 # but note that javascript only does 2^53
int2bytes = (x) ->
if x > Number.MAX_SAFE_INTEGER
throw new Error "Number is larger than Number.MAX_SAFE_INTEGER (2⁵³-1)!"
bytes = []
i = INT_BYTES
loop
bytes[--i] = x & 0xff
@julianwachholz
julianwachholz / inputhistory.js
Last active August 28, 2020 10:04
JavaScript <input> history with arrow buttons, a.k.a. poor man's readline
/**
* License: WTFPL - http://www.wtfpl.net/
*
* Usage: element.addEventListener('keydown', inputHistory());
*/
function inputHistory(max_history) {
var PREV = 38, NEXT = 40, ENTER = 13,
history = [''], current = 0;
if (!max_history) {