Over the past year, I've built 2 projects related to Charts, Python-NVD3 & Django-NVD3. For those of you who aren't familiar with NVD3 yet, please visit their website (http://nvd3.org/), NVD3 will help you build re-usable and attractive charts with the power of D3.js (http://d3js.org/).
A screenshot of a PieChart created with NVD3 (the real example is interacive):
Example link: http://nvd3.org/examples/pie.html
If you want to play with examples on Jsfiddle?
-> http://jsfiddle.net/areski/z4zuH/246/
In my day to day work, I use Python & Django, so I'll let you guess what my next step was. I started building a simple wrapper on top of the NVD3 javascript library. The goals were simple, I needed to simplify injecting charts into my (Django) web projects. Indeed, a lot of my projects have built-in dashboards or reporting tools, having those without a few charts is no fun at all for your users.
NVD3 is a great piece of software and a big thanks to Novus for making this project open source.
Novus released a project that will cover most of my chart needs and maybe yours, they did a great job which lead to a successful open source project with plenty of contributers. Now it was time for me to build something I could use accross my Python projects.
So here comes Python-NVD3: https://github.com/areski/python-nvd3
After the installation of Python-nvd3, you can create a variety of different charts (cumulativeLineChart, discreteBarChart, scatterChart and more).
If you want to create a Piechart Chart with Python-NVD3, here is a quick example:
from nvd3 import pieChart
#Open File to write the D3 Graph
output_file = open('test-nvd3.html', 'w')
type = 'pieChart'
chart = pieChart(name=type, color_category='category20c', height=450, width=450)
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
#Create the keys
xdata = ["Orange", "Banana", "Pear", "Kiwi", "Apple", "Strawberry", "Pineapple"]
ydata = [3, 4, 0, 1, 5, 7, 3]
#Add the serie
extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}}
chart.add_serie(y=ydata, x=xdata, extra=extra_serie)
chart.buildhtml()
output_file.write(chart.htmlcontent)
#close Html file
output_file.close()
Finally, Django-NVD3 is my attempt at using the power of Python-NVD3 within Django's project: https://github.com/areski/django-nvd3
So far, there are a good amount of contributors and I'm really looking forward to seeing how this simple
library will grow. If you have ideas, suggestions, feel free to comment here or contact me on twitter @areskib
Yesterday, we released a new version of both projects. Thanks to the help of Justin (https://github.com/jmduke) the javascript output is rendered with Jinja2, which is a much cleaner approach.
Docs:
http://python-nvd3.readthedocs.org/en/latest/
http://django-nvd3.readthedocs.org/en/latest/
Bon Python!
]]>Asterisk is an open source PBX system, created by Digium, more exactly, authored by Mark Spencer. Asterisk PBX allows people to make calls to each other but also connects them with telephone services, such as reaching the public network or VoIP services. Asterisk is certainly the number one PBX system out there.
We can see many advantages in using Asterisk inside Docker, the main reason in my case was to solve my development environment. It allows us to spawn small Asterisk containers and test them with applications without needing to alter our own OS or use a heavy VM system. Docker is extremely fast and in a matter of seconds the container is running.
There is also a significant potential in deploying Asterisk for customers, for instance companies willing to provide small PBXs containers to their clients will find docker especially interesting.
This post is a simple recipe for how to create an Asterisk Docker. Right now, the only flaw is the port mapping, as we speak Docker doesn't have an elegant way to map range of ports
to a container, this can be sorted with a long command line but it just won't be very pratical. This will certainly be sorted in the future, there is work in progress on the matter: https://github.com/jhorey/docker/pull/1
Before Docker 0.8 you might have encountered an issue in mapping UDP & TCP on the same port, this has now been solved in docker v0.8, so make sure you have 0.8 running at least.
Download Debian images:
$ docker pull debian
Run an image on a new container:
$ docker run -i -t debian:wheezy /bin/bash
$ Install Asterisk & Apache2
$ apt-get -y install apache2 asterisk
Docker doesn't currently allow a range of ports to be opened, as such all RTP ports have to be specified on the command line. In the example above we are only opening 10, so you will be limited to 10 simulataneous calls.
Edit the Asterisk RTP configuration to ensure only these ports are used.
Edit /etc/asterisk/rtp.conf
:
rtpstart=16384
rtpend=16394
Or:
$ sed -i "s/rtpstart=10000/rtpstart=16384/g" /etc/asterisk/rtp.conf
$ sed -i "s/rtpend=20000/rtpend=16394/g" /etc/asterisk/rtp.conf
Start Asterisk:
$ /etc/init.d/asterisk start
Check that is well running and listening:
$ netstat -nap | grep asterisk
$ CTRL-P + CTRL-Q (this will return to your shell and keep the container running)
Retrieve the last Container ID:
$ `dl`
# dl is an alias -> alias dl='docker ps -l -q'
Commit your last container and create a new image:
$ docker commit -m "Asterisk with Apache" `dl` mydebian_apache_asterisk
Now, you can launch a new container and open ports for your container mydebianapacheasterisk:
$ docker run -d -p 9080:80 -p 5060:5060/tcp -p 5060:5060/udp -p 16384:16384/udp -p 16385:16385/udp -p 16386:16386/udp -p 16387:16387/udp -p 16388:16388/udp -p 16389:16389/udp -p 16390:16390/udp -p 16391:16391/udp -p 16392:16392/udp -p 16393:16393/udp -p 16394:16394/udp mydebian_apache_asterisk run
You can start as many containers as you want and stop them with docker stop
. The command docker ps
will allow you to watch all the running containers and the ports mapped to them.
I hope you found this post useful, feel free to drop some comments.
]]>Nikola is a static Blog & Site generator, it's built in Python and it's to my opinion a very interesting Python project and one of the best site generator out there. I want to take the opportunity to thanks Roberto Alsina, who authored and who support the project, as well as Chris "Kwpolska" Warrick who is a major contributor to Nikola.
Nikola website: http://getnikola.com/
Python Package : https://pypi.python.org/pypi/Nikola/
On Github: https://github.com/getnikola/nikola
Nikola take his name from Nikola Tesla, which is considered as one of the greatest geek of all times, he invented fluorescent lighting, the Tesla induction motor, the Tesla coil, and developed the alternating current (AC) and many other things.
Nikola has many features, the most remarkable ones are:
I personally designed few website with Nikola and from my experience it has been a breeze even to create multi-languages website (English, Spanish & Catalan). To show an example, here 2 websites I built & deployed using Nikola/Bootstrap3:
There is many reasons that are well explained by Roberto Aslina (http://getnikola.com/handbook.html#why-static). There is countless advantages, but the most notable ones is that is crazy fast as you remove all the logic of dynamic website and just deliver your content, plus you can take advantage for free hosting provided by Github (http://pages.github.com/), I will definitely trust more Github than my own hosted webserver. By experience, I had many sites using Wordpress and they ended up into a costly maintenance effort, many security updates, down-time and so many problems you really want to be taken off your shoulders. So static is the answer in many cases, I really try to ask myself why do I need a dynamic website and if I don't find a very good reasons then it means that static fit perfectly.
The recommended formats are reStructuredText and Markdown, but there is also support for textile and WikiCreole and even for just writing HTML. I use Nikola with reStructuredText so if you don't have a preference, here a quick tutorial http://getnikola.com/quickstart.html and there is a handy Online reStructuredText editor that may help you to learn some rst quickly: http://rst.ninjs.org/
Enough, it's time to get started, no? Let's show you how to create a simple website with Nikola.
1) create a virtualenv :
$ mkvirtualenv kickass-website
2) install nikola:
$ pip install Nikola
3) install python-requests & livereload:
$ pip install requests==2.2.1
$ pip install livereload==2.1.0
Now type nikola and you should be good to get started!
Let's type nikola help
, this will give us an idea of all the command available by Nikola.
$ nikola help
Nikola is a tool to create static websites and blogs. For full documentation and more information, please visit http://getnikola.com
Available commands:
nikola auto automatically detect site changes, rebuild and optionally refresh a browser
nikola bootswatch_theme given a swatch name from bootswatch.com and a parent theme, creates a custom theme
nikola build run tasks
nikola check check links and files in the generated site
nikola clean clean action / remove targets
nikola console start an interactive Python console with access to your site
nikola deploy deploy the site
nikola doit_auto automatically execute tasks when a dependency changes
nikola dumpdb dump dependency DB
nikola forget clear successful run status from internal DB
nikola help show help
nikola ignore ignore task (skip) on subsequent runs
nikola import_blogger import a blogger dump
nikola import_feed import a RSS/Atom dump
nikola import_wordpress import a WordPress dump
nikola init create a Nikola site in the specified folder
nikola install_plugin install plugin into current site
nikola install_theme install theme into current site
nikola list list tasks from dodo file
nikola mincss apply mincss to the generated site
nikola new_post create a new blog post or site page
nikola orphans list all orphans
nikola run run tasks
nikola serve start the test webserver
nikola strace use strace to list file_deps and targets
nikola tabcompletion generate script for tab-complention
nikola version print the Nikola version number
nikola help show help / reference
nikola help <command> show command usage
nikola help <task-name> show task usage
1) We will create now a demo site with demo files to explore nikola
$ nikola init --demo mykickasswebsite
This create the directory mykickasswebsite, if you don't want the demo files, then you can simply remove --demo
I will recommend to explore the files that has been created by nikola, those will help generating your static website.
2) From here, you should be able to build the website, this will create all the static files needed by your webserver to deliver a kickass website:
$ cd mykickasswebsite
$ nikola build
... some magic is happening here!
All the static files are stored in the folder output
, you can open the output/index.html
in your web browser, but there is nicer way we will show after how to see the result on your browser.
When you enter in the new site directory you will notice the following structure:
files
galleries
listings
posts
stories
files
directory contains static assets that you want to have available regardless of the theme you use. galleries
reveal the photo gallery feature of Nikola. Inside this directory you can create as many directories as you like, each being a separate gallery. listings
, is for source code listings, please refer here for further information http://getnikola.com/handbook.html#id41posts
get more to the heart of Nikola. This directory will keep all your post files in a chosen markup language. stories
, it contains all the "static" pages (non-post pages) you wish to serve. Things like an about or contact page would fit nicely there.The main page is stored in stories/index.rst, so you can update this file and then run nikola build
again.
3) Now let's type nikola serve
to serve locally all the static files built:
$ nikola serve
Point your browser to the ip/port indicated, normally it should be http://127.0.0.1:8000/
'CRTL-C' on terminal to stop it!
4) If you remember we installed livereload
earlier this will help us to reload automatically our website every time we edit our code.
$ nikola auto
So this is a much nicer way than nikola serve
5) Let's keep nikola auto
and let's try create a new post by running nikola new_post
$ nikola new_post
Creating New Post
-----------------
Enter title: my new post
Scanning posts....done!
[2014-02-13T16:17:46Z] NOTICE: new_post: Your post's text is at: posts/my-new-post.rst
Now edit posts/my-new-post.rst
and write some text to finalize your first blog post on Nikola.
If you kept nikola auto
running you will notice that your home page changed automatically and displayed the new post.
All of this also produced new static files, saved in the output/
folder which you can host on a webserver (or github) and power your awesome kickass website freely hosted.
6) Let's change the theme to bootstrap3.
$ nikola bootswatch_theme bootstrap3
This command download and install bootstrap3 on your Nikola website.
You will notice a new directory themes
which contains a directory custom
,
you can explore this directory to customize the bootstrap3 theme .
bootswatch_theme
allow you to download and install theme from http://bootswatch.com/
7) Let's explore conf.py
, let's start by configuring properly few settings:
# Data about this site
BLOG_AUTHOR = "Your Name"
BLOG_TITLE = "Demo Site"
# This is the main URL for your site. It will be used
# in a prominent link
SITE_URL = "http://getnikola.com/"
# This is the URL where nikola's output will be deployed.
# If not set, defaults to SITE_URL
# BASE_URL = "http://getnikola.com/"
BLOG_EMAIL = "[email protected]"
BLOG_DESCRIPTION = "This is a demo site for Nikola."
Other important settings you will want to configure are the menu:
# Links for the sidebar / navigation bar.
# You should provide a key-value pair for each used language.
NAVIGATION_LINKS = {
DEFAULT_LANG: (
('/archive.html', 'Archives'),
('/categories/index.html', 'Tags'),
('/rss.xml', 'RSS'),
),
}
I think that will be enough for today, if you feel Nikola is the right tool for you, I can recommend those extra references:
Why share new pictures when there are good old ones ?
I dug in my archive folder and found a few good picks that had never had the chance to hit the Web. They are a year old and were taken during a trip to Costa Rica & Nicaragua. I hope you enjoy them, they are full of good memories!
This work is licensed under a Creative Commons Attribution 4.0 International License.
There have been huge amounts of exciting Go projects emerging in the last year, just to give a brief list of the ones I found very interesting:
Docker: http://www.docker.io/ which has just announced their new release 0.8 (http://blog.docker.io/2014/02/docker-0-8-quality-new-builder-features-btrfs-storage-osx-support/)
Viewdocs: https://github.com/progrium/viewdocs when Read the Docs meets Gist.io, a pretty small codebase but shows the huge potential of Go
Etcd: A highly-available key value store for shared configuration and service discovery https://github.com/coreos/etcd
CGrates: Rating system for telecom operators http://cgrates.org
Vitess: it's a library that provides tools that facilitate the scaling of MySQL databases to large scale web services, built by Youtube https://github.com/youtube/vitess
Tiedot: It's a low-resource NoSQL database implemented in Go. It's designed to be easily embeddable in Go programs, but also runs as a standalone HTTP service. https://github.com/HouzuoGuo/tiedot
Boom: HTTP(S) load generator https://github.com/rakyll/boom
Go has very interesting properties compared to other languages:
It seems to be a perfect fit for scientific computing, high concurrency, server applications, and talking with little experience of Go, it also seems to be a good fit for web:
http://blog.kowalczyk.info/article/uvw2/Thoughts-on-Go-after-writing-3-websites.html
If you fancy learning something new today, why not? Go is a great language, growing a lot in popularity and adoption in companies. As a Programming Language, Go is a pragmatic evolution of C and includes countless benefits of other languages like Python & Ruby.
A good place to get started could be Go by Example.
Are you learning Go, if so what is your opinion? Do you think that Go will play a huge part of our IT ecosystem in the following years?
]]>Nikola a great Static Site and Blog generator and the codebase is all Python which is a great plus for Pythonist, the project is very mature and includes douzen of plugins and free templates. So quite a good choice if you look at a solution for your next website!
If you don't know Nikola project you should definitely check it out. I used Nikola to create few websites: http://pybcn.org/ & http://emerzia.com/ and it has been just pure pleasure!
It comes with a bunch of great plus compare to others, it's very fast to learn, the documentation is clear as the codebase which is very easily hackable. Take few minutes and go ahead to create a simple site: http://getnikola.com/creating-a-site-not-a-blog-with-nikola.html
There is 2 important quality I appreciate from Nikola:
- Static: Improve security, hosting cost highly reduced (or free) and performance. If you have used Wordpress in the past, at some stage you had security issues, either a plugins that bring some vunerability or the setup of WP wasn't perfect.
- Python: When you need to do some changes into your blog engine, you definitely appreciate if the codebase is the actual language you work with.
Thumbs-ups!
Nikola fitted perfectly for my needs on side creation and still does, but not for blogging, when blogging I wanted a tool on which I feel I was writing, not coding, something like Wordpress but without the issues of WP, slow, own hosting, security problem.
Here comes Ghost, simple blogging engine, write your post with 'markdown', kind of WYSIWYG feeling, let's share a screenshot:
Ghost provide hosting but all the code is fully Open Source (Github) and so you can host it yourself. Now I'm a big fan of Github Pages : http://pages.github.com/ if your site is static, it's a nice way to get free & performan hosting.
Came at the rescue Buster (Yes like in GhostBuster), this python project will allow you to scrape your local Ghost website, save it into a static directory and push it to your Github repo where you host your website :
https://pypi.python.org/pypi/buster/
Introduction to buster : http://blog.axitkhurana.com/introducing-buster/
This is quite a neat way to get the good of all sides, enjoy the nicest blogging engine, get a great hosting without worry and even be able to blog offline in train, plane, wherever you feel like writing.
So check out Ghost, it might not be the right tool for you but it will certainly inspire you!
]]>Telefony & Web development has been my main occupation for the last 9 years, during this time I have had the chance to author and opensource a few projects related to Telefony, some working with Asterisk & others with FreeSWITCH.
I wanted to present some of the most popular projects in a short post:
Newfies-Dialer is a voice broadcast/autodialing application, which can fulfil a variety of roles for organisations who wish to call large numbers of people.
The Newfies-Dialer aplication uses RabbitMQ so that it can support distributed processing on cloud servers. The platform is built to perform millions of calls that can be processed daily.
Newfies-Dialer was commissioned by a charity named Kubatana (http://www.kubatana.net) based in Zimbabwe, which sponsors the Freedomfone project (http://www.freedomfone.org/) dedicated in providing information via phone technology.
You can find more about Newfies-Dialer at http://www.newfies-dialer.org
CDR-Stats is a call analysis and reporting software for Freeswitch, Asterisk and other types of VoIP Switch. It allows you to interrogate CDR and provide realtime reports and statistics.
It is based on the Django Python Framework, Celery, SocketIO, Gevent, PostgreSQL and MongoDB.
You can find more about CDR-Stats at http://www.cdr-stats.org
A2Billing is a telecom switch and billing system capable of providing billing for telecom products and services to customers such as calling card products, residential and wholesale VoIP termination.
It is built using PHP, Mysql, Asterisk, AGI.
Find more about A2Billing at http://www.asterisk2billing.org
]]>Getting started with Docker is very simple, I'm going to give you a very simple recipe to get started quickly, I would first recommend to use DigitalOcean, they provide box with Ubuntu 13.10 and Docker ready for you, so at a very low cost you can start playing with Docker and not have to worry to install anything locally.
If you wish to install Docker locally you can follow this guide : https://www.docker.io/gettingstarted/#h_installation
Ready!? So let's play with Docker then, you can now type docker
and you will get list of all available commands.
Type the following:
docker run ubuntu /bin/echo hello world
This should output 'hello world'. Just one line?
Docker did all of the following:
You can also run an interactive shell session inside the container
docker run -i -t ubuntu /bin/bash
To detach from the container crtl-p + crtl-q
Searching for a docker image: docker search [image name]
Try: docker search ubuntu
Run a container and stay attached to the shell session:
docker run -i -t ubuntu /bin/bash
You should see your shell changing to something like: root@b99484200e8t:/#
Type apt-get update
and now install Apache2 : apt-get install -y apache2
Now you can detach (crtl-p + crtl-q)
By default Docker will expose the port 80 of the container to a random port of the host.
So let's list the current containers : docker ps
You should be able to see the port number that is mapped (ie '49158->80'), in your web browser open the IP of your Droplet follow by the mapped port. You should see the Apache running from your docker.
To finish for today, let's now see what happen on our container, let's type docker diff ID_Container
(ID_Container you can find it by typing docker ps), with docker diff are able to inspect all the changes made on the container's filesystem.
That's all for this short post, now you can explore the documentation and docker tutorials out there: http://www.docker.io/
]]>We all have a #shit# lot of work, aren't we? Maybe you try to run a company, have a busy job, do sport, enjoy leisure, watch a movie, read a book or two... My feeling is that time is always flying, I enjoy everyday but rarely have the time to do everything I would like to, and maintaining my blog is one of them. My previous blog started 9 years ago, I did few posts the first few months and then it get lost among the hundreds of other priorities which were always more important.
I really wonder how peoples keep themselves rigorous on writing, specially if they are coders? I hope this time it won't be again my next New Year resolution! And how do you become good at it, is perseverance and persistence the key?
Well as you guessed, this is my new attempt in blogging, a desire in sharing text rather than code! I hope by getting feedback it will keep me motivated, and to get feedback I need first to write something worth reading :)
I know I want my personal blog to be about my experience, a way to share some of my knowledge, a place where I could freely share doubts/questions and try new way to communicate, basta twitter... I hope this won't get lost in the immensity of the Internet, I will definitely try harder this time :)
I'm trying to gather few ideas for the upcoming posts:
We may hear a lot about Python / Django / Flask, but I will definitely do some efforts to not be too religious about the Python world, I'm also interested into Lua, Erlang, GoLang, about Deployment, CI, testing, Telephony, so I guess there is a lot of topiics to the rhythm of the blog.
Stay tuned!
]]>