/dev/blog/ID10T

Advertisement

Mount partitons of dd block device image

• linux • Comments

A small tip while I’m playing with my Raspberry Pi, Docker and the love child of both, Hypriot:

If you want to mount an image of a block device you created with dd, you might encounter the problem that you don’t know where the partitions start. In past times I used either offsets or kpartx for that. Today I found an easier way on superuser, the losetup tool. With losetup the process is really easy. Just associate your image file with a new loop device mount the corresponding partition:

  losetup --partscan --find --show disk.img
  mount /dev/loop0p1 /mnt

If you’re done, umount and detach the file from the loop device:

  losetup -d /dev/loop0

It seems the –partscan function is fairly new and not every Linux distro has such a new losetup version. Then you can either upgrade the version or do it as our ancestors did, utilizing offset or using kpartx.

Picture Howto: Adding group members in TextSecure

• misc • Comments

I had the big task of explaining my mother how to add members to a TextSecure group. As she’s no IT native, she often forgets and tends to be slow on the uptake. That’s why I created a picture howto for it. It’s not polished in any way, but perhaps I can help someone who has met a similar challenge.

Python3: UnicodeDecodeError when using subprocess.Popen

• python • Comments

While writing a Python script which handles an applications STDOUT on Windows, I encountered an error:

Traceback (most recent call last):
  File "C:/Users/m3adow/PycharmProjects/proj1/script.py", line 355, in <module>
    main()
  File "C:/Users/m3adow/PycharmProjects/proj1/script.py", line 347, in main
    openme(bin_args)
  File "C:/Users/m3adow/PycharmProjects/proj1/script.py", line 307, in spectate
    for line in iter(p.stdout.readline, ''):
  File "C:\tools\python\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 1478: character maps to <undefined>

The lines in question looked like this:

def openme(bin_args):
  with subprocess.Popen(args=bin_args, stdout=subprocess.PIPE, stderr= subprocess.STDOUT, universal_newlines=True) as p:
        for line in iter(p.stdout.readline, ''):
          process_stdout(line)

Modifying And Repacking Android Apps

• android • Comments

The problem

While installing a SuperHexagon APK which I bought from Humble Bundle a couple of years ago I encountered an error. The package installer simply stated “App not installed”, a logcat got me some more information:

D/Finsky  (22452): [1] 1.onResponse: Verification id=7 response=0
D/Finsky  (22452): [1] PackageVerificationReceiver.onReceive: Verification requested, id = 7
E/Vold    (  226): Error creating imagefile (Read-only file system)
E/Vold    (  226): ASEC image file creation failed (Read-only file system)
W/Vold    (  226): Returning OperationFailed - no handler for errno 30
E/PackageHelper(22426): Failed to create secure container smdl1097147630.tmp

Trying to install it via adb install didn’t help either:

adb install c:\home\downloads\SuperHexagon-release-v1.0.7-humblebundle.apk
5139 KB/s (27327032 bytes in 5.192s)
    pkg: /data/local/tmp/SuperHexagon-release-v1.0.7-humblebundle.apk
Failure [INSTALL_FAILED_CONTAINER_ERROR]

I did some research and finally found the problem. The HumbleBundle Android version of SuperHexagon hasn’t aged well, the APK is configured to install on SD card. This simply doesn’t work on my First Generation Moto G which doesn’t even have a SD card slot. So I did some more reasearch and found the solution. Of course this will most likely work for other applications with the same error too.

Use Perl As Sed Alternative

• linux • Comments

Small tip for people often using sed for substitutions: In the process of porting my old wordpress blog posts to Jekyll I had to do a lot of substitutions. Specifically I had to substitute a lot of HTML Tags. Sadly, sed in most Linux distributions doesn’t support lazy regex quantifiers. When searching for an expression which is only known to begin with <code and end with > and a lot of possibilites between those delimiters, it’s really annoying to not have lazy quantifiers.

That’s why I’d recommend using perl for this. Perl can easily be used like sed:

# sed
sed -e 's/<code.*lang="bash".*>/&#123;% highlight bash %&#125;/g' test.html
# perl
perl -pe 's/<code.*?lang="bash".*?>/&#123;% highlight bash %&#125;/g' test.html
# Of course you can substitute inline:
perl -pi -e 's/<code.*?lang="bash".*?>/&#123;% highlight bash %&#125;/g' test.html

I really prefer the Regex handling of perl over the limited one of sed. That’s why I totally fell in love with this.

Advertisement