Travel Log

This is a list of all the countries I have flown to since 1999.

Posted in General | Tagged , | Leave a comment

Fixed drive letters for removable USB sticks

If you use multiple USB drives, you’ve probably noticed that the drive letter can be different each time you plug one in. If you’d like to assign a static letter to a drive that’s the same every time you plug it in, read on.

Windows assigns drive letters to whatever type of drive is available. This can be annoying especially if you use backup tools or portable apps that prefer to have the same drive letter every time.

To work with drive letters, you’ll use the Disk Management tool built into Windows. In Windows 7, 8, or 10, click Start, type “create and format,” and then click “Create and format hard disk partitions.” Don’t worry. You’re not going to be formatting or creating anything. That’s just the Start menu entry for the Disk Management tool. This procedure works the same in pretty much any version of Windows (though in Windows XP and Vista, you’d need to launch Disk Management through the Administrative Tools item in the Control Panel).

Windows will scan and then display all the drives connected to your PC in the Disk Management window. Right-click the USB drive to which you want to assign a persistent drive letter and then click “Change Drive Letter and Paths.”

The “Change Drive Letter and Paths” window the selected drive’s current drive letter. To change the drive letter, click “Change.”

In the “Change Drive Letter or Path” window that opens, make sure the “Assign the following drive letter” option is selected and then use the drop-down menu to select a new drive letter. When you’re done, click “OK.”

NOTE: We suggest picking a drive letter between M and Z, because earlier drive letters may still get assigned to drives that don’t always show up in File Explorer—like optical and removable card drives. M through Z are almost never used on most Windows systems.

Windows will display a warning letting you know that some apps might rely on drive letters to run properly. For the most part, you won’t have to worry about this. But if you do have any apps in which you’ve specified another drive letter for this drive, you may need to change them. Click “Yes” to continue.

Back in the main Disk Management window, you should see the new drive letter assigned to the drive. You can now close the Disk Management window.

From now on, when you disconnect and reconnect the drive, that new drive letter should persist. You can also now use fixed paths for that drive in apps—such as back up apps—that may require them.

Source: howtogeek

Posted in MS-Windows | Tagged , , , , , , , , , | Leave a comment

Xnest

This trick lets you run X-Windows within an X-Windows session. This is kinda like running VNC. It is useful for testing scenarios.

#!/bin/sh
Xnest :1 -name "Bla" -ac -geometry 800x600 &
sleep 1
export DISPLAY=:1
exec xterm
Posted in Linux | Tagged , , | Leave a comment

Side Load apps on Android TV

So we bough a Philips 50PFK6540. This is a 50" TV with Ambi Ligh and Android TV.

One of the things I wanted to do from the very start was to load my own APKs. This was not possible until a recent (2016) update that enabled the "Install from Unknown Sources" setting option.

This made it possible to side load applications. However, things are not as easy as I initially thought. Because while installing from unknown sources was possible, you can not do this from the built-in browser. So the procedure is as folows:

  1. Go to settings to enable Install from Unknown sources, which should be under Security & Restrictions.
  2. Download ES File Explorer from the Play Store. A bit of a warning: on phones and tablets, ES File Explorer isn’t something that is generally recommended as it used to be a reliable file manager that was one of the most valuable Android apps, but recently it became riddled with ads—many of which are highly intrusive—leading many users to uninstall it and websites to remove it from their “must have” lists. Fortunately, the Android TV app seems to have gone largely untouched by this, so it still is recommended it for the purpose of this tutorial.
  3. Use ES File Explorer to download the APK you want to side load. There is a number of ways to do this. I used the built-in FTP server. But you could use any method (i.e Thumb drive, Cloud Storage, etc...)
  4. Open the APK from ES File Explorer and install it.
Posted in Android | Tagged , , , , , , , , , , , | 1 Comment

Building Signed APKs

Building signed APK's for Android is easy if you know what you are doing.

Preparation

First you need to have a keystore. Use this command:

#!/bin/bash
keystore_file="my_key_store.keystore"
key_name="john_doe"
secret='fake_password'
name='John Doe'
dept='Engineering'
org='TLabs Inc'
place='New York'
province='NY'
country='US'

keytool -genkey -v -keystore "$keystore_file" -alias "key_name" -keyalg "RSA" -validity 10000 -storepass "$secret" -keypass "$secret" <<EOF
$name
$dept
$org
$place
$province
$country
yes
EOF

Remember the keystore file and passwords.

Build instructions

In your build.gradle you need the following:


android {
  signingConfigs {
    release {
      storeFile file("my_keystore.keystore")
      storePassword "{password}"
      keyAlias "Key_Alias"
      keyPassword "{password}"
    }
  }
  buildTypes {
    release {
      signingConfig signingConfigs.release
    }
  }
}
Posted in Android | Tagged , , , | Leave a comment

Archiving DVDs and CDs

Since now I have a Android TV I put away my HTPC and with that the capability to view DVDs or listen CDs directly.

So I converted my entire CD and DVD library to media files and stored in my home NAS.

Since we are talking hundreds of DVDs and CDs, I was using some tools.

CD ripping

For CD ripping, pretty much everything can be done with abcde. I would use the following command:

abcde -G -k -o mp3 -x

Options:

  • -G : Get album art.
  • -k : Keep wav after encoding. This is not really necessary.
  • -o mp3 : Output to mp3.
  • -x : Eject the CD after all tracks have been read.

Afterwards I would use eyeD3 to embed the cover art and tweak things. (Note under archlinux, eyeD3 is installed from the python2-eyed3 package).

To add cover art:

eyeD3 --add-image="$cover_file":FRONT_COVER *.mp3

DVD Ripping

For DVD Ripping I was using a couple of homegrown scripts. These can be found on github.

I started using vobcopy, but if I were to do this again I would use dvdbackup with the -M option. vobcopy is quite old and probably is orphaned by now.

Scripts for archiving media

Scripts:

  • archive-dvd : Create an iso image from a DVD.
  • alltitles : Extract titles/chapters from a DVD.
  • auto.sh : Used to transcode titles/chapters extracted by alltitles

archive-dvd

This script uses vobcopy and mkisofs to create an ISO file. Just run the script and insert a DVD, you will get an ISO file in return.

alltitles

Usage:

[option_vars] sh alltitles [chapter]

Option vars:

  • drive=[device-path] defaults to /dev/sr0
  • titles="01 02 03 ..." defaults to all titles in DVD (as listed by lsdvd)
    You can also specify titles as:
    title="01,1-4 01,5-8"
    This will create two files, one with track 1, chaptes one trough four (inclusive) and another one with track 1, chapters five through eigth (inclusive)

Command options:

chapter: Leave blank for all chapters, otherwise:

-chapter [$start-$end]

Will dump starting from $start until $end. (or end) If you only want to extract chapter 7 by itself, use -chapter 7-7

auto.sh

Usage:

sh $0 [options] 

vob files must be the ones extracted from alltitles.

Options:

  • --preview|-p : Only encode 30 seconds from 4 minutes in
  • --copy|-c : Do only copy
  • --interlace|-i : Force interlace filter
  • --no-interlace|+i : Disables interlace filter

Dependancies

  • libdvdcss (or equivalent).
    This is used by the dvdread library to decode CSS protected DVDs.
  • libdvdread
    This is used to read DVD by a number of binaries.
  • vobcopy
    Used by archive-dvd to extract the data that will be used to create the ISO image. Uses libdvdread.
  • udisks or udisks2
    Used by the scripts to detect when a CD/DVD is inserted.
  • cdrkit Used to create the iso images by archive-dvd.
  • lsdvd
    Used by alltitles.sh to get track information.
  • mplayer
    Used by alltitles.sh to extract DVD titles/chapters.
  • ffmpeg
    Used by alltitles.sh to encode video.

Some useful commands

Using mplayer to play extract:

mplayer -dvd-device /dev/sr0 dvd://$title -chapter $chapter-$chapter -dumpstream -dumpfile ~/$title.VOB
Posted in IT Multimedia | Tagged , , , , , , , , , , , , , , | Leave a comment

Writing Safe Shell scripts

This article comes from Writing Safe Shell.

Writing shell scripts leaves a lot of room to make mistakes, in ways that will cause your scripts to break on certain input, or (if some input is untrusted) open up security vulnerabilities. Here are some tips on how to make your shell scripts safer.

Don't

The simplest step is to avoid using shell at all. Many higher-level languages are both easier to write the code in in the first place, and avoid some of the issues that shell has. For example, Python will automatically error out if you try to read from an uninitialized variable (though not if you try to write to one), or if some function call you make produces an error.

One of shell's chief advantages is that it's easy to call out to the huge variety of command-line utilities available. Much of that functionality will be available through libraries in Python or other languages. For the handful of things that aren't, you can still call external programs. In Python, the subprocess module is very useful for this. You should try to avoid passing shell=True to subprocess (or using os.system or similar functions at all), since that will run a shell, exposing you to many of the same issues as plain shell has. It also has two big advantages over shell — it's a lot easier to avoid word-splitting or similar issues, and since calls to subprocess will tend to be relatively uncommon, it's easy to scrutinize them especially hard. When using subprocess or similar tools, you should still be aware of the suggestions in "Passing filenames or other positional arguments to commands" below.

Shell settings

POSIX sh and especially bash have a number of settings that can help write safe shell scripts.

I recommend the following in bash scripts:

set -euf -o pipefail

In dash, set -o doesn't exist, so use only set -euf.

What do those do?

set -e

If a command fails, set -e will make the whole script exit, instead of just resuming on the next line. If you have commands that can fail without it being an issue, you can append || true or || : to suppress this behavior — for example set -e followed by false || : will not cause your script to terminate.

set -u

Treat unset variables as an error, and immediately exit.

set -f

Disable filename expansion (globbing) upon seeing *, ?, etc..

If your script depends on globbing, you obviously shouldn't set this. Instead, you may find shopt -s failglob useful, which causes globs that don't get expanded to cause errors, rather than getting passed to the command with the * intact.

set -o pipefail

set -o pipefail causes a pipeline (for example, curl -s http://sipb.mit.edu/ | grep foo) to produce a failure return code if any command errors. Normally, pipelines only return a failure if the last command errors. In combination with set -e, this will make your script exit if any command in a pipeline errors.

Quote liberally

Whenever you pass a variable to a command, you should probably quote it. Otherwise, the shell will perform word-splitting and globbing, which is likely not what you want.

For example, consider the following:

[email protected] tmp [15:23] $ dir="foo bar"
[email protected] tmp [15:23] $ ls $dir
ls: cannot access foo: No such file or directory
ls: cannot access bar: No such file or directory
[email protected] tmp [15:23] $ cd "$dir"
[email protected] foo bar [15:25] $ file=*.txt
[email protected] foo bar [15:26] $ echo $file
bar.txt foo.txt
[email protected] foo bar [15:26] $ echo "$file"
*.txt

Depending on what you are doing in your script, it is likely that the word-splitting and globbing shown above are not what you expected to have happen. By using "$foo" to access the contents of the foo variable instead of just $foo, this problem does not arise.

When writing a wrapper script, you may wish pass along all the arguments your script received. Do that with:

wrapped-command "[email protected]"

See "Special Parameters" in the bash manual for details on the distinction between $*, [email protected], and "[email protected]" — the first and second are rarely what you want in a safe shell script.

Passing filenames or other positional arguments to commands

If you get filenames from the user or from shell globbing, or any other kind of positional arguments, you should be aware that those could start with a "-". Even if you quote correctly, this may still act differently from what you intended. For example, consider a script that allows somebody to run commands as nobody (exposed over remctl, perhaps), consisting of just sudo -u nobody "[email protected]". The quoting is fine, but if a user passes -u root reboot, sudo will catch the second -u and run it as root.

Fixing this depends on what command you're running.

For many commands, however, -- is accepted to indicate that any options are done, and future arguments should be parsed as positional parameters — even if they look like options. In the sudo example above, sudo -u nobody -- "[email protected]" would avoid this attack (though obviously specifying in the sudo configuration that commands can only be run as nobody is also a good idea).

Another approach is to prefix each filename with ./, if the filenames are expected to be in the current directory.

Temporary files

A common convention to create temporary file names is to use something.$$. This is not safe. It is better to use mktemp.

Other resources

Google has a Shell Style Guide. As the name suggests, it primarily focuses on good style, but some items are safety/security-relevant.

Conclusion

When possible, instead of writing a "safe" shell script, use a higher-level language like Python. If you can't do that, the shell has several options that you can enable that will reduce your chances of having bugs, and you should be sure to quote liberally.

Posted in IT development | Tagged , , , , , , , , , , , , | Leave a comment

Building chroots with yum

Building CHROOTs with Yum in a single command:

yum --releasever=7 --installroot=/chroot/jail2 -y install httpd

Will install httpd with all its dependancies. If you are on x86_64 and want a 32 bit chroot:

setarch i386 yum --releasever=6 --installroot=/chroot/jail32 -y install httpd
Posted in Linux | Tagged , | Leave a comment

MariaDB Quickest Quick start

Make sure your system is up to date:

CentOS/RHEL ArchLinux
yum update -y pacman -Syu

Install the software:

CentOS/RHEL ArchLinux
yum install mariadb-server pacman -S mariadb
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql

Start the database service:

 systemctl start mariadb

Check if it is running:

 systemctl is-active mariadb.service
 systemctl status mariadb

The following step is optional but highly recommended:

 mysql_secure_installation

Enable database to start on start-up:

 systemctl enable mariadb

Enter SQL:

 mysql -u root -p

Creating database:

 create database bugzilla;
 FLUSH PRIVILEGES;

Create user:

 GRANT ALL PRIVILEGES ON bugzilla.* TO 'warren'@'localhost' IDENTIFIED BY 'mypass';
 GRANT ALL PRIVILEGES ON killrate.* TO 'pocketmine'@'%' IDENTIFIED BY 'mypass';
 FLUSH PRIVILEGES;
Posted in Linux | Tagged , , , , , , | Leave a comment

Jaxon: Call PHP classes from JavaScript using AJAX

Jaxon

Jaxon is an open source PHP library for easily creating Ajax web applications. It allows into a web page to make direct Ajax calls to PHP classes that will in turn update its content, without reloading the entire page.

Jaxon implements a complete set of PHP functions to define the contents and properties of the web page. Several plugins exist to extend its functionalities and provide integration with various PHP frameworks and CMS.

Posted in IT development | Tagged , , , , | Leave a comment