Categories

Tips and Tricks

Rather than cluttering up the main blog with my random techy discoveries (and notes mainly to myself so  don’t forget!)  I am going to put them here from now on:

Dec 2010

Security Hardening Linux / Apache / PHP5

 

Oct 09 Useful commands and stuff relating to Software RAID on Linux

http://www.howtoforge.com/software-raid1-grub-boot-debian-etch-p2

cat /proc/mdstat – gives information on Software RAID arrays

cat /proc/partitions is a handy one for identifying disks.

April 09: Quick Excel Macro to create a new sheet, clear some of the parts of it and prompt the user for a new name for the sheet:

Mostly constructed using the record and then edit the code technique (!!) throwing it up here as a reminder for me in case I need some basic stuff in VBA again in the future…

Sub CreateNewFormSheet()
'
' CreateNewFormSheet Macro
' Macro recorded 02/04/2009 by OC

' Holds the name of the new sheet
Dim newSheetName As String
Sheets("example_form").Select
Sheets("example_form").Copy Before:=Sheets(1)
Sheets("example_form (2)").Select

'Clear contents of rows that are likely to have been completed
Range("B2:D30").Select
Selection.ClearContents
'Skip ones in the middle as this is useful to have prefilled
Range("K2:N30").Select
Selection.ClearContents
Range("B2").Select

'prompt for sheet name
newSheetName = InputBox("What name should this new sheet / form have?")
' newSheetName = "new_form_rename" + Str(Round(Rnd * 10, 0))
Sheets("example_form (2)").Name = newSheetName
' MsgBox ("Please rename the " + newSheetName + " Sheet")
End Sub

Having slow SSH logins to Ubuntu 8.04 Hardy Heron? Plus general SSH security tips…

Was getting really frustrated with the pregnant pause between entering my username and getting the password prompt on logins to my Ubuntu server. Turns out it waiting whilst it attempts to look up the client’s machine name. To fix (as per http://ubuntuforums.org/showthread.php?t=574818&page=2) add a UseDNS no to /etc/ssh/sshd_config. Whilst you are in /etc/ssh/sshd_config you might want to add/uncomment the following line:

AllowUsers username anotheruser user3

This will only allow the specified users access to login over SSH.

Additionally installing DenyHosts is a good idea (particularly if you have SSH open to the wider internet) as it will block IPs from attempting to brute force their way in – and stops them filling up the logs in the process). You can install Denyhosts easily via a Ubuntu package (eg sudo apt-get install denyhosts).

Initially the pause got me worried that my machine might have been compromised – so I installed and ran chkrootkit which checks for evidence of rootkits on a system. Again easy to install via apt-get on Ubuntu.

Quick fix for Olympus Exif problem in Gallery2 (Apr 08)

A friend of mine was having issues uploading images to my photo gallery software (that uses Gallery2). Turned out that for some reason it didn’t like images taken with Olympus cameras (the exif data).

The error was along the lines of unable to allocate memory xxx <webserver dir> /gallery/modules/exif/lib/exifer/makers/olympus.inc on line 155

Anyway the quick fix that worked for me (as at time of writing I am struggling to upgrade to the latest version of Gallery) is to remove a zero from the line 154 (the line above the error) so that L154 and 155 now read:

if($v==0 && $bytesofdata < 10000000) {
$data = fread($seek, $bytesofdata);

Just thought I’d throw this up in case it helps anyone (as I didn’t see a fix listed anywhere) as its pretty obscure. I’d recommend if you can upgrade your Gallery install then do!

Jan 2007 notes:

Found a great article I bookmarked ages ago – talking about Google Adwords switching from MySQL to Oracle – as it was viewed as “a real database”.

Tips on MySQL, PostgreSQL and Word VBA-ODBC

Using Word with PostgreSQL

If you are getting “Data source not found” or “Word cannot open data source” errors when trying to connect to postgres from Word (97) then try the following macro VBA code (the InsertDatabase Method).

Sub insertpgquery()

‘ insertpgquery Macro
‘ Macro recorded 21/08/02 by Oliver Cronk

Selection.Range.InsertDatabase Format:=0, Style:=0, LinkToSource:=False, _
Connection:= _
“DSN=dsnname; ” _
, SQLStatement:= _
“SELECT * FROM table” _
& “”, PasswordDocument:=””, PasswordTemplate:=””, WritePasswordDocument _
:=””, WritePasswordTemplate:=””, DataSource:=””, From:=-1, To:=-1, _
IncludeFields:=True
End Sub

MAKE SURE THAT YOUR SQL QUERY IS VALID OTHERWISE THE DATA SOURCE WILL FAIL!

This had me tied up in knots for ages so I hope that this helps.

Getting PERL DBI to work with PostgreSQL (DBD/DBI:Pg):

Try the following DBI connection string (not very well documented) if you are getting connection errors:

DBI->connect(“dbi:Pg:dbname=databasename;host=hostname”,
username, password, {RaiseError => 1, AutoCommit => 1})
or die “Cannot connect”;

As trying to use the MySQL style connection string will not work!! So much for DBI Database Independence!! Once the connection is established the database will work in pretty much the same way as MySQL – except:

Execute will fail if data is truncated
Execute will fail if referential integrity would be comprised.

Other things I might write about when I get a sec: – Connecting Access to MySQL via ODBC.
– Review of MySQL 4/5 maybe a discussion on MySQL GPL vs MySQL Network/Enterprise

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.