When querying objects in django the simplest way is to use the filter() query.
If we have a set of systems for example and we want to filter out those that have a SPARC architecture we could do:
And if we wanted to narrow that down to only sparc machines that use NIS for name resolution we could do:
But that is narrowing down the selection. It’s an AND. What were asking for is systems that are a SPARC _AND_ use NIS. And although we can use exclude() to reject some results it’s still and AND operation. What about an OR query?
What if we wanted to select systems that had either a T5 or a T7 processor? Then we need Q queries.
Q queries take the same form of argument as filter() & exclude() etc. but can be combined using OR operators. Here’s the Q query for our model that looks at the cpu_implementation for T5 or T7:
Q(sysconfig__icontains="T7") | Q(sysconfig__icontains="t5")
To build our query we just use this Q expression in a filter:
from django.db.models import Q
Windows 10 comes with a very handy Windows Subsystem for Linux. This lets you set up a linux environment (Ubuntu/SuSE/Redhat etc.) and run linux commands, use linux utilities, and interact with the windows filesystem.
What it doesn’t let you do however is run graphical applications.
Continue reading Running Graphical Linux/X programs on Windows 10
A while ago I was writing a tool in python to communicate with a sensor on an Arduino. The idea was to have a class for the Arduino that would hold the connection and handle the reading and writing to the serial port. However that way I needed to have the object maintain the connection and the open COM port (this was on windows), but this meant that I could not have multiple objects. Why? Because you can only have one connection to a COM port. The solution – use a Singleton design pattern.
Continue reading Python: Creating a singleton (to control an Arduino)
When I was in school, I remember being told that it was possible to tune an FM radio do a free frequency low in the band and during a meteor storm you could ‘hear’ when meteors struck the atmosphere as the FM signal from distant radio stations would be reflected back down from the ionised meteor trail. This may have been possible as back then there were plenty of high powered FM stations from Eastern Europe using a lower portion of the spectrum and receivers often went below the 88.5 that is the limit on the dial now. But I never heard anything. Over the years as my interest in meteors and radio was peeked I looked into it again, but the number of stations to use was dwindling and there were few artificial sources that could produce an audible ping. Continue reading Detecting Meteors from radio reflections
I’ve forgotten this several times now so it’s time I wrote a short post to help me remember in future! In Solaris 11 we use the Image Packaging System to maintain the software on the system. This is written in python and uses libcurl and for non zoned systems setting the http_proxy is sufficient to allow the system to communicate with the repo. Continue reading Updating Solaris 11 zones behind a proxy
… or Overcoming Your Fear of Repositories as the OTN Garage puts it! My colleagues Glynn Foster, Pete Dennis and I have put three articles on Oracle Tech Network that we hope will help you keep your Solaris 11 systems up to date. Here’s why these documents may be of interest to you administering Soalris 11.
Continue reading Helping you manage you Solaris 11 support updates
Works for me:
ffmpeg -i INPUT -acodec aac -ac 2 -ab 160k -vcodec libx264 -vpre iPod640 -f mp4 -strict experimental -threads 0 OUTPUT
For other recipies, well, starting points anyway, see https://develop.participatoryculture.org/index.php/ConversionMatrix
I’m clearing out the attic and have some old computer magazines that some of you might be interested in. Free to a good home if you can collect from me, otherwise they go to recycling.
The first batch contains titles like Personal Computer News and Your Computer from around 1981-1983. The second batch are mainly Amiga Shopper (and the odd CU Amiga and Amiga Format) from around 1994.
UPDATE: All gone! Continue reading Old computer magazines free to a good home
When creating python unit tests you need to create a method in a unittest class. The problem however is when you don’t know until the code is running what these tests will be. In my particular case I need to run a series of tests against a number of Solaris packages. But I won’t know what the packages will be in advance. Continue reading Python : generating unittests on the fly
The simple way to search for a string in a list is just to use ‘if string in list’. eg:
Continue reading Python: Searching for a string within a list – List comprehension
>>> list = ['a cat', 'a dog', 'a yacht']
>>> string = 'a cat'
>>>if string in list:
... print 'found a cat!'
... found a cat!