<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-326546128991905962</id><updated>2011-09-06T05:52:15.624-07:00</updated><category term='mercurial hg clone commit pull push aide mémoire'/><category term='hack'/><category term='interpreter'/><category term='bpython'/><category term='google transliteration chinese input method'/><category term='phishing'/><category term='child soldier'/><category term='social engineering'/><category term='omar khadr'/><category term='shell'/><category term='government'/><category term='canada'/><category term='django'/><category term='hackers'/><category term='data theft'/><title type='text'>Blog On Stuff</title><subtitle type='html'>Technology, linux, politics, whatever</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://newblogonstuff.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://newblogonstuff.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>B.</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-326546128991905962.post-8485359819831788634</id><published>2011-02-18T05:36:00.001-08:00</published><updated>2011-02-18T06:52:46.426-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='canada'/><category scheme='http://www.blogger.com/atom/ns#' term='social engineering'/><category scheme='http://www.blogger.com/atom/ns#' term='phishing'/><category scheme='http://www.blogger.com/atom/ns#' term='government'/><category scheme='http://www.blogger.com/atom/ns#' term='data theft'/><category scheme='http://www.blogger.com/atom/ns#' term='hackers'/><category scheme='http://www.blogger.com/atom/ns#' term='hack'/><title type='text'>Dear Canadian Government - Learn Computers.</title><content type='html'>The recent cyber-attacks by foreign hackers on the Canadian Government network infrastructures shouldn't have happened and were easily preventable. I believe it was exactly what our government needed to start thinking about implementing modern system security strategies to secure data.&lt;br /&gt;&lt;br /&gt;It appears that &lt;a href="http://www.globalsaskatoon.com/Going+phishing/4304355/story.html"&gt;the hackers used "spear-phishing" tactics&lt;/a&gt; targeting specific government officials, fooling them into giving away sensitive information, and having them open documents infected with viruses.&lt;br /&gt;&lt;br /&gt;In a few sentences, spear-phishing works a bit like this:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Hacker Zhang sends an email to Industry Canada clerk Bob.&lt;/li&gt;&lt;li&gt;The email appears to come from Bob's colleague Rita working at the "Gov of Canada's Central File Repository" administration. It warns Bob that his password has been compromised and needs to be reset. It provides him with a link.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Bob clicks on the link and resets his password.&lt;/li&gt;&lt;li&gt;The link is actually pointing to a website hosted in Indonesia that "appears" to be an official government website, but actually isn't.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Hacker Zhang now has the password, and does what he wants with it.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;Of course it's probably a lot more complicated than this, you need to obtain a lot more information in order to even know things like.. how does the government store sensitive data? Is it on a separate network? How to I access this network.. etc. etc. Of course with a bit of &lt;a href="http://en.wikipedia.org/wiki/Social_engineering_%28security%29"&gt;social-engineering&lt;/a&gt; in a bureaucracy that is clueless to software security, all this easily done.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;How could this have been prevented?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Well let's first start by identifying the security holes that allowed this to happened:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Government officials exchange emails with no encryption, allowing hackers to send emails "appearing" to come from legitimate contacts.&lt;/li&gt;&lt;li&gt;Government email system has bad virus cleansing strategies.&lt;/li&gt;&lt;li&gt;Government officials with access to sensitive system credentials have little IT training.&lt;/li&gt;&lt;/ol&gt;&lt;span style="font-weight: bold;"&gt;Unencrypted email problem, and email address spoofing:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Every government agency should encrypt emails with with digital signatures to ensure that the sender is actually who he / she claims to be, and so that no middle-man can read sensitive data. See this for more information: &lt;a href="http://www.openpgp.org/"&gt;http://www.openpgp.org/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This is not something new.. this could have been implemented years ago.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Better Virus Cleansing Strategies&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;Allow only the exchange of safe file formats by email. No .doc, .pdf, .exe, .zip etc... The email servers should filter all files that are potentially dangerous, and government agencies should use "safe" file formats such as restructured text.. txt... etc. It won't be as pretty as docs / pdfs, but it will prevent getting infected because of a bad file attached to a spoofed email.&lt;br /&gt;&lt;br /&gt;Also, perhaps e-mail should simply not be used as a file-exchange medium. Emailing's initial purpose was to exchange messages, not mp3s, videos, pdfs... Other technologies are much better at dealing with file exchange.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;IT Training:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is perhaps the most important point of all! Regardless of how high-ranking a government official may be, he / she can the the victim of phishing attempts / impersonation attempts. Classes on Information Security in IT should be mandatory for &lt;span style="font-style: italic;"&gt;ALL&lt;/span&gt; government officials that have access, or &lt;span style="font-style: italic;"&gt;CAN&lt;/span&gt; have access (through a colleague) to sensitive credentials allowing them to access sensitive data.&lt;br /&gt;&lt;br /&gt;There are simple things that most people should know regarding network security.&lt;br /&gt;&lt;br /&gt;Few examples:&lt;br /&gt;-How to store passwords (or &lt;span style="font-style: italic;"&gt;should&lt;/span&gt; you store passwords?)&lt;br /&gt;-What's phishing?&lt;br /&gt;-What's social engineering?&lt;br /&gt;-Is email a safe medium for communication?&lt;br /&gt;-How to send files?&lt;br /&gt;-What can I install on my computer?&lt;br /&gt;-.. and so on.&lt;br /&gt;&lt;br /&gt;Why wasn't the government ready to prevent such simple cyber-attacks? How can the Harper government have billions of dollars to spend on brand new planes, while its network security infrastructure is failing in every way and needs major restructuring?&lt;br /&gt;&lt;br /&gt;Why do I know this, yet millions of dollars in consultation fees spent every year couldn't prepare them for such an attack?&lt;br /&gt;&lt;br /&gt;How are we now supposed to trust our own government for keeping our data safe when its network security standards (that are actually in place) are practically non-existent?&lt;br /&gt;&lt;br /&gt;Just my two cents.&lt;br /&gt;&lt;br /&gt;-&lt;br /&gt;Benoit&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/326546128991905962-8485359819831788634?l=newblogonstuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://newblogonstuff.blogspot.com/feeds/8485359819831788634/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=326546128991905962&amp;postID=8485359819831788634' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default/8485359819831788634'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default/8485359819831788634'/><link rel='alternate' type='text/html' href='http://newblogonstuff.blogspot.com/2011/02/dear-canadian-government-learn.html' title='Dear Canadian Government - Learn Computers.'/><author><name>B.</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-326546128991905962.post-3200613357365181579</id><published>2010-12-09T15:47:00.000-08:00</published><updated>2010-12-09T15:57:57.305-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='google transliteration chinese input method'/><title type='text'>Google Transliteration - Quite impressed.</title><content type='html'>I just checked out &lt;a href="http://www.google.com/transliterate/"&gt;Google Transliteration&lt;/a&gt; currently in Google Labs.&lt;br /&gt;&lt;br /&gt;It's basically a *any language* phonetics writer, which when using Chinese, can be used a an excellent Input method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_B21gUaId8FY/TQFs2XaN7OI/AAAAAAAAAlE/Ch30jUywuf0/s1600/googletrans.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 260px;" src="http://2.bp.blogspot.com/_B21gUaId8FY/TQFs2XaN7OI/AAAAAAAAAlE/Ch30jUywuf0/s400/googletrans.png" alt="" id="BLOGGER_PHOTO_ID_5548835897149877474" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/326546128991905962-3200613357365181579?l=newblogonstuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://newblogonstuff.blogspot.com/feeds/3200613357365181579/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=326546128991905962&amp;postID=3200613357365181579' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default/3200613357365181579'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default/3200613357365181579'/><link rel='alternate' type='text/html' href='http://newblogonstuff.blogspot.com/2010/12/google-transliteration-quite-impressed.html' title='Google Transliteration - Quite impressed.'/><author><name>B.</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_B21gUaId8FY/TQFs2XaN7OI/AAAAAAAAAlE/Ch30jUywuf0/s72-c/googletrans.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-326546128991905962.post-7865860344564392067</id><published>2010-12-06T09:45:00.000-08:00</published><updated>2010-12-06T09:57:57.900-08:00</updated><title type='text'>Request's IP address using django, Apache proxying through Nginx.</title><content type='html'>So I spent about 2 hours trying to figure out how to get the real IP address from the request objects when proxying through Nginx using Apache. I didn't find much documentation online about this topic so I figured that I should share.&lt;br /&gt;&lt;br /&gt;Problem:&lt;br /&gt;So you do something like this:&lt;br /&gt;&lt;pre&gt;Class MyModel(models.Model):&lt;br /&gt; ...&lt;br /&gt; def populate_meta(self, meta_data):&lt;br /&gt;     try:&lt;br /&gt;         if 'REMOTE_ADDR' in meta_data:&lt;br /&gt;             self.ip = meta_data['REMOTE_ADDR']&lt;br /&gt;     except KeyError:&lt;br /&gt;             pass&lt;/pre&gt;&lt;br /&gt;And you ./manage.py runserver and all works well, your IP addresses are recorded fine.&lt;br /&gt;&lt;br /&gt;Then you set-up a production server with Nginx and Apache with a configuration that looks like this:&lt;br /&gt;&lt;pre&gt;server {&lt;br /&gt;  listen   80;&lt;br /&gt;  server_name example.com;&lt;br /&gt;  location / {&lt;br /&gt;           proxy_pass      http://127.0.0.1:81;&lt;br /&gt;           proxy_redirect  off;&lt;br /&gt;           proxy_set_header   Host             $host;&lt;br /&gt;           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;&lt;br /&gt;           proxy_set_header    X-Magic-Header "secret";&lt;br /&gt;           client_max_body_size       10m;&lt;br /&gt;               proxy_set_header   X-Real-IP $remote_addr;&lt;br /&gt;  }&lt;br /&gt;  location /static {&lt;br /&gt;       alias /srv/web/landing/landing/static/;&lt;br /&gt;  }&lt;br /&gt;  location /media {&lt;br /&gt;      alias /srv/web/landing/env/lib/python2.6/site-packages/django/contrib/admin/media/;&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;And then suddenly all the IP addresses are recorded as 127.0.0.1!&lt;br /&gt;&lt;br /&gt;How to fix it:&lt;br /&gt;Change your python code to the following:&lt;br /&gt;&lt;pre&gt;Class MyModel(models.Model):&lt;br /&gt; ...&lt;br /&gt; def populate_meta(self, meta_data):&lt;br /&gt;     try:&lt;br /&gt;         if 'HTTP_X_REAL_IP' in meta_data:&lt;br /&gt;             self.ip = meta_data['HTTP_X_REAL_IP']&lt;br /&gt;     except KeyError:&lt;br /&gt;             pass&lt;/pre&gt;&lt;br /&gt;That's it! Hope it helps.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/326546128991905962-7865860344564392067?l=newblogonstuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://newblogonstuff.blogspot.com/feeds/7865860344564392067/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=326546128991905962&amp;postID=7865860344564392067' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default/7865860344564392067'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default/7865860344564392067'/><link rel='alternate' type='text/html' href='http://newblogonstuff.blogspot.com/2010/12/requests-ip-address-using-django-apache.html' title='Request&apos;s IP address using django, Apache proxying through Nginx.'/><author><name>B.</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-326546128991905962.post-6625469689931354585</id><published>2010-12-02T07:16:00.000-08:00</published><updated>2010-12-02T07:21:50.834-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mercurial hg clone commit pull push aide mémoire'/><title type='text'>Petit aide-mémoire mercurial</title><content type='html'>Voici un petit aide mémoire pour mercurial, pour ceux et celles qui en ont besoin.&lt;b&gt; &lt;/b&gt;&lt;span style="font-style: italic;"&gt;Note, cet aide-mémoire décrit un cas ou un repository est sur un serveur, et l'autre en local. Les exemples s'appliquent quand même dans le cas de deux repository locaux. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;hg clone ORIGINE [DESTINATION&lt;/b&gt;]&lt;br /&gt;*Pour créer une copie locale (un "repository" local) du projet ORIGINE&lt;br /&gt;&lt;br /&gt;&lt;b&gt;hg commit [NOMS DE FICHIERS] [-m "Description du commit"]&lt;/b&gt;&lt;br /&gt;*Inscrire les changements (le "changeset") dans le repository local&lt;br /&gt;&lt;br /&gt;&lt;b&gt;hg add [NOMS DE FICHIERS]&lt;/b&gt;&lt;br /&gt;*Ajouter un nouveau fichier dans le changeset actuel&lt;br /&gt;&lt;br /&gt;&lt;b&gt;hg rm [NOMS DE FICHIERS]&lt;/b&gt;&lt;br /&gt;*Enlever un fichier dans le changeset actuel&lt;br /&gt;&lt;br /&gt;&lt;b&gt;hg log&lt;/b&gt;&lt;br /&gt;*Voir la liste des commits&lt;br /&gt;&lt;br /&gt;&lt;b&gt;hg status&lt;/b&gt;&lt;br /&gt;*Voir l'etat du repository local&lt;br /&gt;**A = Fichier ajouté dans le changeset&lt;br /&gt;**M = Fichier modifié dans le changeset&lt;br /&gt;**R = Fichier enlevé dans le changeset.&lt;br /&gt;**? = Fichier pas dans le changeset&lt;br /&gt;**! = Fichier manquant dans le changeset actuel.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;hg pull&lt;/b&gt;&lt;br /&gt;*Mettre à jour le repository local, avec les changements&lt;br /&gt;du repository sur le serveur.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;hg push&lt;/b&gt;&lt;br /&gt;*Mettre à jour le repository du serveur, avec les changements&lt;br /&gt;du repository local.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;hg update&lt;/b&gt;&lt;br /&gt;*Après avoir fait un hg pull, il faut faire un update pour&lt;br /&gt;mettre à jour les fichiers avec les changements récupérés&lt;br /&gt;sur le serveur.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;hg merge&lt;/b&gt;&lt;br /&gt;*Pour mettre à jour l'historique des commits avec une&lt;br /&gt;historique différente.&lt;br /&gt;Exemple:&lt;br /&gt;&lt;i&gt;*Anna:&lt;/i&gt;&lt;br /&gt;-Fait des changements à ses fichiers&lt;br /&gt;-hg commit -m "Mes changements!!"&lt;br /&gt;&lt;i&gt;*Ben:&lt;/i&gt;&lt;br /&gt;-Fait des changements à ses fichiers&lt;br /&gt;-hg commit -m "Changements de mehdi"&lt;br /&gt;-hg push **OK!!&lt;br /&gt;&lt;i&gt;*Anna:&lt;/i&gt;&lt;br /&gt;-hg push **ERREUR!!&lt;br /&gt;-hg pull&lt;br /&gt;-hg merge&lt;br /&gt;-hg commit -m "merged avec changements de mehdi"&lt;br /&gt;-hg push **OK!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/326546128991905962-6625469689931354585?l=newblogonstuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://newblogonstuff.blogspot.com/feeds/6625469689931354585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=326546128991905962&amp;postID=6625469689931354585' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default/6625469689931354585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default/6625469689931354585'/><link rel='alternate' type='text/html' href='http://newblogonstuff.blogspot.com/2010/12/petit-aide-memoire-mercurial.html' title='Petit aide-mémoire mercurial'/><author><name>B.</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-326546128991905962.post-4212390792365216217</id><published>2010-08-11T09:37:00.000-07:00</published><updated>2010-08-11T10:17:13.068-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='omar khadr'/><category scheme='http://www.blogger.com/atom/ns#' term='child soldier'/><title type='text'>What if Omar Khadr was a white, middle-class American?</title><content type='html'>Here's a scenario:&lt;br /&gt;&lt;br /&gt;James Jones, a 15 y/o, middle-class white American, leaves home by himself to fight coalition forces in Afghanistan, convinced by some radical ideas he's picked in during his teenage years.&lt;br /&gt;&lt;br /&gt;Next thing you know, James Jones is taken by Canadian forces, brought to a military prison, and accused of murdering a Canadian soldier on foreign soil.&lt;br /&gt;&lt;br /&gt;Imagine his pinkish face, on TV in a court room, answering to the crimes he's been charged with.&lt;br /&gt;Imagine him &lt;a href="http://articles.latimes.com/2010/apr/28/nation/la-na-guantanamo-prisoner-20100428"&gt;holding on to a Mickey Mouse book&lt;/a&gt;, trying to sleep at night.&lt;br /&gt;Imagine his fear as the child remains imprisoned for 7 years with murderers.&lt;br /&gt;&lt;br /&gt;Would you deny his right to defend himself in a fair, internationally recognized justice system?&lt;br /&gt;&lt;br /&gt;Would refuse that the child should be protected by international agreements such as the &lt;a href="http://en.wikipedia.org/wiki/Paris_Principles"&gt;Paris Agreement&lt;/a&gt;, adopted by the United Nations in order to safeguard the rights and welfare of children during wartime?&lt;br /&gt;&lt;blockquote&gt;&lt;span style="font-weight: bold;"&gt;Treatment of children accused of crimes under international law&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;3.6 Children who are accused of crimes under international law allegedly committed while they were associated with armed forces or armed groups should be considered primarily as victims of offences against international law; not only as perpetrators. They must be treated in accordance with international law in a framework of restorative justice and social rehabilitation, consistent with international law which offers children special protection through numerous agreements and principles.&lt;br /&gt;&lt;br /&gt;3.7 Wherever possible, alternatives to judicial proceedings must be sought, in line with the Convention on the Rights of the Child and other international standards for juvenile justice.&lt;br /&gt;&lt;br /&gt;3.8 Where truth-seeking and reconciliation mechanisms are established, children’s involvement should be promoted and supported and their rights protected throughout the process. Their participation must be voluntary and by informed consent by both the child and her or his parent or guardian where appropriate and possible. Special procedures should be permitted to minimize greater susceptibility to distress.&lt;/blockquote&gt;Why are we treating prisoner &lt;a href="http://www.humanrightsfirst.org/us_law/detainees/cases/khadr.aspx"&gt;Omar Khadr&lt;/a&gt; as a war criminal? Why has he been imprisoned for 7 years when instead he should have been in school, studying, playing, loving?&lt;br /&gt;&lt;br /&gt;Is it because he is brown? Because he's a muslim? Are we really living in a world where society accepts to jail children and deny them the rights we have promised to give them?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/326546128991905962-4212390792365216217?l=newblogonstuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://newblogonstuff.blogspot.com/feeds/4212390792365216217/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=326546128991905962&amp;postID=4212390792365216217' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default/4212390792365216217'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default/4212390792365216217'/><link rel='alternate' type='text/html' href='http://newblogonstuff.blogspot.com/2010/08/what-if-omar-khadr-was-white-middle.html' title='What if Omar Khadr was a white, middle-class American?'/><author><name>B.</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-326546128991905962.post-6977877952396731906</id><published>2010-07-21T09:23:00.000-07:00</published><updated>2010-07-21T09:54:44.133-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='django'/><category scheme='http://www.blogger.com/atom/ns#' term='bpython'/><category scheme='http://www.blogger.com/atom/ns#' term='interpreter'/><category scheme='http://www.blogger.com/atom/ns#' term='shell'/><title type='text'>Bpython + Django</title><content type='html'>Hi,&lt;br /&gt;&lt;br /&gt;If you'd like to use the &lt;a href="http://bpython-interpreter.org/"&gt;bpython&lt;/a&gt; interpreter with django, and auto-load your models, here's how you can do it.&lt;br /&gt;&lt;br /&gt;install bpython using pip or whatever, make sure it's  in your path&lt;br /&gt;example:&lt;br /&gt;    pip install bpython&lt;br /&gt;&lt;br /&gt;create a file in (django location)/core/management/ &lt;div id=":xx" class="ii gt"&gt;&lt;wbr&gt;commands/ (I use virtualenv so for me it's in (env)/lib/python2.6/site-packages/django/core/management/  )&lt;br /&gt;&lt;br /&gt;Name the file bpshell.py containing the code below.&lt;br /&gt;&lt;br /&gt;and now you can run ./manage.py bpshell !!!&lt;br /&gt;&lt;br /&gt;&lt;pre style="overflow: scroll; border: 2px solid #aaaaaa;"&gt;&lt;br /&gt;# Copy this file to (django location)/core/management/commands/bpshell.py&lt;br /&gt;# make sure that bpython is somewhere in your path (virtual env?)&lt;br /&gt;# run using ./manage.py bpshell&lt;br /&gt;&lt;br /&gt;import os&lt;br /&gt;from django.core.management.base import NoArgsCommand&lt;br /&gt;from django.db.models.loading import get_models, get_apps&lt;br /&gt;from optparse import make_option&lt;br /&gt;&lt;br /&gt;class Command(NoArgsCommand):&lt;br /&gt;    option_list = NoArgsCommand.option_list + (&lt;br /&gt;        make_option('--plain', action='store_true', dest='plain',&lt;br /&gt;            help='Tells Django to use plain Python, not bpython.'),&lt;br /&gt;    )&lt;br /&gt;    help = "Runs a Python interactive interpreter. Tries to use bpython, if it's available."&lt;br /&gt;&lt;br /&gt;    requires_model_validation = False&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    def handle_noargs(self, **options):&lt;br /&gt;        # XXX: (Temporary) workaround for ticket #1796: force early loading of all&lt;br /&gt;        # models from installed apps.&lt;br /&gt;        from django.db.models.loading import get_models&lt;br /&gt;        loaded_models = get_models()&lt;br /&gt;&lt;br /&gt;        use_plain = options.get('plain', False)&lt;br /&gt;&lt;br /&gt;        imported_objects = {}&lt;br /&gt;&lt;br /&gt;        for app_mod in get_apps():&lt;br /&gt;            app_models = get_models(app_mod)&lt;br /&gt;            if not app_models:&lt;br /&gt;                continue&lt;br /&gt;            model_labels = ", ".join([model.__name__ for model in app_models])&lt;br /&gt;            print self.style.SQL_COLTYPE("From '%s' autoload: %s" % (app_mod.__name__.split('.')[-2], model_labels))&lt;br /&gt;            for model in app_models:&lt;br /&gt;                try:&lt;br /&gt;                    imported_objects[model.__name__] = getattr(__import__(app_mod.__name__, {}, {}, model.__name__), model.__name__)&lt;br /&gt;                except AttributeError, e:&lt;br /&gt;                    print self.style.ERROR_OUTPUT("Failed to import '%s' from '%s' reason: %s" % (model.__name__, app_mod.__name__.split('.')[-2], str(e)))&lt;br /&gt;                    continue&lt;br /&gt;&lt;br /&gt;        try:&lt;br /&gt;            if use_plain:&lt;br /&gt;                raise ImportError&lt;br /&gt;            from bpython.cli import main&lt;br /&gt;            locals_=imported_objects&lt;br /&gt;            args=['-i', '-q']&lt;br /&gt;            banner=None&lt;br /&gt;            main(args, locals_, banner)            &lt;br /&gt;&lt;br /&gt;        except ImportError:&lt;br /&gt;            import code&lt;br /&gt;            imported_objects = {}&lt;br /&gt;            try: # Try activating rlcompleter, because it's handy.&lt;br /&gt;                import readline&lt;br /&gt;            except ImportError:&lt;br /&gt;                pass&lt;br /&gt;            else:&lt;br /&gt;                # We don't have to wrap the following import in a 'try', because&lt;br /&gt;                # we already know 'readline' was imported successfully.&lt;br /&gt;                import rlcompleter&lt;br /&gt;                readline.set_completer(rlcompleter.Completer(imported_objects).complete)&lt;br /&gt;                readline.parse_and_bind("tab:complete")&lt;br /&gt;&lt;br /&gt;            # We want to honor both $PYTHONSTARTUP and .pythonrc.py, so follow system&lt;br /&gt;            # conventions and get $PYTHONSTARTUP first then import user.&lt;br /&gt;            if not use_plain: &lt;br /&gt;                pythonrc = os.environ.get("PYTHONSTARTUP") &lt;br /&gt;                if pythonrc and os.path.isfile(pythonrc): &lt;br /&gt;                    try: &lt;br /&gt;                        execfile(pythonrc) &lt;br /&gt;                    except NameError: &lt;br /&gt;                        pass&lt;br /&gt;                # This will import .pythonrc.py as a side-effect&lt;br /&gt;                import user&lt;br /&gt;            code.interact(local=imported_objects)&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/326546128991905962-6977877952396731906?l=newblogonstuff.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://newblogonstuff.blogspot.com/feeds/6977877952396731906/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=326546128991905962&amp;postID=6977877952396731906' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default/6977877952396731906'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/326546128991905962/posts/default/6977877952396731906'/><link rel='alternate' type='text/html' href='http://newblogonstuff.blogspot.com/2010/07/bpython-django.html' title='Bpython + Django'/><author><name>B.</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
