Thursday, 5 January 2017

Use an Amazon dash button to trigger a relay for 30min

ere is a neat script I'm running on a Raspberry PI to close a contact for 30 min (to boost the shower fan for 30min) whenever I press an

Notes:
  • The script is made to start a timer of 30min every time the button is pressed.
  • If the button is pressed when the timer is already running, the countdown restarts
  • The relay for the ventilation is connected on GPIO 24
  • Write your mac address(es) below indicated in yellow (if you don't know them, just comment the line and run the script, you will see the mac displayed when you press the button).
  • You have to half configure the Dash button before the first use (but stop the process before assigning the button to a product).
  • There are a lot of scripts online (such as this one) but I find this solution more elegant as it does not use scapy... only standard stuff. Source of where of what Ibuilt this script on


Saturday, 24 December 2016

Sound settings when using Rasplex on a Raspberry PI 1, 2 or 3

Therse are the only settings I found to work when using Rasplex with the following setup:

  • Plex on a Synology NAS (or any nas with limited CPU power supporting Plex)
  • Rasplex on a RPi (Raspberry Pi 1,2 or 3).
  • A 5.1 home cinema receiver compatible with DTS and Dolby Digital
Before using these setting I could read anything exept videos encoded with AAC 5.1 (no sound).

Here are the settings I use:
  • Number of channels: 2.0
  • Enable passthrough: Enabled
  • Dolby Digital (AC3) capable receiver: Enabled
  • Enable Dolby Digital (AC3) transcoding: Enabled
  • DTS capable receiver: Enabled
I now can read
  • All stereo formats (MP3, AAC...)
  • DTS 5.1
  • Dolby Digital (AC3) 5.1
  • AAC 5.1 (transcoded to Dolby Digital 5.1)

Thursday, 14 May 2015

How To Shrink Your Virtualbox VM And Free Up Space For Your Hard Disk - Make Tech Easier

Ever needed to share VirtualBox machines, transfer them over the internet or back them up?

This article describes how to reduce the size of your virtual machine hard disk. Space savings are incredible, especially if you've been adding/deleting files to the VM hard drive a lot.

What the article does not say (because it is obvious): zip your virtual machine after performing the described steps and before transferring/backing it up.

Link: How To Shrink Your Virtualbox VM And Free Up Space For Your Hard Disk - Make Tech Easier

Sunday, 10 May 2015

Migrate a VMware disk to Virtualbox: VMware player does not work on the Dell XPS 13 2015 Developer Edition

The Dell XPS 13 2105 Developer Edition is a wonderful machine. It comes with plenty of punch in a small laptop but the most interesting thing is that it comes with Ubuntu loaded on it.

If you plan to use VMware player on it, you should know that I got plenty of issues as soon as I started using it: freezes every day or so, the sound was distorted and copy/paste wan't working 100%, I won't get in the details why I chose VMware player over Virtualbox in the first place.

For my office work (read: Microsoft Office 2013 ;-), I needed and purchased licences from Microsoft and wasn't too keen on creating a new virtual machine so I decided to migrate it. The best (and only) working solution I found was to convert the virtual harddrive and use it in VirtualBox. Here are the steps I followed (source):

Install qemu

sudo aptitude install qemu

Convert the virtual disk to a raw image

qemu-img convert /path/to/original.vmdk converted.bin


Convert the raw image to a VirtualBox vdi format:

VBoxManage convertdd converted.bin converted.vdi


 I then recreated a VirtualBox virtual machine around that harddrive and was good to go.
Note: I had to call the Microsoft support to (re)activate (virtual hardware had changed) Windows. I suppose they don't mind as long as you don't use the other virtual machine (which I don't intend to do since it was crashing my computer).

Please let me know if it helps (in the comment section below).

Friday, 31 October 2014

Recover everything between two lines matched with grep

I frequently need to recover everything between two lines (that I can match with grep).

Example:
line1
some text
random text
random text
other text
line2
line3
line4
Let's say I want to retrieve the 'random text' lines but have no clue of what it looks like. I however know that the previous line contains the unique 'some text' string and that the line just after the random text I want to retrieve contains the unique 'other text' string.
Note the previous and next lines can contain any other text on them as long as I have a pattern I can match with grep.

Here is how I solve that problem;

Find the pattern before and return it with 999999 lines after

grep 'some text' -A 999999

Remove the first line of the previous results (start at line two)

tail -n +2

Find the pattern following our random text and return it with 999999 lines before it 

grep 'other text' -B 999999

Skip the last line of these results

head -n -1

Put together we get

cat file.txt |  grep 'some text' -A 999999 | tail -n +2 | grep 'other text' -B 999999 | head -n -1

Friday, 24 October 2014

Write your (Word) document with 'style' using keyboard shortcuts


This is a quick tip for people who don't want to start clicking on the Heading/Normal styles all the time when writing a long document (full of titles). This is especially handy when making a quick fist draft taking care of the structure but without looking too much at the format.

Here are the most useful keyboard shortcuts I use in these cases. Change the current selection or line to:

  • Heading 1: Ctrl+Alt+1
  • Heading 2: Ctrl+Alt+2
  • Heading 3: Ctrl+Alt+3
  • Normal: Ctrl+Shft+N
Thes are keyboard shortcuts any good MSWord document writer should know.

Friday, 10 October 2014

Useful commands when parsing HTML from the command line

These are commands I'm using all the time when working with HTML files from the command line:

Replacing <BR> tags with actual carriage returns:

sed 's_<[bB][rR][^>]*>_\n_g'
Note this command works with
  • Capitalised and small letter tags e.g.: <BR> or <br>
  • Tags with additional parameters (which is nonsense), e.g.: <br class="something">
  • Tags with spaces and a closing slash, e.g.: <br />

Replacing &nbsp; with spaces

sed 's_&nbsp;_ _g'

Remove heading space at the begining of each line

sed 's_^[\t ]*__g'

Remove all remaining html tags

sed 's_<[^>]*>__g'

You can then use all these commands together:
cat file.html | sed 's_<[bB][rR][^>]*>_\n_g' | sed 's_&nbsp;_ _g' | sed 's_^[\t ]*__g' | sed 's_<[^>]*>__g'