Skip to content

Instantly share code, notes, and snippets.

View antonagestam's full-sized avatar
🍉

Anton Agestam antonagestam

🍉
View GitHub Profile
@antonagestam
antonagestam / forms.py
Last active August 29, 2015 14:11
Configurable Model Form
from django import forms
class ConfigurableModelForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ConfigurableModelForm, self).__init__(*args, **kwargs)
opts = self.Meta
if hasattr(opts, 'field_conf'):
self.update_fields(opts.field_conf)
workon test-project
cdvirtualenv
pip install -e git+git://github.com/antonagestam/django-text.git
cd src
sudo rm -r django-text
ln -s ~/path/to/local/django-text/ django-text
@antonagestam
antonagestam / cycle_example.html
Last active August 29, 2015 14:17
Cycle example
<div class="posts">
<div class="row">
{% for post in posts %}
<div class="post">{{ post }}</div>
{% if not forloop.last %}
{% cycle '' '' '</div><div class="row">' %}
{% endif %}
{% endfor %}
</div>
</div>
from django.shortcuts import render
from models import User, ItemDetail
def my_view(request):
gadget_users = User.objects.filter(item_detail__category=ItemDetail.GADGET)
return render(request, 'yourtemplate.html', {'gadget_users': gadget_users})
def get_category_users(category):
return User.objects.filter(item_detail__category=category)
def item_upload(request):
if request.method == 'POST':
item = ItemUpload(user=request.user)
form = ItemUploadForm(request.POST,request.FILES, instance=item)
if form.is_valid():
form.save()
<h3>Gadget users</h3>
<ul>
{% for user in gadget_users %}
<li>{{ user }}</li>
{% endfor %}
</ul>
$ brew update
Already up-to-date.
$ brew doctor
Error: No such file or directory - ~/.homebrew_temp/doctor20150625-10964-1gbo4wh
$ brew doctor --debug
Error: No such file or directory - ~/.homebrew_temp/doctor20150625-10987-122pw1l
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tmpdir.rb:85:in `mkdir'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tmpdir.rb:85:in `block in mktmpdir'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tmpdir.rb:142:in `create'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/tmpdir.rb:85:in `mktmpdir'
@antonagestam
antonagestam / comp.py
Last active August 29, 2015 14:26
compare two strings word by word
"""
>>> comp("""Hi folks
... What is the best way to clear a Riak bucket of all key, values after
... running a test?
... I am currently using the Java HTTP API.
... """, """Hi folks
...
... What is the best way to clear a Riak bucket of all key, values after
... running a test?
... I am currently using the Java HTTP API.
@antonagestam
antonagestam / morning.sh
Last active February 21, 2016 13:38
good morning!
osascript -e 'tell application "Spotify" to activate';
sleep 5;
osascript -e 'tell application "Spotify" to set shuffling to true';
osascript -e 'tell application "Spotify" to play track "spotify:user:bananatrapp:playlist:4a6RQIxSGXZVvXy6ckDeL5"'
@antonagestam
antonagestam / .vimrc
Last active April 9, 2018 13:14
.vimrc
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required