Twitter Updates

Tuesday, 28 April 2009

Displaying code Snippets on blogspot

I have been trying to show pretty code snippets on blogspot.com/blogger.com. I found for larger files github.com displays code nicely but not very handy for short inline examples. Today I discovered prettify by google



This post describes setting up code.google prettify on blogger.com



Originally explained here:
http://lukabloga.blogspot.com



Include this before the head tag in the blogger template.



I have made a modified version of the css file suitable for displaying code on darkbackgrounds, I use this instead:





Then change the body tag to:



Then use the prettyprint class when using pre tags around code:



Monday, 27 April 2009

Scite bash script config

in Scite the config for bash/shell scripts are handled by the perl.properties by default.

I believe this is the section of the config file which applies it to .sh file by default.
file.patterns.perl=*.pl;*.pm;*.cgi;*.pod
file.patterns.bash=*.sh;*.bsh;configure

shbang.perl=pl
shbang.sh=sh

filter.perl=Perl (pl pm)|$(file.patterns.perl)|
filter.bash=Bash (sh bsh)|$(file.patterns.bash)|

lexer.$(file.patterns.perl)=perl
lexer.$(file.patterns.bash)=bash

Ruby Shoes, Get full path of current application

After reading this post [1] I though that [2] would return the full path, as the url suggest it is only a relative path. For Ruby scripts executing under Shoes the current dir can change so it is always best to refer to a full path. The short script at [3] should give just that.

[1] http://stackoverflow.com/questions/757455/relative-file-paths
[2] File.dirname($PROGRAM_NAME)

[3]:
def getFullPath
modulepath = File.expand_path($PROGRAM_NAME)
modulepath = $modulepath.gsub($PROGRAM_NAME,"")
return modulepath
end

Friday, 24 April 2009

Create new Repository on Github

github.com repositories are setup through the web page:
http://github.com/repositories/new

Which then forwrds you to these instructions (some of which can been done before setting up the repo):

Global setup:

Download and install Git
git config --global user.name "Registerd githubname"
git config --global user.email yourgithub@emailaddress.com

Next steps:

mkdir shoesexamples
cd shoesexamples
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@github.com:git_hub_username/shoesexamples.git
git push origin master

Existing Git Repo?

cd existing_git_repo
git remote add origin git@github.com:git_hub_username/shoesexamples.git
git push origin master

Google Apps to host your Domain mail server

A mini howto forward you domain emails to google and get a gmail interface for your emails using use google apps.

Register at http://www.google.com/apps/
The standard edition is free and can have upto 50 users.

Now Configure Mail
https://www.google.com/a/cpanel/yourdomain.com/Dashboard
click "Activate Mail"

Follow Instructions for setting MX records
which are :
Priority Address TTL
1 aspmx.l.google.com 1week
5 alt1.aspmx.l.google.com 1week
5 alt2.aspmx.l.google.com 1week
10 aspmx2.googlemail.com 1week
10 aspmx3.googlemail.com 1week

The login page should be:
https://mail.google.com/a/yourdomain.com
or you can set up mail.yourdomain.com [instructions]

https://www.google.com/a/cpanel/yourdomain.com/DomainSettingsDomains
select "Service Settings" -> "Email"
Tell google what you want the domain to be.
Update your dns records by adding a cname with alias mail (should match the google setup), points to host name should be ghs.google.com ttl 1 week

It may take a few hours for google and world wide dns caches to update making it functional, just wait a and and at some point your new mail.yourdomain.com should spring to life.

Thursday, 23 April 2009

New file and directory permissions on unix

Unix and Linux based sytems define default file permissions with umask.
$ man umask

To see you current permissions just run:
$ umask
>0022


For a more user friendly format:
$ umask -S
>u=rwx,g=rx,o=rx

Person is User, Group and Other.
Properties are Read, Write and eXecute.

umask subtracts from the normal properties set by chmod.
Folder and file are the same, except files will never be set executable by default.
(the -- are just to allign the tables, the numbers are the decimal equivalent for a 1 set in that position)
--421,--421,--421
u=rwx,g=rwx,o=rwx


Say you (User) want full access to a file but not allow Group or Other access.
you want:
--421,--000,-000 ie 700
The mask would be
--000,--421,--421 => 077
to set this just run (and may be add to your ~/.bashrc file) :
$ umask 077

You (User) want full access, Group has read and execute and Other none
--421,--401,--000 ie 750
the mask would be:
--000,--020,--421 => $ umask 027

You (User) have full access and Group and other have read and execute.
--421,--401,--401 ie 755
mask would be:
--000,--020,--020 => $ umask 022

NB:
Q) How do i set umask to make files executable by default?
A) You can not create exectuable file by default using umask, it is thought to be a security issue.

Perl Variables

#Perl comments use #hash

Some general perl variables:
$scalar = 1 ; #String, integers, floats
print $scalar ;

@array = ("apple", "pair");
print $array[0];
print $array[1];

%hash = ();
$hash{"apple"} = 100;
$hash{"pair"} = 200;
print "Cost is $hash{"apple"} \n";

Perl shebang

The first (shebang) line of perl scripts should be:
#!/usr/bin/perl -w

Wednesday, 15 April 2009

Ruby decimal / frational to binary conversion

The following function can be used to convert decimal (fractional) numbers to binary format:

def dec2bin(number, int_bits, frac_bits, decimal_mark)
negative = false
if (number < 0)
negative = true
number = -number
end

## Create Integer only number
number_int = Integer(number);

## Create Fractional only number
number_frac = number - number_int;

## Create Integer Binary String
ret_bin_int = "";

## Create Fractional Binary String
ret_bin_frac = "";

##Integer
ret_bin_int = number_int.to_s(2) ;
padding_bits = int_bits - ret_bin_int.length ;
begin
ret_bin_int = Array.new(padding_bits, "0").join + ret_bin_int ;
rescue
puts "ERROR not enough integer bits to represent #{number}";
return -1;
end

## Fractional
ret_bin_frac = ""
fractional = 0
if (frac_bits > 0)
ret_bin_frac = Integer(number_frac * 2**frac_bits).to_s(2);
padding_bits = frac_bits - ret_bin_frac.length ;
ret_bin_frac = Array.new(padding_bits, "0").join + ret_bin_frac ;
fractional = ret_bin_frac.to_i(2).to_f / (2**frac_bits)
end

if (negative == true)
number = (ret_bin_int + ret_bin_frac).to_i(2)
#Perforrm this binary operation number = -number + 1
#In an integer number space
number = 2**(int_bits+frac_bits) - number
ret_bin_int = number.to_s(2)[0,int_bits]
ret_bin_frac = number.to_s(2)[int_bits, frac_bits]
end

binary = ret_bin_int + decimal_mark + ret_bin_frac;

## ret_bin Add decimal marker
return {
:binary => binary,
:int => number_int,
:frac => fractional,
:real => (fractional+number_int)
}
end


Example using the function:
intBits = 6
fracBits =4
converted = dec2bin(10.5, intBits, fracBits, "_")
puts converted[:binary]


NOTE:
Since first post I have fixed a fracbits=0 bug and now works with negative numbers (converting to a twos complement format)

Monday, 13 April 2009

module load fail when scripted

The following works on the command line
[1]$ module load something
but fails with [2] when used in make, bash, etc script files:
[2]> module: command not found

This is because the module enviroment has not been loaded, as it is for a normal user session.
Try using some thing similar to this before your module load call:
#!/bin/bash

. /usr/share/modules/init/bash
module load something

Friday, 10 April 2009

Scite sensible open action

I use the text editor scite which has a SciTEGlobal.properties file which defines the behaviour. I just found out about this option:

open.dialog.in.file.directory=1

When pressing open it forces Scite to start the open file dialog box in the folder of the currently active file.

Thursday, 9 April 2009

Java duplicate class error

I recently created a new class and when trying to compile my new code I got this error (below) and it took some time to figure out what the duplicate class error meant.

[javac] N:\morgan\utils\FileExplorer\src\fileexplorer\TransferListItem.java: 5: duplicate class: TransferListItem
[javac] public class TransferListItem extends JPanel {

The problem was that I had missed the package decleration at the start of the file.
so by adding "package fileexplorer;" on line 1 the error went away and the code started compiling again.

Saturday, 4 April 2009

Java loading Jar Resources

When moving from running java programs from a directory to running from inside a jar file, I ran into trouble with loading images.

I use to do the following :

fileIconLocation = "toolbarButtonGraphics/general/Edit16.gif";

//http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html
/** Returns an ImageIcon, or null if the path was invalid. */
protected ImageIcon createImageIcon(String path, String description) {
java.net.URL imgURL = getClass().getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + imgURL.toString());
return null;
}
}


Once inside the Jar it can not find the file and always returns null.
Replacing getClass() with getClass().getClassLoader() seems to fix the problem.


protected ImageIcon createImageIcon(String path, String description) {
java.net.URL imgURL = getClass().getClassLoader().getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL, description);
} else {
System.err.println("Couldn't find file: " + imgURL.toString());
return null;
}
}

Thursday, 2 April 2009

Adobe Lightroom 2.3 Updates

Adobe has released the third update to Lightroom 2. The updates can be downloaded from Adobe directly, and no need to dig out the serial number again as they do not require revalidation.

Adobe Lightroom 2.1 Update
Adobe Lightroom 2.2 Update
Adobe Lightroom 2.3 Update
NB: update 27/06/2009
Adobe Lightroom 2.4 Update