How to Fix Ubuntu Unlock wireless/Gnome Keyring Issues

Even if you manage to get wireless/wifi working fine in Ubuntu, one annoying issue (if you have auto login set) will be that the ‘Gnome keyring’ will keep prompting you for a password every time you login or wake from hibernation - so that it could connect to my Wi-Fi network.

The solution is simple but one you shouldn’t have to worry about:

  • Right click the Network Manager icon in your panel
  • Select Edit Connections, and switch to the Wireless tab
  • Select the connection you want to work with and click the Edit button
  • Check the boxes for Connect Automatically and Available to all users.

2 Decimal Places in Javascript/jQuery

I always forget how to format a number as 2 decimal places in Javascript/jQuery, its extremely simple, just use the unmemorable toFixed() function - refer below is an example

1
$("#total"+row_number).html($total,toFixed(2));

Ubuntu Numlock

If your using a smaller Ubuntu or Debian based distro (lubuntu, solusOS, etc..) you’ll often find that numlock on the keyboard isn’t turned on my default. Just paste the below commands into the commandline and numlock will be on by default.

1
2
3
sudo apt-get update
sudo apt-get -y install numlockx
sudo sed -i 's|^exit 0.*$|# Numlock enable\n[ -x /usr/bin/numlockx ] \&\& numlockx on\n\nexit 0|' /etc/rc.local

Commandline Dropbox Client

Looking for a simple way to upload files from your server to Dropbox without doing a full sync?

By using the script from Andrea Fabrizi your easily upload or download individual files to and from Dropbox from the commandline

Setup

Download the script from github with wget

wget https://raw.github.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh

Make it executable

chmod +x dropbox_uploader.sh

Run the dropbox_uploader script ./dropbox_uploader.sh and it’ll print out the below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
This is the first time you run this script.
Please open this URL from your Browser, and access using your account:

-> https://www2.dropbox.com/developers/apps

If you haven't already done, click "Create an App" and fill in the
form with the following data:

App name: MyUploader888
Description: What do you want...
Access level: App folder or Full Dropbox

Now, click on the "Create" button.

When your new App is successfully created, please type the
App Key, App Secret and the Access level:

# App key: 

Open up the url https://www2.dropbox.com/developers/apps in your browser, sign into Dropbox and click the Create an app button

Fill in the app name as listed by the script, select ‘Core’ and ‘App folder access’ (this will create a folder call /App/MyUploader888 in your Dropbox director. If you want to access all files in your Dropbox select ‘Full Dropbox’

Dropbox will now show you your API details for this app, get the ‘App key’ and paste it into commandline Then paste in the ‘App secret’ when requested

1
2
3
# App key: jxxxxxxxxxxxxxxp
# App secret: sxxxxxxxxxxxxxx4
# Access level you have chosen, App folder or Full Dropbox [a/f]: 

Select the access level and it’ll provide you with link to verify the app.

https://www2.dropbox.com/1/oauth/authorize?oauth_token=nxxxxxxxxxxxxxxf

Open the link in your browser and Allow the app access

Your now setup to upload/download individual files from the command line to and from Dropdox

Usage

To upload a file from your server to Dropdox just run

./dropbox_upload.sh upload myfiles.zip

If you have selected the Full Dropbox access you can sepecify the folder location to upload to

./dropbox_upload.sh upload /some/folder/indropbox.com/myfiles.zip

Other commands available are download which uses the same style as the uppload command, delete,list,info and unlink

Posterous Backup

Posterous.com is due to shutdown at the end of April 2013. If your after a simple way to backup a Posterous site the below command will download your Posterous site as static html

wget -r -l inf -k -E -p -nc http://yourblog.posterous.com/

The options used are:

  • -r recursive
  • -l inf infinite depth
  • -k suffix html files with .html
  • -E update the saved files with links to local files
  • -p download page resources
  • -nc don’t redownload urls more than once

This command won’t download all images (ones hostes on a different CDN) but it will download the majority of your site fine

PDO Out of Memory Fix

If your having issues with large PDO query sizes in PHP and getting out of memory issues the solution is to set PDO::MYSQL_ATTR_USE_BUFFERED_QUERY to false

refer below example

1
2
3
4
5
<?php
$pdo = new PDO('mysql:host=127.0.0.1', 'foo', 'bar', array(
    PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION,
));
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

For whatever reason on certain system even small queries can bomb out - just add in this attribute and your queries should now run fine in PDO

How to Ignore Changes in Tracked Files With Git

If you’ve added files into your GIT repository, then realised you don’t want changes to these files tracked.( ie. log files, cache directories etc. ) adding the tracked files to .gitignore won’t work.

GIT will still track the changes and commit the file if you use the -a parameter.

To untracked file changes use the below command:

git update-index --assume-unchanged <file>

If you wanna start tracking changes again run the following command:

git update-index --no-assume-unchanged <file>

For more info refer the Git manual on this topic

jQuery Year Based Slider

I haven’t been able to find any decent year based jQuery UI date slider examples that have the 2 date ranges pre-populated.

Here’s a simple year based slider that I’m using is a current project

Demo

Code

How to Create Self Signed Wildcard SSL Certificates for Apache

Create the wildcard SSL certification

Open up your terminal and execute the below commands, replacing yourdomain.com with the domain name

1
2
3
4
mkdir /etc/ssl/wildcard.yourdomain.com
cd /etc/ssl/wildcard.yourdomain.com/
openssl genrsa 2048 > host.key
openssl req -new -x509 -nodes -sha1 -days 3650 -key host.key > host.cert

For a wildcard cert enter *.yourdomain.com for Common Name. It’s the 6th option in the dialog. All other options can be left blank for defaults

1
2
3
openssl x509 -noout -fingerprint -text < host.cert > host.info
cat host.cert host.key > host.pem
chmod 400 host.key host.pem

Apache

Enable SSL in Apache and restart

1
2
sudo a2enmod ssl
sudo service apache2 restart

Virtual hosts

Then add the SSL settings into each VirtualHost in your Apache configuration files

Note: that if you are planning to run your sub-domain or domains on http(80) aswell asn http(443) then you need to have 2 separate virtualhost entries. 1 for port 80 and 1 for port 443

For the sub-domains you want to use with https add the below options with the 443 into your existing files

1
2
3
4
5
<VirtualHost *:443>

SSLEngine On
SSLCertificateFile /etc/ssl/wildcard.yourdomain.com/host.pem
SSLCertificateKeyFile /etc/ssl/wildcard.yourdomain.com/host.key

Then reload Apache

1
sudo service apache2 reload

To test if its working open up https://www.yourdomain.com and check if the certificate works