Index

  • Many great talks and swag to be had

    Posted on Tuesday, April 15th, 2014
    2 comments

    PyCon 2014 was a great experience to be had. There were many fascinating talks and so much to see and do at the convention. I also performed a Lightning Talk on server security giving some tips and tricks I use on a daily basis, which is based on my Debian Diary article I wrote a couple months back.

    Some of the larger swag items I nabbed was a book titled, Hacking: The art of exploitation, and another called Core Python Application Programming which was signed by the author. I am really excited about reading both of these books.

    I went to a couple very interesting talks as well.

  • PyCon 2014 Montreal

    Posted on Tuesday, April 8th, 2014
    0 comments

    I will be attending the PyCon in Montreal this week, and I look forward to many of the talks and blogging about as much as I possibly can while I am there. If anybody whom follows Python Diary is attending, you should be-able to find me there.

    Looking forward to all the excellent talks this year, and this is my very first PyCon, so you can just see how excited I must be!

    Everything PyCon will be properly tagged on the blog, so just bookmark that tag for the latest news directly from PyCon 2014.

  • Website made entirely using ncurses!

    Posted on Saturday, February 1st, 2014

    As an interesting proof-of-concept idea, I built an entire website, my personal profile page using nothing more than ncurses and a vt100 terminal emulator! I recently unleashed it out into the public, and there was lots of positive and nostalgic responses. This is only the first iteration of the site, and more features will be coming soon.

    The result was unexpectedly usable! Although hosting such a site is only ideal for low traffic websites as the server resources can really be used up by each forked Python process. How it works is simpler than you might imagine, it is merely a standard Python console application running directly in the browser! To obtain the vt100 emulation and access to the Python application, I used a popular remote shell tool called Shellinabox. Shellinabox is normally used to provide a Linux admin with a remote login shell via their browser to administer the server, just as he/she would while using SSH. Shellinabox can actually run any terminal program you tell it to run, and this gave birth to this idea. I first tested it by running Lynx in a web browser directly, so accessing a page would immediately display the popular Lynx browser. Amazingly, the mouse was also able to control Lynx! So... I thought, if I could make my own ncurses application which can also use a mouse, I could build an entire website using just ncurses!

    You can view it live by clicking on my name below my photo in the right bar of this website. There is also an alternative telnet interface for those whom don't have a graphical browser handy, as vt100 emulation requires a decent JavaScript engine.

    This is more of a proof-of-concept, as I am planning on building this idea further with a complete recode of my Hacker's Edge massively multiplayer online game. I had some difficulties making Hacker's Edge what I wanted it to be, and I believe turning it into a full Python console application with some ncurses components might be what I need to really make this game take off. The game will end up featuring both a web-based vt100 terminal emulation for those without a compatible Telnet client, and telnet connection support. The new idea will be to add a better network simulator, many console applications, and a fake assembly language to built fake viruses and malware to create fake botnets. Think of it as a Grand Theft Auto for CyberCrime! As you can see from my Bitbucket page, I have been creating some specialized applications, such as the CPU simulator, which will make it's way into Hacker's Edge.

  • Kevin Veroneau Consulting demo video

    Posted on Tuesday, December 10th, 2013

    In this video you can see my Consulting Services website in action to see the benefits of working with me over other independent Django contractor. The tools were of course built using Django, and have been used for over a year now successfully:

  • Have Django respond to Email in real-time

    Posted on Thursday, August 1st, 2013

    It's been a long time since I wrote a new article on Python Diary, and I do apologize for the lack of content recently. Hopefully this interesting article will make up for that.

    Have you ever wanted Django to parse an incoming Email in real-time as soon as it comes into your server? Look no further than this handy solution here. In order to use this solution, you will need to configure a local Postfix server, it doesn't need to be-able to send outbound email, only receive new messages for your domain. Although being able to send messages will make it easier to reply back to the user's whom are sending the server messages.

    You will first need to create a short Python script which Postfix will deliver the actual message to:

    import sys
    import urllib2
    
    req = urllib2.Request(url='[Django URL]', data=sys.stdin.read())
    f = urllib2.urlopen(req)
    

    This script submits the entire message unmodified directly to any web address you give the script, preferably a Django URL. Notice that I am not using the standard form encoding, as there is no need to add additional overhead when all we want to do is have Django process an entire message. The main reason why this script exists, is because this script will run normally as nobody:nogroup, so it will not be-able to easily talk with your local Django app directly using say, a management script. Sending the data directly over HTTP to the Django instance is simple and should have very little overhead and integrate easily with existing solutions.

    from django.views.decorators.csrf import csrf_exempt
    from email import message_from_string
    from django.http import HttpResponse
    
    @csrf_exempt
    def mail_parse(req):
      msg = message_from_string(req.body)
      # Process data from msg here!
      return HttpResponse("OK", content_type="text/plain")
    

    Here is the Django view which will receive the raw message data and parse it. You should read the Python documentation on the subject to learn how to extract the headers, body, and attachments you want to parse. Finally, here is what you should place in your /etc/aliases:

    api:         |/[path to script].py
    

    Be sure to run newaliases afterwards to rebuild the hash table. This alias here makes anything api@[domain] submit to your Django site. Enjoy!

  • Django bootstrap theme is ready!

    Posted on Saturday, May 25th, 2013

    You can download a project template for this now: http://www.pythondiary.com/templates/bootstraptheme

    It's finally ready for developer consumption, my Django bootstrap theme Django app. With this super simple app in your Django project, you can easily apply a site-wide Bootstrap theme in a matter of minutes. Here's an example base.html you would use in your project's templates directory:

    {% extends 'bootstrap_theme/starter.html' %}
    
    {% block title %}Bootstrap Django site{% endblock %}
    
    {% block branding %}Django Project{% endblock %}
    
    {% block content %}
    Yes Folks, this is how easy it is to implement bootstrap in Django now.  Be sure to look at the other templates available to see what <b>blocks</b> you can override.
    {% endblock %}
    

    Be sure to add bootstrap_theme to your INSTALLED_APPS, and this will work like a charm. Here is a list of available base templates you can extend:

    base.html
    This is the main template which the ones below extend to create the Bootstrap experience.
    starter.html
    This is the exact starter template from the Bootstrap documentation, it's the most basic and easiest to extend.
    fluid.html
    Similar to starter, except it allows users to sign in and out, and has a left navigation bar.
    marketing.html
    The marketing template directly from the bootstrap examples page tailored to work with Django.
    marketing_narrow.html
    From the bootstrap example page, another version of a marketing page you can try out.
    marketing_clean.html
    Yet another marketing page example, also from the bootstrap examples page.
    carousel.html
    The bootstrap carousel example made for Django, the bonus is that the Carousel is driven from the database, so it's easy to add and edit the big Carousel banner.

    Wait, there's more... There's a large amount of templatetags at your disposal as well in the bootstrap library which you can load into any template you need it in. Here's what's included:

    buttonlink url icon
    You can create bootstrap themed buttons with this tag.
    emphasis filter
    This filter will add special styling to the text, such as muted which is the default, or anything in the text- CSS components.
    abbrev filter
    This handy filter will create an abbreviation text.
    yesnoicon filter
    Depending if the value is True or False a different icon is displayed.
    ratingicon filter
    This super handy filter will create a specific amount of star icons depending on the value.
    link filter
    Pass in any model object which has a get_absolute_url and it will automatically make it click-able.
    carousel group_name
    This is used to display a database driven Carousel. The group_name parameter is which group in the database model to display for this instance.
    navbar_gradient first_color last_color
    This super handy tag will automatically generate the required CSS style needed for the navbar gradient.
    modal title modal_id form_action
    This block tag is used to generate a modal dialog box, the last 2 options are optional. The first is the title of the dialog box, the second is the unique div ID for the modal, and the last one is the URL which the form inside the modal will be posted to, if the user saves the changes.
    icon slug
    This is used to display bootstrap icons easily.
    modal_button title modal_id icon
    This is used to generate the required A tag to display a modal dialog box generated above. The first option is what to display on the button itself, the second is the div ID chosen, and the last one is an icon slug to place on the button. The last two options are optional and have reasonable defaults.

    Don't leave yet, there's still one last thing... An include-able template which can display a Django form very elegantly in bootstrap! Finally you can make your Django generated forms look great and functional with very little effort. Here's an example contact form to get you started:

              <form action="{% url 'contact-form' %}" method="post">{% csrf_token %}
                <fieldset>
                  <legend>Contact form</legend>
                  {% include "bootstrap_form.html" %}
                  <button type="submit" class="btn btn-primary">Send Message</button>
                </fieldset>
              </form>
    

    Wow, that's a lot to take in, in the next release I will be adding a bunch of ready made templates for django-registration so that you can get a new Django website up and running in a matter of hours.

  • Looking for advertising proposals

    Posted on Sunday, May 19th, 2013

    As some of you may have noticed, the AdSense bar no longer exists on my blog, this is due to Google recently revoking my AdSense account, I am quite sure it is in regards to mentioning it on a page. Currently users who have an account are able to opt'd out of either being tracked by Analytics or have no ads served to them. I will be removing this feature soon, as I am planning on self-hosting ads from prospect publishers. If you have a Python or Django related project which you would like to adverse on this blog, please contact me. Having a way to fund this website will allow me to publish more quality articles and tutorials. When a new article is posted, this blog receives over 1,000 hits in that single day. These are 1,000 prospect users which use Python and maybe Django who will see your advertisement. These can also be users who are just learning Python, so books and courses are also welcome.

    Currently the ad serving system has yet to be implemented, so at this time I am only asking prospect advertisers to provide me with a proposal on how the ads should be served to users and costs they might be willing to pay. For the record this blog has been online for well over a year now and receives many returning users due to the quality of the content which is provided. This website is also much more than a blog, as it has other features which bring users back for more.

    Thank you for your time in reading this.

  • DVD Collection source code now available

    Posted on Sunday, May 19th, 2013

    For those who were wanting a copy of the DVD Collection software made in Python, I have now open sourced it and it is live on BitBucket!

    DVD Collection software

  • Python Script to encode Django templates

    Posted on Sunday, May 19th, 2013

    Do you need to display raw Django template code in your Django <1.4 project? Look no further than this script! It's rather crude, but gets the job done. I haven't yet updated a few Django websites to Django 1.5, which has a new template tag to do this for you, so I created this script to use in legacy Django sites, and it works like a charm!

    #!/usr/bin/python
    
    import sys
    
    try:
      filename = sys.argv[1]
    except IndexError:
      print "This command needs exactly 1 parameter!"
      sys.exit()
    
    data = open(filename, 'r').read()
    data = data.replace('{%', '{! templatetag openblock !}').replace('%}', '{! templatetag closeblock !}')
    data = data.replace('{{', '{% templatetag openvariable %}').replace('}}', '{% templatetag closevariable %}')
    
    print data.replace('{!', '{%').replace('!}', '%}')
    

    You should Pygments to highlight the syntax like I do on this blog of course. If you are using Django 1.5 or greater, you should use the verbatim template tag over this.

  • Building a set of indie community focused Django apps

    Posted on Friday, May 10th, 2013

    Today I have just started work on an set of Django pluggable apps which can either be used independently or as a whole. The main focus is to provide Indie developers with an entire website framework which can be used to host a database of indie downloads, manage assets, support developer blogs and vlogs, and much more. I am building this as an open source project from the start, and it is hosted on BitBucket with the discussion hosted on Uarica.

    The first prototype of the website is done for anyone that's curious on how it currently looks, it can be accessed here.

    Uarica Project page
    BitBucket page

  • A birthday present for a friend made in Django

    Posted on Friday, April 19th, 2013

    I have a friend whom is a huge, and I really mean huge movie buff. He has the largest movie collection that I know of, and one the largest TVs I have seen. He was previously managing his collection using another website someone built, which I think is personally not very well done and my friend deserves much better!

    First I used the standard Python XML libraries to parse and extract all the movies he has on the old website, as I didn't want to re-enter all those movies, and I'm sure he wouldn't either. After it was all extracted and I was able to parse it easily through Python, I created the Django project and models for which the movie titles will live in. I created the first part of the website, including the importing of all his movies in just a mere 4.5 hours(according to my Subversion timestamp). I was truly amazed at what a full featured web application I could create in such little time, I could barely sleep last night as I wanted to continue work and add new features.

    Now, the website is nearing completion and I thought I'd share it here with all my loyal readers. This web application has full IMDb integration, which still has a few bugs here and there that need to be ironed out. I am currently debating if I should open source this creation or not...

    You can check this application at Cinema-Nick.com.

  • Will be taking another look at web2py

    Posted on Wednesday, April 10th, 2013

    My last encounter with Web2py was with version 2.0, this was back in October of 2012, of which I have a review for that version. Reviewing their changelog, I can see that this framework has evolved a great amount in just a few short months. There were many features which I praised about the framework, but there were still some things holding me back from using it over Django for my next project. So, with that, I am planning on diving back into web2py, and should have a new review up with the latest version. I have a project, I am thinking I may convert over to web2py and see how that goes. If development becomes quicker, then I will consider web2py for future projects as well.

    If you haven't already, I would recommend taking a look at web2py and see what it can offer your project. Both Django and web2py are similar, but at the same time they are very different. They both took the Ruby on Rails idea in their own direction. One thing to note, is that apps in web2py are not like apps in Django. This also makes working with web2py a little difficult at times, as it's not easy for apps to talk to each other, not as easy as it is in Django that is. However, in web2py, it's not an apps purpose to extend the frameworks functionality, it is the job of a plugin. That being said, web2py has grown a large amount since I last used it, so all my hardships I experienced last time around might be resolved.

  • Django 1.5 review is up

    Posted on Sunday, April 7th, 2013

    For those interested in Django to see if it's right for your next project, or if you are upgrading from an earlier version, this review is for you.

  • Source code released for my Django PIM suite

    Posted on Friday, April 5th, 2013

    Not sure how many of you were following my previous blog post about a bunch of Django apps I built for my own personal use. I have finally released the source code into BitBucket. Here's a short copy and paste recap of what you can find:

    PCBank AKA myFinance
    This is a personal budgeting system which I have created, it has matured a lot throughout the past few months. I originally created it in October of 2011, as using a spreadsheet to keep track of all my expenses grew tedious. It can also manage roommates, and split bills accordingly. This is my most used app out of all of the apps I created. It also has an RSS and JSON interface for third party applications to fetch data. I use the RSS for a Live Bookmark to easily access all my online banking websites from my browser toolbar. I use the JSON interface with a mobile app I created so that I can easily check my bank balances on the go without needing to actually sign into my online bank website on an insecure wireless network.
    myProjects
    This app was created in recent months to keep track of my many projects I do. It keeps track of individual projects, which I can jot down notes about each one. I can create goals under each project and assign a due date for them. This makes seeing all my workload and upcoming goals easy to browse, and add personal notes to.
    myServers
    Sort of an extension to myProjects above, as it keeps track of my various servers I run and operate. It sorts the servers by hosting provider. Then under each server, I can list the various applications which the server runs. Makes it easy to know where everything is located in my infrastructure.
    django-pim Source code

    Let me know what you think, all of these use Bootstrap for theming and some of them have APIs such as iCalendar, RSS, and JSON. PCBank was developed a very long ago, and some of the programming practices in there need some updating. I have included an svnlog.txt file in each app's directory so you can see just how each project grow since 2011. Yes, you heard me... 2011 was one of the early commits.

  • Using Pyjamas with Bootstrap

    Posted on Thursday, April 4th, 2013

    For a just for fun experiment, I attempted to re-create the standard Bootstrap, from Twitter theme using Pyjamas. It turned out pretty good too. Here is the source code to compile to JavaScript:

    from pyjamas.ui.RootPanel import RootPanel
    from pyjamas.ui.Button import Button
    from pyjamas import DOM
    from pyjamas.ui.Hyperlink import Hyperlink
    from pyjamas.ui.SimplePanel import SimplePanel
    from pyjamas.ui.ComplexPanel import ComplexPanel
    from pyjamas.ui.FlexTable import FlexTable
    
    class CustomPanel(ComplexPanel):
        def __init__(self, Element=None, **kwargs):
            if Element is None:
                Element = DOM.createDiv()
            self.setElement(Element)
            ComplexPanel.__init__(self, **kwargs)
    
    class NavItems(CustomPanel):
        def __init__(self, nav_list=None, **kwargs):
            CustomPanel.__init__(self, Element=DOM.createElement("ul"))
            self.addStyleName("nav")
            self.items = []
            if nav_list == None:
                nav_list = {'Home': self.onClick, 'About': self.onClick, 'Contact': self.onClick}
            for item in nav_list:
                tmp = Hyperlink(item, Element=DOM.createElement("li"))
                tmp.addClickListener(nav_list[item])
                self.items.append(tmp)
            for item in self.items:
                self.add(item)
        def clearActive(self):
            for item in self.items:
                item.removeStyleName("active")
        def onClick(self, sender):
            self.clearActive()
            sender.addStyleName("active")
        def setActive(self, item_id):
            self.clearActive()
            self.items[item_id].addStyleName("active")
    
    class NavBar(SimplePanel):
        def __init__(self, brand="Project name", nav=None, **kwargs):
            SimplePanel.__init__(self, **kwargs)
            self.addStyleName("navbar")
            self.addStyleName("navbar-inverse")
            self.addStyleName("navbar-fixed-top")
            self.setWidget(SimplePanel())
            self.getWidget().addStyleName("navbar-inner")
            self.container = CustomPanel()
            self.getWidget().setWidget(self.container)
            self.container.addStyleName("container")
            self.brand = Hyperlink(brand)
            self.brand.setElement(self.brand.anchorElem)
            self.brand.addStyleName("brand")
            self.container.add(self.brand)
            if nav == None:
                self.nav = NavItems()
            elif isinstance(nav, dict):
                self.nav = NavItems(nav)
            self.container.add(self.nav)
            self.nav.setActive(0)
        def setBrand(self, text):
            self.brand.setText(text)
        def setActive(self, item):
            self.nav.setActive(item)
    
    navbar = NavBar()
    state = 0
    
    def alter_brand(sender):
        global state
        navbar.setActive(1)
        if state == 0:
            navbar.removeStyleName("navbar-inverse")
            state = 1
        else:
            navbar.addStyleName("navbar-inverse")
            state = 0
    
    btn = Button("Hello Bootstrap!", alter_brand)
    btn.setStyleName("btn btn-primary")
    
    container = CustomPanel()
    container.addStyleName("container")
    container.add(btn)
    
    RootPanel().add(navbar)
    RootPanel().add(container)
    
    tbl = FlexTable()
    tbl.addStyleName("table")
    tbl.setText(0, 0, "Hello World!")
    tbl.setText(1,0,"Python rocks")
    tbl.setText(0,1,"Coding in my Pyjamas is awesome!")
    tbl.setText(1,1,"Bootstrap works with Pyjamas!")
    tbl.addStyleName("table-striped")
    
    container.add(tbl)
    

    This code requires the latest version of Pyjamas, version 0.8.1a as of this writing. It won't work in 0.8, which I'm curious on why. You can see a full working demo here.

About Me

My Photo
Names Kevin, hugely into UNIX technologies, not just Linux. I've dabbled with the demons, played with the Sun, and now with the Penguins.




Kevin Veroneau Consulting Services
Do you require the services of a Django contractor? Do you need both a website and hosting services? Perhaps I can help.

If you like what you read, please consider donating to help with hosting costs, and to fund future books to review.

Python Powered | © 2012-2013 Kevin Veroneau