Skip to content

Instantly share code, notes, and snippets.

View bmihelac's full-sized avatar

Bojan Mihelac bmihelac

View GitHub Profile
@bmihelac
bmihelac / center-image.less
Created January 9, 2014 12:02
less mixin to center responsive image in fixed size element
// center responsive image in fixed size element
.center-image(@width, @height) {
position: relative;
// make parent element width/height divisible by 2
width: floor((@width + 0.5) / 2) * 2;
height: floor((@height + 0.5) / 2) * 2;
img {
display: block;
max-width: 100%;
max-height: 100%;
@bmihelac
bmihelac / get serial port
Created August 30, 2013 12:15
IrToy playing
$ python -m serial.tools.list_ports
/dev/ttyACM0
@bmihelac
bmihelac / jquery.total-width.js
Created August 12, 2013 08:34
Returns total width of matched elements
jQuery.fn.totalWidth = function() {
var totalWidth = 0;
this.each(function() {
totalWidth = totalWidth + $(this).width();
});
return totalWidth;
};
@bmihelac
bmihelac / gist:6193333
Created August 9, 2013 12:43
Alias to watch and recompile less files on change, printing errors. Requires watchr.
alias watchless='watchr -e '\''require "date"; watch("(.*)\.less$") { |f| cmd = "lessc #{f[0]} --source-map #{f[1]}.css"; puts "#{DateTime.now}: #{cmd}"; output = `#{cmd}`; if $? != 0 then puts output end }'\'''
@bmihelac
bmihelac / processors.py
Last active December 15, 2015 19:18
easy-thumbnails watermark to right bottom corner of the image
# custom/processors.py
from django.conf import settings
from django.core.files.storage import default_storage
try:
from PIL import Image
except ImportError:
import Image
@bmihelac
bmihelac / gist:4943082
Created February 13, 2013 08:27
Execute python management command from shell
from django.core.management import execute_from_command_line
execute_from_command_line(['', 'show_urls'])
@bmihelac
bmihelac / linkif.py
Created January 2, 2013 14:48
Django templatetag wraps everything between ``{% linkif %}`` and ``{% endlinkif %}`` inside a ``link`` if ``link`` is not False.
from django import template
register = template.Library()
@register.tag
def linkif(parser, token):
"""
Wraps everything between ``{% linkif %}`` and ``{% endlinkif %}`` inside
a ``link`` if ``link`` is not False.
@bmihelac
bmihelac / feincms_admin_content_type.py
Created November 30, 2012 08:10
FeinCMS content type admin inlines customization
from feincms.admin.item_editor import FeinCMSInline
class AuthorContentTypeInline(FeinCMSInline):
# InlineModelAdmin options
raw_id_fields = ('author',)
class AuthorContentType(models.Model):
author = models.ForeignKey(Author)
@bmihelac
bmihelac / metaclass.py
Created November 22, 2012 15:23
Python Metaclass example
"""
Metaclass example
>>> class MyKlass(Klass):
... my_field = Field()
...
... class Meta:
... model = "Model"
...
>>> MyKlass._meta.model
@bmihelac
bmihelac / models.py
Created November 7, 2012 11:48
Reload django dev server when django-rosetta compiles mo files
# ...in models.py
from django.dispatch import receiver
from rosetta.signals import post_save
@receiver(post_save)
def restart_server(sender, **kwargs):
import os
os.system("sleep 1 && echo \"Rosetta reload\" && touch %s &" % __file__)