Month: December 2015

AUTO_INCREMENT tricks

Say, on a mysql database, there’s a table example_table that contains a field example_id of type auto_increment and for some reason, one wants the next value of the auto_increment to be a specific value (x ≥ 0), then, they can do the following in a mysql session: alter table example_table auto_increment x; If the above table is not void of data and the current value of the auto_increment is y, one can run the above code, for any x > y only, otherwise an error is produced. NOTE, if a table has been emptied with the truncate statement, then the auto_increment is reset to the value 1.  

Encrypt Files / Directories

Say we have a directory myStuff in our $HOME and we want to encrypt it and use it to store sensitive information. Run: encfs $HOME/myStuff $HOME/myEncryptedStuff This will prompt you to answer few questions for the encryption. The directory myEncryptedStuff will be used as mount point to the encrypted directory myStuff To unmount the encrypted directory, run: fusermount -u $HOME/myEncryptedStuff To remount it, run: encfs $HOME/myStuff $HOME/myEncryptedStuff To change password for the encryption, have the directory unmounted and run: encfsctl passwd $HOME/myStuff

Metric vs Binary Multipliers

Metric (Decimal) prefixes 1 KB (KiloByte) = 1000 Bytes 1 MB (MegaByte) = 1000 KB or 1,000,000 Bytes 1 GB (GigaByte) = 1000 MB or 1,000,000 KB or 1,000,000,000 Bytes 1 TB (TeraByte) = 1000 GB or 1,000,000 MB or 1,000,000,000 KB or 1,000,000,000,000 Bytes Binary prefixes 1 KiB (KibiByte) = 1024 Bytes 1 MiB (MebiByte) = 1024 KiB or 1,048,576 Bytes 1 GiB (GibiByte) = 1024 MiB or 1,048,576 KiB or 1,073,741,824 Bytes 1 TiB (TebiByte) = 1024 GiB or 1,048,576 MiB or 1,073,741,824 KiB or 1,099,511,627,776 Bytes

Fluxbox Backdrop / Background / Wallpaper

Say we have an image called mySuperCoolImage.png in $HOME/Pictures and we want to set it as backdrop in fluxbox We run fbsetbg -f $HOME/Pictures/mySuperCoolImage.png This will set the backdrop to our new image (see man fbsetbg) The above command should have inserted in $HOME/.fluxbox/lastwallpaper an entry for the image file, so when fluxbox restarts, will use our chosen wallpaper. If for any reason this is not the case, we can manually edit this file and place the name of our chosen image file in place.

Quick Search in Synaptic Package Manager

Say we are using Synaptic Package Manager with our distribution, but the Quick Filter is missing from it. We need to run: apt-get install apt-xapian-index and start Synaptic to check it out. If it still does not appear, we need to close Synaptic and run further: update-apt-xapian-index -vf and wait for it to finish. Starting Synaptic again, we should have Quick Filter available on the toolbar.

Linux install into, or boot from USB flash drive in VirtualBox

Requisites: You have a working installation of Oracle VirtualBox The directory you keep your virtual machines is $HOME/VM (our example) You have created a virtual machine called alpha (our example) that has no hard disk You have plugged in your USB stick and its device name is /dev/sdx (our example) Objectives: You want to install Linux on a USB flash drive from within VirtualBox OR: You want to boot a USB flash drive using VirtualBox Once the above requisites are met, run the following in a terminal: VboxManage internalcommands createrawvmdk -filename $HOME/VM/alpha/usbflash.vmdk -rawdisk /dev/sdx Run the Oracle VM VirtualBox Manager, select the alpha virtual machine and go to its Storage properties, then select the hard disk controller and add the newly created disk usbflash.vmdk Confirm all your changes and close the Storage properties. Start the alpha virtual machine and you will find that your USB flash drive now is attached as a hard disk that you can install Linux to, or boot from

LightDM headless XClient setup

Note: The following configuration is only to be used within a trusted network only, as it is not secure Requisites: Linux host alpha (our example) with X11 environment (XServer) Linux host bravo (our example) with LightDM installed (XClient) Objectives: Remotely connect to LightDM on Linux XClient from XServer Disable XClient display (optional) Edit /etc/lightdm/lightdm.conf on the XClient (bravo) and add the following to the appropriate sections: [LightDM] start-default-seat=false [SeatDefaults] xserver-allow-tcp=true [XDMCPServer] enabled=true On host bravo restart the lightdm service, by running either: service lightdm restart or invoke-rc.d lightdm restart or any other way that your distro provides to restart a service On host alpha run X :1 -query bravo and you should get a LightDM graphical login screen for bravo

Temporarily Disable HTML Anchor

To temporarily disable a link in a website that you’re authoring, say the code for the link is: <a href=”URL_goes_here”>URL</a> You can either use css like this: <a style=”pointer-events: none; cursor: default;” href=”URL_goes_here”>URL</a> Or use javascript like this: <a onclick=”return false” href=”URL_goes_here”>URL</a>

Include $HOME/bin in any Desktop Environment

In any Linux Desktop Environment, if you want to be able to run programs and scripts that reside in your own $HOME/bin via the <Alt>+<F2> you may have to do some configuration on your own, as sometimes desktops do not have this preconfigured. Edit or create $HOME/.xsessionrc and add into it the following: if [ -d “$HOME/bin” ]; then { PATH=$HOME/bin:${PATH##$HOME/bin:} }; fi export PATH Log out and log back into X and try to run the program by invoking <Alt>+<F2> and typing the name of your program or script and pressing <Enter>