welcome to METAROA tutorials searcher Last published Programming Tutorials on July 30, 2010, 8:55 pm
|
|
- How to Avoid, Find (and fix) Memory Errors in Your C/C++ Code
Explore the different types of memory errors and how to use Intel Parallel Inspector to debug your code



- The Secret to Learning Anything
Some of the most important lessons I learned in college came from one professor, Michael Mitzenmacher. Now, this was a guy with a lot of papers to his name, tenured at Harvard, working on some pretty darn complicated computer science theory (I took his algorithms class). So you'd expect that I'd learn something important. But as it turned out, the biggest lessons I learned from him weren't on the topics he taught. I learned a secret that helped me learn much more effectively.



- Programming Practice Problem - Temperature Conversion
A practice program for beginners--write a program that converts Celsius to Fahrenheit and puts it into a nicely formatted table



- Ebook survey
Help us serve you better by completing this very short survey!



- Programming Practice Problem - Computing File Size
In this challenge, given the name of a file, print out the size of the file, in bytes. If no file is given, provide a help string to the user that indicates how to use the program. You might need help with taking parameters via the command line or file I/O in C++ (if you want to solve this problem in C, you might be interested in this article on C file I/O).



- 5 Ways You can Learn Programming Faster
Learning to program isn't something you can do in an afternoon, but it doesn't have to be a life's work, either. There are lots of things you can do to make it easier on yourself when you are learning to program. You already know about The 5 Most Common Problems New Programmers Face--And How You Can Solve Them. Now, discover how to get the most out of your learning.



|
- Migrating a Legacy Forum to vBulletin 4.0.3
How to switch from a legacy forum to vBulletin, and customizing vBulletin.


- Create Your First Application With Ext4Yii
The Ext4Yii Framework brings the power of ExtJS and the Yii Frameworks together. This tutorial is first of Ext4Yii tutorial series.


- 10 Signs of Crappy PHP Software
Like it or not, as a professional developer, sooner or later you are going to do some customising (if you are lucky, "extending") of existing software.


- Monte Carlo Simulations
Monte Carlo simulations are a handy tool for looking at situations that have some aspect of uncertainty, by modelling them with a pseudo-random element and conducting a large number of trials. There isn’t a hard and fast Monte Carlo algorithm, but the process generally goes: start with a situation you wish to model, write a program to describe it that includes a random input, run that program many times, and look at the results.


- CRUD using jQuery and Codeigniter - Part 1
In this tutorial you will learn:
1. How to use jQuery with Codeigniter.
2. How to send Ajax request to perform READ operation.
3. How to use jQuery UI tabs widget.
4. How to use Microsoft’s jQuery templating plugin.


- CRUD using jQuery and Codeigniter - Part 2
In Part 2, you will learn:
1. Displaying Ajax loader animation when an Ajax call is made.
2. How to inject Update/Delete link in each record using jQuery.
3. How to use jQueryUI dialog widget.
4. How to send Ajax request to perform DELETE operation.
5. How and when to use jQuery’s delegate method to bind events.


|
- Montreal Python User Group: Pylons presentation is online
Alexandre Bourget’s energetic presentation on Pylons is at last online: Pylons, Web development done right.
Your browser doesn’t support HTML5. Please use the download link.
If you use Safari and want to use a libre format, install the Xiph QuickTime Component at http://www.xiph.org/quicktime
- Jesse Noller: Miscellanea – Python Sprints, Nasuni, etc.
I’ve obviously been quiet here on my personal blog – as everyone who reads regularly knows I’m neck-deep in a pretty exciting startup call Nasuni as well as doing other projects, like the PSF Sponsored sprints thing. That combined with twitter means my time for other additional long-form content is minimal. So here’s a small roundup of interesting things:
Nasuni
Yup, still running Python and Django! We’re actually pretty proud to be a sponsor for DjangoCon 2010 coming up in September – I’ll be attending, so I hope to see all the familiar Django faces I know, and meet some new ones.
I’ve been blogging semi-regularly for the Nasuni blog itself – my posts are focused on product-things more than anything else. Here’s a small list of posts which I’ve done:
- The Road to Release – Feature Previews – this is actually my latest one, and the first in a series where I’ll be showing off some of the new features we’re adding in the latest release.
- Looking at OpenStack, a Rackspace and NASA initiative – For those of you who don’t know, Rackspace and NASA announced OpenStack – the awesome part? It’s all python – I had the swift component (which powers Rackspace’s cloudfiles system) of OpenStack running pretty quickly. I’d recommend snagging the code from launchpad and taking a look. Swift (the storage component) uses eventlet – and Nova (the compute part) uses Tornado and Twisted.
- Storage Switzerland Test Drives the Filer – This is a response to an article written about the product – I actually used it to preview some of the work going into the next release of the Filer.
- Thanks to Django – This piece goes into some detail about our use of Django, it’s one of our ways of saying thanks. I still need to rework it so we can send it over for the Django Success Stories page.
- Thanks to the Supporting Cast – This is an earlier thank you post – but to the other people who have helped out a ton, including Greg Newman, Lincoln Loop, and Revsys.
- The Donut Solution – This was a fun one, mainly to show that yes – we’re listening hard to customer feedback, and we’re improving/iterating quickly. Also, I get to show off UI improvements.
- Finally – The Nasuni Blog team – this is the rosetta stone for the authors of the blog, describing who we are. I didn’t write this piece, but it’s good reading to figure out who is who.
If you’re interested in Nasuni – or cloud storage in general – I’d encourage you to sign up for the RSS feed. We’re trying to keep the information useful outside of “just us” (despite my urge and predilection to churning out completely product-related posts) – and if you ever have feedback, drop us a line.
PSF Sponsored Sprints
The project continues on – we’ve funded two sprints so far, and have several more coming down the pike. We’re always in need of volunteers to help us do things like the manuals and site maintenance/content authoring. Here’s some highlights:
- The call for applications is open – The call for applications is open – and now I suspect we won’t be closing it. Originally, I thought we’d have to do things in waves of apply-approve. As time has progressed, I no longer think this is the case.
- Montreal Python Packaging sprint wrap up – the wrap up report for our first sprint!
- Europython core sprint report - another wrap up report for the core sprint we provided funds to.
- Just added the locations page – we now have people/companies offering up space for sprinters! Check it out!
- Finally - Sprints at PyOhio – PyOhio is going on this weekend, if you’re in the area you should really go check it out! Catherine has gone above and beyond with the entire “become a contributor” effort going on.
Please! If you’re thinking about holding a sprint - send us an application! Heck, even if we’re not sponsoring it, we’ll help promote you via the blog, and the sprint calendar we have up. A little fact? The sprints we’ve funded so far, and that are on deck for funding are all outside of the US, which is both awesome, and surprising!
PSF Board
Some of you probably know that I’m currently on the board of directors for the PSF – things progress well here, but I mainly wanted to call out the excellent blog Doug Hellmann has been authoring for PSF news. You should really be watching that because yes – we do do things, and hopefully over the next year, we’ll be doing more awesome things.
I’ve actually got a bigger post in the works for what I think the ultimate mission of the PSF is/should be as well as “how do you get money from us” as well. Must find the time!
- Lightning Fast Shop: Released 0.5.0 beta 4
Today we released LFS 0.5.0 beta 4
What's new?
- Bugfix pages: caching page_view
- Bugfix cart: display correct stock amount within growl message
- Bugfix product_inline: display property title within error message
- Bugfix order_received_mail.html: display the correct selected values of a configurable product
- Bugfix cart: calculation of maximum delivery date
- Bugfix redirect: save redirect url for variants
- Bugfix lfs.page.views: added missing import of Http404
- Bugfix: restrict adding to cart if the product is not deliverable. Issue #37
- Added french translations (Jacques Seite)
- Added get_properties method to OrderItem
- Added optional cached parameter to cart/utils/get_cart_price and cart/utils/get_cart_costs
- Removed javascript which dynamically sets the height of the slots.
- Changed properties management: display name instead of title within left portlet
- Improved lfs.portlet: caching
Further Information
You can find more information and help on following places:
- Salman Haq: A Simple Experiment with Hookbox
Hookbox is a new Python-based comet server with support for Websockets. It’s main features include:
- Support for named channels on which data is published/subscribed.
- Server-side Websocket and WSGI support via the eventlet concurrent networking library.
- Client-side Websocket support via js.io.
- Fall-back to a custom comet protocol when websocket support is not available in the browser.
- A RESTful api to interact with the channels.
- Easy integration with web frameworks like Quixote and Django, again via web hooks.
- A built-in admin interface to view the state of active channels and users.
It has been authored by some of the original people behind Orbited and represents a significant simplification in the process of writing websocket-enabled web apps primarily because it includes its own message broker.
Experiment: Graphic EQ
To better understand Hookbox, I decided to write a web-based graphic EQ which updates itself based on data produced on the server (strictly speaking, a graphic EQ is a control instrument, but my example presents it as a measurement instrument so perhaps calling it a web-based spectrum analyzer would be more appropriate). Checkout the video below to see it in action:
Hookbox Graphic EQ Demo from Salman Haq on Vimeo.
The top-half of the clip shows the equalizer bands dynamically updating in Firefox (v3.6.8) while the bottom-half shows the Firebug pane displaying the live network calls. If you look carefully, you will see that in this particular experiment all the network requests used the CSP protocol and not the websocket protocol. This is expected because websocket support is only available in version 4 or later of Firefox.
The video capture was a bit sluggish so it’s worth mentioning that it actually ran much smoother than it appears in the video. This is due to the fact that graphics acceleration is improperly configured on my quad-core box. (Side note: Each time I upgrade to the latest Ubuntu release, my video and printer settings need to be tweaked significantly to recover optimal performance. Since I upgraded to Lucid Lynx, I have not been able get the video performance I would like).
Trials
The experiments were repeated using three data publishing rates: 10 Hz, 100 Hz, and 1000 Hz. I should note that the producer.py process used time.sleep() which is not very precise on systems running a non-realtime kernel which typically lack high-precision timers. At the 10 and 100 Hz rates, the browser was able to keep up with the deluge of data and rendered the bands quite smoothly. At the 1KHz rate, all of my system’s cores reached maximum loading and Firefox rendered the bands rather slowly. The memory consumption did not jump between these trials and the network bandwidth increased slightly but never crossed 30 kbps in the steady-state.
These observations suggest that the experiments were CPU-limited rather than memory or bandwidth limited as the data publishing rate was increased. This is fitting with my earlier remark that graphics acceleration on the test system is mis-configured, which means that the display rendering was done by the CPUs rather than the onboard video card and hence the high cpu consumption.
I failed to repeat these experiments with Google Chrome due to this bug which I consequently filed on github. But given that V8 is a faster javascript engine, I would expect Chrome to perform better.
Code
The source code of the experiment is available in my fork of the hookbox project on github (I expect it will be pulled into Michael Carter’s main branch soon). It consists of fewer than 100 lines of Python, fewer than 30 lines of Javascript, and took about a couple of hours to get working satisfactorily. That’s not bad considering that it was an introductory play-date with Hookbox.
The equalizer widget consists of seven sliders from the jQuery-UI library, lined up vertically alongside each other. To update the sliders, a call back is attached to the hookbox subscription object’s “onPublish” event which looks like this:
// see index.html for the full code.
subscription.onPublish = function(frame) {
// adjust each slider from the data values in the frame's payload.
// the payload is expected to be an array of seven integers (one for
// each slider).
$("#eq > span").each(function (index) {
$(this).slider("value", frame.payload[index]);
});
};
The data production and publishing loop is also very simple. Seven random integer samples are produced, and sent via a HTTP POST to the Hookbox server, which then publishes it to all subscribers of that channel:
# see producer.py for the full code.
while True:
# generate seven random data points
# and publish them via the HTTP/REST api at 10 Hz.
# pop = range(0,100) (defined earlier)
# 'values' is a dictionary with some other fields required by hookbox (also defined earlier).
values["payload"] = random.sample(pop, 7)
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
# publish the samples!
resp = urllib2.urlopen(req)
time.sleep(0.1)
The common and most important thing between these two snippets is the “payload” object. In this example, it is an array of seven integers, ranging from 0 to 99 that is produced by the aptly named producer.py which also publishes it via the hookbox server and is received by the javascript running in the browser. The rest of the code in my example is quite self-explanatory and is a good way to learn Hookbox (and even Quixote).
Conclusion
While still in its infancy, Hookbox looks like a very promising project. From a developer’s perspective, it allows you to get something up and running very quickly. Its simplicity derives from the web hook api which also concerns me a bit. Using HTTP for inter-process communication, as in my example producer.py communicates with the hookbox server to publish data, doesn’t seem like the best choice for low-latency high-throughput applications. Perhaps Hookbox might introduce a web socket interface for inter-process communication so that the data can travel from the producer to the consumer using only one protocol? Overall, I’m quite impressed with Hookbox and really hope that it gains momentum. And lastly, don’t forget to read Michael Carter’s introduction to the project on cometdaily.com!
- Michael Foord: A plugin system for unittest(2)
One of the big problems with unittest, which I have been maintaining for well over a year now, is how hard it is to extend. For a long time I've been saying that my "big task" with unittest was to implement a plugin system. ... [838 words]
- Reinout van Rees: Software releases 6: skeletons for easy best practices
This is the last post in my software releases series (at
least, the last as I originally planned the series).
In the last 5 articles, you've seen a couple of places where there's some
irritating boilerplate. What's supposed to go into your setup.py? How
did you start off with a buildout.cfg again? Oh, don't forget the
CHANGES.txt and a basic README.txt. The solution for that is
something I normally call a skeleton. I mentioned skeletons earlier in a
Dutch python user group talk on practical project automation.
A skeleton is a basic project structure with a README, a couple of
directories, some python files to start off with and whatever else you want to
put in there. You give it some parameters (project name, website address,
whatever) and it'll fill in the blanks with those parameters.
Django has a manage.py startapp, but there's a generic python tool called
PasteScript. PasteScript's
documentation almost exclusively talks about running wsgi applications, but it
actually can create project skeletons for you. The best way to get started is
to look at ZopeSkel, which has a
large collection of skeletons. Download it and see what it can do.
There are two core advantages to using skeletons either for yourself or
within your community or within your company:
- Boilerplate reduction. Basic files get created and set up for you.
Laziness works to your advantage. "Just start the project from a skeleton"
gives you something reasonably solid and neat. The alternative is to just
start off with a python file and a sub directory and "remember" to add the readme
and so later.
- Best practice. Pour your knowledge into a skeleton. Figure out the way
you want to set up your projects once and reap the fruits many times over.
You're probably copy-pasting apache config files from one project to the
other: why not keep the latest and greatest config file in the skeleton?
For me, this is the number one advantage: you've got a place to collect
your project setup best practice. And having that place to put it means
that more best practice gets attracted!
Want to start your own skeleton? What I'd recommend is to start with a
ZopeSkel download and to look at
their code and how to set it all up. Then start your own. I worked for Zest
software and started "zestskel" there. I worked
for The Health Agency afterwards and
started "thaskel" there. Now I work at Nelen en Schuurmans so I've started "nensskel" here :-)
Some examples of what I get when I create a new django site with
nensskel (after giving it a project name):
- Basic setup.py with project name filled in. Long description is read
from the readme and changelog. Some common dependencies are pre-filled.
- buildout.cfg which sets up django, creates apache config files, contains
package-versioning best practice setup, contains some commonly used tools,
etc.
- Readme, changelog, todo file. Of course with the project name in there.
- Basic apache config file. In here there's also the configuration that's
needed for django's static files. And some caching setup. And the wsgi
configuration. And the setup needed for django-compressor.
- A directory with the actual django app (empty models.py, views.py
and so). A bit like how django's manage.py startapp does it, but now
with our own defaults.
- Our own defaults? Yes, for instance the boilerplate needed in
settings.py for our django-staticfiles css/js setup.
You definitively don't want to type that by hand.
- Pre-created PROJECTNAME/templates/PROJECTNAME,
PROJECTNAME/media/PROJECTNAME and PROJECTNAME/fixtures/ directories.
- Ready-made test setup just the way we like it.
So: make it easy to do the right thing. Let laziness work in your
favour. Start a skeleton today!
|
|