Skip to content

Instantly share code, notes, and snippets.

import Image
def borders(filename):
im = Image.open(filename)
im = im.convert("RGB")
pix = im.load()
x = im.size[0]-1
y = im.size[1]-1
import Image
def borders(filename):
im = Image.open(filename)
im = im.convert("RGB")
pix = im.load()
x = im.size[0]-1
y = im.size[1]-1
@riklomas
riklomas / gist:130614
Created June 16, 2009 09:14
For adding a class to anchors
if (typeof window.location.hash == "string" && window.location.hash != "")
{
$(window.location.hash).addClass('anchored');
}
@riklomas
riklomas / gist:143562
Created July 9, 2009 10:27
How to default (or initial) an admin select in Django's ModelAdmin
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == "user":
return forms.ModelChoiceField(queryset=User.objects.all().order_by('username'), initial=kwargs['request'].user.id)
return super(NamedAdmin, self).formfield_for_dbfield(db_field, **kwargs)
@riklomas
riklomas / gist:158649
Created July 30, 2009 10:44
Query string in JS
var querystring = function () {
var obj = {};
var query = window.location.search.substring(1);
if (query != "") {
var vars = query.split("&");
for (var i = 0; i < vars.length; i++) {
var p = vars[i].split("=");
obj[p[0]] = p[1];
}
}
def borders(filename, threshold = 0.5):
try:
im = Image.open(filename)
im = im.convert("RGB")
pix = im.load()
x = int(im.size[0])
y = int(im.size[1])
javascript:window.location.href='http://www.example.com/postbookmark/?url='+encodeURIComponent(window.location.href)+'&user=riklomas&secret=948340934503498';
@riklomas
riklomas / adding-to-user-admin-form.py
Created August 6, 2010 15:01
How to add a field to the Django Admin Add User form using UserCreationForm. Add this to a admin.py and alter to whatever fields you'd like
# How to add a field to the Django Admin Add User form
# using UserCreationForm. Add this to a admin.py and alter
# to whatever fields you'd like
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.contrib import admin
<% nmonth = "" %>
<li>
<ul class="weeks">
<li>Week</li>
<% navigation_weeks.each do |w| %>
<li class="<%= (controller_name == "posts" || controller_name == "things") && params[:action]=="index" && params[:week].present? && params[:year].present? && params[:week]==w.week.to_s && params[:year]==w.year.to_s ? 'active' : '' %>">
<%= link_to posts_path(:week => w.week, :year => w.year), :class => 'tip', :title => week_dates(w.week, w.year) do %>
<%= w.week %>
<% if nmonth != week_month(w.week, w.year) %>
<span class="<%= week_month(w.week, w.year).downcase %>"><%= week_month(w.week, w.year) %></span>
@riklomas
riklomas / loz-tipsy-1
Created February 7, 2012 14:41 — forked from lawrencebrown/loz-tipsy-1
tipsy start
<script type="text/javascript">
(function ($) {
$(function () {
$('ul.dd li').tipsy({gravity: $.fn.tipsy.autoNS});
});
})(jQuery);
</script>