CustomLiveServerTestCase(LiveServerTestCase):
def setUp(self):
self.wd = webdriver.PhantomJS()
self.wd.set_window_size(1280, 720)
super(CustomLiveServerTestCase, self).setUp()
def tearDown(self):
super(CustomLiveServerTestCase, self).tearDown()
self.wd.close()
Tuesday, December 30, 2014
Python / Django / Selenium: Set viewport size (window size)
Python / Django / Selenium: "Webdriver Exception: Unable to startphantomjs with ghostdriver"
However, if that doesn't solve your issues you might have a failing test and not closing the webdriver down in your teardown method in your test if you have a custom test case:
CustomLiveServerTestCase(LiveServerTestCase): def setUp(self): self.wd = webdriver.PhantomJS() super(CustomLiveServerTestCase, self).setUp() def tearDown(self): super(CustomLiveServerTestCase, self).tearDown() self.wd.close()
Monday, December 29, 2014
Show Django-Debug-Toolbar when development IP addresses are dynamic (Vagrant, Landrush, etc.)
def show_toolbar(request):
return True
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TOOLBAR_CALLBACK': 'YourAppName.settings.development.show_toolbar',
}
Tuesday, December 16, 2014
Django-Stronghold with Django-Debug-Toolbar
STRONGHOLD_DEFAULTS = True
STRONGHOLD_PUBLIC_URLS = (
r'^/__debug__/.+$',
)
The STRONGHOLD_DEFAULTS tells Stronghold to include regex patterns for Static and Media file urls so your static assets will work too.
Wednesday, December 10, 2014
Correct connection settings for ElasticSearch / Django-Haystack on Bonsai.io
from urlparse import urlparse
es = urlparse(os.environ.get('BONSAI_URL'))
port = es.port or 80
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': es.scheme + '://' + es.hostname + ':' + str(port),
'INDEX_NAME': 'your_index_name',
},
}
if es.username:
HAYSTACK_CONNECTIONS['default']['KWARGS'] = {"http_auth": es.username + ':' + es.password}
Monday, September 1, 2014
Dell Sputnik Tip: Mouse / Cursor is broken or frozen after resuming from suspend or sleep
For some reason my third generation Dell Sputnik (aka Dell XPS13 with Ubuntu pre-installed) sometimes has a frozen or broken mouse / cursor after I suspend or sleep my laptop. You can easily get it working again (this is not a permanent fix) by switching to a different TTY and then back to the TTY that holds the x-server GUI.
- ctrl+alt+F6 to switch to TTY6 (this will give you a terminal)
- Do nothing in the terminal
- ctrl-alt+F7 to switch back to the TTY7 which is the Ubuntu x-server
- Voila... your mouse should be working again.
If anyone has a permanent fix, please let me know.
Thursday, August 21, 2014
Installing Cython - x86_64-linux-gnu-gcc: error: unrecognized command line option ‘-fstack-protector-strong’
I went around and around trying to get Cython install on my Ubuntu 14.04 LTS box. I kept getting:
x86_64-linux-gnu-gcc: error: unrecognized command line option ‘-fstack-protector-strong’
Turns out that the ‘-fstack-protector-strong’ option was not added to the GCC compiler until version 4.9. Upgraded my GCC to the latest available fixed the issue.
Tuesday, August 19, 2014
The City of Munich -- Switching Back to Windows from Linux?
Munich’s much vaunted migration to Linux could be about to unravel, sending the city back into the fee-driven bosom of Microsoft.
http://www.omgubuntu.co.uk/2014/08/munich-city-linux-switching-back-windows
The City of Munich, Germany has been a Linux user for over 10 years but it appears that city employees are clamoring to switch back to Windows.
The issue I see is that they built their own distribution - LiMux. It was originally based on Debian and then switched to Ubuntu. The last stable release of LiMux was in 2011 and is based on Ubuntu 10.04 LTS which was released in April 2010. That version of Ubuntu is seriously old in the tooth now -- even Microsoft releases new version of Windoze faster.
Seems to me that the City of Munich suffers from "Not invented here" syndrome and would be better off if they just switch to an vendor with commercial support like Ubuntu or Red Hat instead of trying to build and maintain their own distro.
Monday, August 11, 2014
Uninstall all Python packages via pip
This is for my future reference because it's really handy if you don't want to drop a virtualenv or doing some crazy work on a vagrant box. Even ignores any packages you installed from git or vcs sources with the -e flag
pip freeze | grep -v "^-e" | xargs pip uninstall -y
Friday, July 25, 2014
Logitech Unifying Receiver Pairing on Linux
This post is mostly for my future reference. Really simple to pair a new mouse with an existing receiver on Linux.
ltunify is a program resulting from the gathered knowledge on the Logitech HID++ protocol. It allows you to pair additional devices like keyboards and mice to your Unifying receiver, unpair existing devices and list information about connected devices. This section will show you how to install the ltunify program.
Besides a C compiler and a way to fetch sources (wget+tar or git), you will need Linux 3.2 or newer with the hid-logitech-dj module. On Debian and Ubuntu distributions, the required packages can be installed using:
sudo apt-get install git gccFetch the sources and install
ltunify
to$HOME/bin/
using the next commands:git clone https://git.lekensteyn.nl/ltunify.git
cd ltunify
make install-homeThe following steps will assume that
$HOME/bin
is available in your path. If not, run:export PATH="$HOME/bin:$PATH"If everything went well, you should be able to run
ltunify --help
to show the available options:Usage: ltunify [options] cmd [cmd options]
Logitech Unifying tool version dev
Copyright (C) 2013 Peter Wu <lekensteyn@gmail.com>
Generic options:
-d, --device path Bypass detection, specify custom hidraw device.
-D Print debugging information
-h, --help Show this help message
Commands:
list - show all paired devices
pair [timeout] - Try to pair within "timeout" seconds (1 to 255,
default 0 which is an alias for 30s)
unpair idx - Unpair device
info idx - Show more detailed information for a device
receiver-info - Show information about the receiver
In the above lines, "idx" refers to the device number shown in the
first column of the list command (between 1 and 6). Alternatively, you
can use the following names (case-insensitive):
Keyboard Mouse Numpad Presenter Trackball TouchpadThe below session shows you how to use a device index to unpair a mouse.
$ sudo ltunify list
Devices count: 1
Connected devices:
idx=1 Mouse M525
$ sudo ltunify unpair 1
Device 0x01 Mouse successfully unpaired
$ sudo ltunify list
Devices count: 0
Connected devices:
$ sudo ltunify pair
Please turn your wireless device off and on to start pairing.
Found new device, id=0x01 Mouse
$ sudo ltunify list
Devices count: 1
Connected devices:
idx=1 Mouse M525It is also possible to select a device by device type (case-insensitive). When multiple devices of the same type are available, the first one will be selected.
$ sudo ltunify unpair mouse
Device 0x01 Mouse successfully unpaired
Wednesday, April 30, 2014
PyCon 2015 will...
PyCon 2015 will be held in Montreal again next year from April 8th - 16th, 2015. We hope to see you there!
Tutorials: April 8th - 9th
Conference: April 10th - 12th
Sprints: April 13th - 16th
Blogging this because it's hard to find the dates for PyCon 2015
Friday, February 14, 2014
Car2Go Minneapolis Promo Code - Expires 3/16/14
Didn't get a free lifetime membership to Car2Go Minneapolis last Fall? This is the last "cheap" promo for Car2Go and lifetime memberships. My wife and I used Car2Go in both Portland and Seattle during our recent vacation. We never had to rent a car!
The PFAR1030 promo code gives you a discounted $10 car2go registration fee (instead of the normal $35) AND 30 free minutes of car2go drive time. My promo code expires on 3/16.
Wednesday, February 12, 2014
How to fix a R1Soft NO_PUBKEY error during apt-get update
During a recent apt-get update of one of our systems, we encountered an error with the R1Soft repository for CDP:
W: GPG error: http://repo.r1soft.com stable Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 1BF3530AA40384ED
It appears that R1Soft started using a new key which they publish. In order to get this repository working again, you must update to use the new key. Use the following commands to import the new key:
wget http://repo.r1soft.com/r1soft.asc
apt-key add r1soft.asc
apt-get update
The key (pun intendned) of this post is to remind myself of the URL of the public key block.
Wednesday, February 5, 2014
Reaction to Two Scoops of Django 1.6 FAQ - No Digital Edition?!?!
Considering that we publicly offered a free electronic copy to those who requested it, seeing piracy of the electronic editions from the first day of sales has been disheartening. As indie authors, it hurts to see this happening.
It is awful to think of the piracy that occurred, however this just punishes the people that want an electronic format and are honest in the first place. If somebody wants to pirate a copy, they will do it whether an electronic edition is available or not.
I can totally understand the argument on multiple ebook formats being an issue due to formatting. The solution is simple -- only offer a PDF that is a rendering of the physical book.
It is legal (* from what I can tell) to scan a book that was legally acquired for personal use. This falls under the fair usage laws (similar ripping MP3s of CDs you own). I've scanned books at home into PDF and then shredded them (I have fairly limited space for tech books at home). The results are only fair and are better if I slice off the binding.
It is more than likely that with this edition of Two Scoops of Django, I will buy via Amazon and ship directly to 1dollarscan.com which will scan ($1 per 100 pages) a book into a PDF and then after two weeks they shred the book (they do not return books). Talk about a waste of natural resources -- paper manufacturing, printing, ship to a warehouse and ship to a scanning company, etc.
Maybe an alternative is to sell PDFs but password protect them which makes it easier to figure the origin if a pirated copy is discovered and watermark the header on the top each page with the name, email and phone number of the original purchaser.
Physical books won't stop the pirates. Yes, it does make it harder for them (marginally), however this just punishes the majority of honest people that used the electronic format in a responsible and legal manner for the few (relatively) that decided to pirate a copy. So the only thing that has changed is increased the cost of my book by about $4 (the cost to scan at 1dollarscan.com) and I can no longer search it (unless I pay extra for the OCR option).
Edit on Feb. 7th, 2014 due to feedback -- I want to clarify some points:
This post is a reaction to not publishing a digital edition and points to how I'm probably solving the "no digital edition" issue for myself. I will still purchase a legal physical copy of the book. I still want Danny and Audrey to take my money because I want the content. I just expressed my wishes to get an official digital edition. Using a scanning service is a lazy hack, however Fair Use hack (as long as I don't distribute it). Also, I do not support pirating media and therefore this post isn't a "how to pirate" manual -- merely a legitimate fair use solution to having a digital version for personal use.
Other than this post... I have not participated in any public discussions (other than the single automated tweet when this post was publishing). I've now been counted and blamed as one of the trolls that "caused" future editions of Two Scoops of Django to not happen. This is a rather unfair assessment.
The point is pirates will still pirate a copy of this book because they want to. If anything, this is a testament to quality of the content that Danny and Audrey produce. I must admit it is sad that the availability of pirated copies of Two Scoops is a compliment to the authors. It does reinforce that quality content is in demand and there are people that un-willing or just plain too cheap to buy a legitimate copy.
The real losers here are the legitimate users that want to buy a legal copy of a book. The only thing done by not making a digital edition available is that making the first pirated copy is just slighly harder to make. I would guess about 45 minutes at a flatbed scanner is about it. Not having a digital edition won't stop piracy at all and therefore I don't except that as a legitimate reason to not do a digital edition. On to a real reason... time!
Two Scoops 1.5 edition was released with three digital edition types (mobi, epub and pdf). The PDF looks like the print copy and I never used the epub or mobi editions. Considering the target devices for epub and mobi, I suspect it took Danny and Audrey a LOT of time to probably do it right (which they indicated in their FAQ). This was an ambitious and lofty goal to release so many formats. Kudos to them for doing it however I'm sure it contributed to the reason to not release a digital edition for this version. So it understandable that time is a factor for the authors (rightfully so). The solution is export a PDF version of the book and skip the tedious hand grooming of epub and mobi formats.