Python: talk to bash via Popen

Use Popen to start bash. Then pipe stdout,stderr,stdin to be able to read and write to these handles. Write ‘ls’ to stdin followed by an enter. Calling flush is important, without it nothing happens.

#!/usr/bin/env python3
import subprocess
def main():
cmd = 'bash'
process = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
universal_newlines=True)
process.stdin.write('ls\n')
process.stdin.flush()
for line in iter(process.stdout.readline, b''):
print(line, end='')
if __name__ == '__main__':
main()

Golang: why packages matter when testing

When creating a piece of software in Golang you are not obligated to separate your code into logical packages. You can go ahead and have everything in a single package called main and it will work fine. Until you start to write tests and the most simple unit test will take seconds to complete when running `go test`. Why is this? Because go test compiles that needs to be compiled in order to run the tests. So if you have defined only one package then EVERYTHING is going to be compiled. Even third party libraries…

So creating logical packages benefits your program’s structure and maintainability, but also speeds up your test times, or gives you back the time lost when testing with one package name. Depends on the angle you look at it…

Convert SVN repository to a GIT repository

Steps I followed to convert my SVN repository to a GIT repository.

1.

svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt

then I editted the authors-transform.txt to have my name fully spelled out and my e-mail address filled in.

2.

git svn clone [SVN repo URL] --no-metadata -A authors-transform.txt --stdlayout ~/temp --prefix=origin/

the important part for me was adding the –prefix=origin/. Without this, it all becomes a big mess because?the remote branches will have an empty prefix which makes things harder for you in the future.

3.

To create a .gitignore file based on your svn:ignore properties use the following command:

cd ~/temp
git svn show-ignore -i origin/trunk > .gitignore
git add .gitignore
git commit -m 'Add .gitignore from svn:ignore properties'

Again the critical part for my situation was to add the -i origin/trunk (or –id). Without it it doesn’t know what SVN branch you want the properties off.

All of this was shamelessly copied from http://john.albin.net/git/convert-subversion-to-git with some modifications to really make it work, because that post is a little outdated. Credits to John Albin.

 

modesetting instead of xf86-video-intel plus benchmark

Today I stumbled upon this reddit-article.

It speaks about using the modesetting driver shipped with xorg instead of the xf86-video-intel driver. I did a benchmark with the xf86-video-intel and the modesetting driver to see which performs better in order to decide if I will drop xf86-video-intel. Here are the results:

Unigine-valley Basic preset @xf86-video-intel:

FPS: 14.4
Score: 604
Min FPS: 8.2
Max FPS: 33.1

Unigine-valley Basic preset @modesetting:

FPS: 23.5
Score: 984
Min FPS: 11.8
Max FPS: 40.3

It doesn’t really matter what hardware I’m using, all that matters is that the situation improved. But for reference: Intel HD Graphics 5500.

So my choice is simple, I’m ditching xf86-video-intel in favor of using modesetting, which was already installed on my system together with xorg-server.

backlight issue

because of the switch to modesetting driver the xbacklight utility does no longer work. Using a xorg config file with the Backlight option set to intel_backlight also does not work as a workaround. So I installed light-git (from the AUR) which allows me to control my laptop backlight once again.

Goodbye Firefox (at least for now)

Because of things like this I will stop using Firefox today. The article I linked to is about the file picker in Firefox, which is really lacking in many areas. My particular use case is as follows:

I use dropbox camera uploads to upload each and every photo/video I take. So on my laptop I have a folder containing thousands of photos and videos named in a “Y-M-D H.M.S.jpg” format. Now when I want to upload a few photos via Firefox, I do not get a thumbnail/preview for a jpg if the file is larger than 2MB(or has it got to do with a longest side of over 4096 pixels? either way no preview for me…). Another fun fact: 99% of my photos is larger than 2MB. So in order to find the photo that I want to upload I have to open up a file explorer and search in thousands of photos. Then I have to remember the name in the awkward format. Then I can head back to FF in the hope I still remembered the filename. This effort is only for uploading one photo… Imagine when I want to upload more than one photo. In short, usability is hard to find in Firefox when uploading photos.

For me this one (little?) thing is so annoying that FF is no longer usable for me. This annoyance have been present for over 10 years now!

Well done Firefox developers!

Maak een Ubuntu 16.04 live usb-stick met Rufus

Ubuntu 16.04 LTS is op 21 april 2016 uitgekomen. LTS staat voor Long Time Support en daarom is dit een versie van Ubuntu die het waard is om de komende tijd te gebruiken door middel van een live usb-stick.

Met Rufus een Ubuntu 16.04 LTS live usb-stick maken

Dit artikel legt je uit hoe je met behulp van Rufus een Ubuntu 16.04 live usb stick maakt. Volg de stappen:

  1. Ga naar www.ubuntu.com
  2. Klik op Download (rechtsboven, links naast zoekveld)
  3. Klik op “Ubuntu Desktop >”, je komt nu op een pagina waar staat Ubuntu 16.04 LTS
  4. Klik dan op de oranje Download knop
  5. Nu willen ze dat je gaat doneren, scroll helemaal naar beneden en klik op “Not now, take me to the download”
  6. De download start in paar seconden
  7. Ga naar https://rufus.akeo.ie
  8. Scrol een beetje tot je Download ziet en kies dan voor Rufus 2.8 Portable
  9. Start rufus. Er wordt gevraagd of je online wilt zoeken naar programma updates. Klik maar op nee. Het programma start verder op. Doe je usb stick van 4GB of groter in je computer… even wachten tot je computer de usb stick herkent.  Kies je Apparaat (usb stick) in de eerste dropdown, vul de rest in zoals de afbeelding weergeeft. Het veld Clustergrootte wordt automatisch ingevuld. Klik op het icoontje met een cd+drive om te browsen naar de ubuntu-16.04-desktop-amd64.iso. Het veld Nieuwe volumelabel wordt nu automatisch ingevuld.
  10. Druk nu op Start.
    afbeelding van Rufus waarmee een Ubuntu 16.04 LTS live usb stick gemaakt wordt
    Rufus instellingen om een bootable Ubuntu 16.04 LTS live usb stick te maken

    (Het kan zijn dat er gevraagd wordt om een paar bestanden te downloaden die met syslinux te maken hebben, klik dan op Ja, zodat rufus deze automatisch voor je download.)
    Er wordt nog een laatste keer gevraagd of je echt wilt doorgaan, klik op OK als je zeker weet dat je het juiste apparaat hebt geselecteerd.

 

Start nu je computer opnieuw op en start op vanaf de usb stick die je net hebt gemaakt door in je bios de boot order zo in te stellen dat je USB device bovenaan staat. Sommige computers geven ook een boot optie aan om tijdens het booten eenmalig de opstart disk te kiezen, dit is handiger dan de vorige optie omdat je nu geen bios instellingen permanent hoeft te veranderen.

partclone restore exit error

Over the last three years I have made a lot of disk clones with clonezilla. I did this before reinstalling another OS or just to backup, but I always did it quickly. That means I just cloned the disk and never looked at it again. I only had to restore two or three times.

The problem is that because I did not really document anything about what is in the image, I now have no clue if I still want to keep image X or image Y. I need to see what is in the images…

So I’m restoring  images by cat’ing together the compressed pieces of my images and decompressing them and piping that stream into partclone restore utility.

Now I keep getting this very obscure error:
Partclone v0.2.80 http://partclone.org
Starting to restore image (2013uncompressed.img) to device (2013.iso)
UID is root.
source=2013uncompressed.img, target=2013.iso
open source file/device 2013uncompressed.img
open target file/device 2013.iso
device (2013.iso) is mounted at
error exit

I have no clue what to do with that. So I downloaded an old version of clonezilla that contained the same version of partclone that the cloned image was made with. That gave the same error. Then I found an answer on askubuntu with zero rating. Just create the file first before you issued the partclone.restore. So to summarize:

touch /dir-to-new-image/partition.img
sudo cat /dir-to-images/partitionname.gz.* | sudo gzip -d -c | sudo partclone.restore -C -s - -O /dir-to-new-image/partition.img

So in the end this was super easy and I did not even need a clonezilla live usb. I could just do this from arch linux using partclone 2.80.

Thanks to:

Are you copy pasting too? Maybe this is something for you then! COPYDROID

Copydroid Mascotte
The fierce Copydroid

Today I finally released my android application called Copydroid. Copy-what? Yes Copydroid, as the name implies this is an android application that copies something.

So let me explain to you what this app does: it lets you copy and paste between your computer and android device! How cool is that? No more e-mail sending or android cable searching to quickly transfer some text from phone to computer. You can now install Copydroid on your android device and a client on your desktop/laptop and setup a link between these two. After setting up you are ready to go! Just type some text on your computer, select it and copy it (CTRL+C!!!)… voila the text is now available on your phone or tablet or whatever android device you have that is connected to the internet.

It also works the other way around, so you could select for example a link in your favorite android browser, copy it. Go to your computer if you are not allready sitting in front of it and then paste (CTRL+V).

How nice is this? I already like it a lot, that’s why I made the app!

The app is available at the Android Market a.k.a. Google Play:

Update 08-03-2016: At the moment this app is unavailble because I have no time to maintain it.

GrabIt – Repair it – out the name of the par2 file from the command line

Is your GrabIt newsgroup leecher not unpacking your downloads anymore? Does it flash the following warning at the bottom of the screen:

Repair it - out the name of the par2 file from the command line

If you have this problem, then I have your solution! Check your download folder and see if any foldername ends with “.par2” or “.PAR2” or “.par” or “.PAR” or anything like that. If you found folders ending with “.par2” you should remove that from the folder name, so just rename it and remove the .par2/.PAR2/.par/.PAR from the folder name. It is a folder and not a par file, so it should not have this extension in the folder name.

Note: You should only change the foldername when GrabIt is DONE downloading/extracting, or change a folder name GrabIt is not currently using to download to or extract from. If you do this anyways you will mess things up and I will not take responsibility for it…

When you resolved all folder names to be without .par(2) extensions the repair and extract now functionallity will once again work like it has before!

What GrabIt does is checking all files/folders in the download folder and checks to see if the file/foldername has some kind of .par extension. Because it can’t handle a folder to use as par file you will receive the error message stated above.

Good luck resolving your problems!

Happy downloading!