Recently I was tracking down a bug in some code. The source of the problem was an 'if' block that had a elif this, elif that, but it didn't have an 'else' clause. It should have had an else clause. It was going through a loop from a database and checking for certain conditions. It would set a variable based on that if block, since there was no else block, the variable was not getting updated in this iteration of the loop, causing a duplicate of the code. If there had been an 'else: assert False' it wouldn't have been a problem, because we could have caught it. After fixing the code here, I started to wonder about any other potential bugs like this were lurking elsewhere. It would be cool if I could analyse the code and see if there were any more if blocks without an else condition.
pylint is a programme that will scan your python source code for coding standards (variable names, unused imports, line length, etc). It's also extensible, so you can write your own plugin for it. this looked like the perfect tool to use. it turned out to be very straight forward to write a plugin that will scan for this kind of thing.
The code is stored in a git repository here. Anonymouse users can push to the 'mob' branch on this, so I welcome all submissions. It's quite easy to use, just call this command from the same directory as the missing_else.py file from the above repository. It'll generate warning messages for if blocks that have elif blocks but have no else blocks.
There are 2 options with this file. By default it will warn you if you have a if that has an elif and doesn't have an else clause. If you add the option "--warn_if_no_else=y" then it'll also warn you if you have a bare if clause that has no else clause. I don't enable this by default.
Many programmes produce logs, e.g. apache produces log files of webpages that people visit. One common feature of these log files is that each line has the time and date that the event happened at. This is very convienent because you can easily search for things that happened on a certain date or at a certain time.
Sometimes you might want to run a command that will print some output, and it might take a while. In cases like this it would be helpful to have a timestamp on each line. This is a simple little snippet you can put onto the end of a big command that will print timestamps.
The magic here is the 'read' built in. It will read the whole line (and store it in the shell variable line). However if there is no output yet, it will just sit there and the contents of the loop (which prints out the timestamp) will not be run. Since the time is only evaluated inside the loop, it will not update the time until it has a line. i.e. it will calculate a timestamp when a line is output by the first programme.
This is all you need to add to your command to get some nice output
$ command | while read line ; do NOW=$(date -Iseconds) ; echo -e "${NOW}\t${line}" ; done
Meteor is the 3rd largest mobile phone provider in Ireland. They have a 3G service. I recently signed up with them so I could get their 3G internet service.
I bought an Android Dev G1 Phone. It's not locked to a certain network, so I can freely use any SIM card I want on it. However since I didn't get the phone from Meteor, I have to configure all the settings myself, including the APN to connect to the internet.
To set it up you need to enter these values. At the home screen, press menu, then 'Settings', then 'Wireless controls' then 'Mobile Networks' then 'Access Point Names'. At this screen press menu, then 'New APN'.
Fill in the following information:
After that you should have 3G/EDGE internet access on your android.
| Name | Donation | Total Amount |
| Alice | 10 | |
| Alice | 12 | |
| Alice | 8 | |
| Alice | 9 | |
| Bob | 2 | |
| Bob | 3 |
UPDATE table SET "Total Amount" = x.total from ( SELECT "Name", SUM("Amount") AS total FROM table GROUP BY Name ) AS x WHERE x.Name = Name;
def powerset(seq):
"""
Returns all the subsets of this set. This is a generator.
"""
if len(seq) <= 1:
yield seq
yield []
else:
for item in powerset(seq[1:]):
yield [seq[0]]+item
yield item
#! /bin/bash
FILES=$*
TMP_FILE=$(mktemp combined-traces.gpx.XXXXXX)
[ "$TMP_FILE" ] || exit 1
cat ${FILES} | gpsbabel -i nmea -f - -x sort,time -x discard,hdop=4,vdop=4 -x track,merge,sdistance=0.5k,title="track-%Y-%m-%d-%H:%M:%S" -x track,speed -o gpx -F ${TMP_FILE}
POINTS=$(xmlstarlet sel -N gpx=http://www.topografix.com/GPX/1/0 -t -m "/gpx:gpx" -v "count(//gpx:trkpt)" ${TMP_FILE})
NUM_TRACKS=$(xmlstarlet sel -N gpx=http://www.topografix.com/GPX/1/0 -t -m "/gpx:gpx" -v "count(./gpx:trk)" ${TMP_FILE})
echo "Found ${POINTS} trackpoints in ${NUM_TRACKS} tracks"
for TRACK in $(xmlstarlet sel -N gpx=http://www.topografix.com/GPX/1/0 -t -m "/gpx:gpx/gpx:trk" -v "./gpx:name" --nl ${TMP_FILE}) ; do
echo "Extracting ${TRACK}.gpx..."
gpsbabel -i gpx -f ${TMP_FILE} -x track,name=${TRACK} -o gpx -F ./${TRACK}.gpx
done
rm ${TMP_FILE}
echo "Done"
mkfifo pipe.fifo
pv bigfile > pipe.fifo
bigcommand bigfile
./adb install /path/to/ConnectBot-svn-rXXXX.apk
./adb install ~/Desktop/ConnectBot-svn-r174.apk
$ sudo gedit /etc/udev/rules.d/50-android.rules
SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", MODE="0666"
sudo chmod a+rx /etc/udev/rules.d/50-android.rules
./adb devices List of devices attached HT847GZ20615 device
$ ./adb shell $ su # am start -a android.intent.action.MAIN -n com.android.settings/.Settings #