a blog about programming, photography and electronics.

[Plugin] jQuery Holed Div

Posted: February 3rd, 2011 | Author: | Filed under: jQuery, WebDevelopment | Tags: , , , , , , | No Comments »

Recently I needed to create a holed div, like this:

I haven’t found any good solution to create a holed div without using images, so I tried to use canvas as a background and it worked nicely.

Anyway I wanted to share my result to everyone, maybe it’ll be useful to someone else :)
So I created a jQuery Plugin called jquery.holedDiv.

Here’s a demo: demo

Download Latest This version may not work, because is used for testing, download the minified version.

Download Minified (0.1)
Download Minified (0.1.1)

Update: code uploaded to bitbucket (see below)

Usage:

$('div.info').holedDiv({
      'padding': 10,
      'radius': 10, //0 if you don't want rounded borders
      'stroke': false, //if you want to add a (black) stroke to the background
      'holeRadius': 20,
      'drawInner': true, //if you want to draw an inner circle, like the demo
      'drawInnerColor': 'black' //the color of the inner circle
});

Tested On:

  • Chrome 10
  • Firefox 4b10
  • Opera 10
  • IE 9

If you find any bug, or have any question (or feature suggestions) please let me know :)

Update 03/02/2011 20.41

Added version 0.1.1 that supports IE 9.0

Update 04/02/2011 23.50

Version 0.2 is ready, supports IE < 9 using excanvas

You can download it on bitbucket:

http://bitbucket.org/patrick91/jquery.holeddiv/

Update 08/02/2011

Relased Version 0.3 check it on bitbucket


[Project] Arduino and Canon EOS 400d

Posted: August 16th, 2010 | Author: | Filed under: Arduino, Projects | Tags: , , , , , | No Comments »

This is my last project, an intervalometer for my Canon EOS 400d created with arduino.

I created it because i need to create some time lapse video for the coming soon bisaccia.info‘s web tv.
Here are two videos:

The “Backstage”:

A sample time lapse:

I’ll upload the code and the schematic soon when I create a better version, currently you can’t change the delay between every shoots, also you can’t stop it.
A better time lapse video is also coming but I should buy a battery grip for my canon, currently my battery last only 5 hours.


Tip – Dynamic Path For FileField

Posted: June 15th, 2010 | Author: | Filed under: django, tips | Tags: , , | No Comments »

In a recent project I needed to save a file to a dynamic directory.

My model was something like this:

from django.db import models
 
class MyDoc(models.Model):
    name = models.CharField()
    document = models.FileField(upload_to='uploads/documents')

with this code each document will be uploaded to MEDIA_ROOT/uploads/documents.
In order to upload the file to a dynamic dir like this: MEDIA_ROOT/uploads/documents/id/ I used this code:

from django.db import models
 
class MyDoc(models.Model):
    upload_to = 'uploads/documents/%d/%s'
 
    def _get_upload_to(self, filename):
        return self.upload_to % (self.pk, filename)
 
    name = models.CharField()
    document = models.FileField(upload_to=_get_upload_to)

That’s all (Thats’s Django!), now this code will upload each document into a separated dir for each object.

UPDATE
The code I posted before doesn’t work properly in fact the first time we save the model the pk is None so this code can’t get the correct path.

If you have any question, please feel free to ask.


Adding additional views to django admin

Posted: May 17th, 2010 | Author: | Filed under: django | Tags: , | 2 Comments »

Today I wanna show you a simple way to add an additional view to the admin site.
Imagine that you want to create a view to review a model, something like send an email to the site owner with your thoughs (or your changes) about an entry.

First we need to define a simple model (of course you can use your existing model):

from django.db import models
 
class MyEntry(models.Model):
    title = models.CharField(max_length=100)
    body = models.TextField()
 
    def __unicode__(self):
        return self.title
 
    class Meta(object):
        verbose_name = 'My Entry'
        verbose_name_plural = 'My Entries'

Read the rest of this entry »