Twitter Updates
Friday, 14 May 2010
So long and thanks for all the fish
I have not made many posts for a while on this blog. Out of frustration with posting code samples and interest of writing sinatra web applications I have setup on webfaction please view http://lizard-spock.co.uk from now on my new posts will be here.
Also my sourceforge/opensource projects will be moved here.
Update: software projects no longer available
Tuesday, 23 March 2010
Wednesday, 17 March 2010
GIT setup on webfaction
git is a popular revision control system which allow users to make local commits to capture their work in progress before it is pushed to the central repository. Most webfaction servers do not currently have git installed so you will have to compile it your self fairly trivial if you follow the instructions.
The intended work-flow is to keep committing local changes while you work on you r website and when you are happy with it you push to a secure git repo. Then make your webapp pull from the central secure repo.
Now local stuff to connect it
You will see this error
This is because of an oddity in the way the .bash_profile and .bashrc are setup.
ssh only loads the .bash_profile.
.bash_profile
.bashrc
NB: The following may be added so you can use the 'git push' shortcut (it actually runs git push origin master).
Based on http://devioustree.co.uk/2009/07/23/setting-up-git-on-webfaction/
and http://docs.webfaction.com/software/git.html
The intended work-flow is to keep committing local changes while you work on you r website and when you are happy with it you push to a secure git repo. Then make your webapp pull from the central secure repo.
$ shh username@username.webfaction.com
$ cd ./bin
#//Check out the latest version, currently it is 1.7.0.2
$ wget http://kernel.org/pub/software/scm/git/git-1.7.0.2.tar.gz
$ tar zxf git-1.7.0.2.tar.gz
$ cd git-1.7.0.2
$ ./configure --prefix=$HOME && make && make install
#//Clean up the original stuff leaving the compiled binaries in ~/bin
$ cd ~/bin
$ rm -rf git-1.7.0.2*
#//This bring the total from 80MBs down to 14MBs
$ mkdir ~/repo/projectname.git
$ cd ~/repo/projectname.git
$ git --bare init
Now local stuff to connect it
$ cd /path/to/your/local/repository/
$ git init #Assumes it is not already a git repo
$ touch README.md
$ git add README.md
$ git commit -a -m '*Added README.md'
#//Now try to connect to server, will request your ssh password or not if you have key based ssh auth setup
$ git push ssh://user@user.webfactional.com/~/repo/projectname.git
You will see this error
$ bash: git-receive-pack: command not found
$ fatal: The remote end hung up unexpectedly
This is because of an oddity in the way the .bash_profile and .bashrc are setup.
ssh only loads the .bash_profile.
.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
## MOVE THIS TO .bashrc THENthey Will both be the same
# User specific environment and startup programs
#PATH=$PATH:$HOME/bin
#export PATH
.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
# User specific aliases and functions
NB: The following may be added so you can use the 'git push' shortcut (it actually runs git push origin master).
$ git remote add origin ssh://user@server-ip-or-address/~/repo/projectname.git
$ git push origin master
$ git push
Based on http://devioustree.co.uk/2009/07/23/setting-up-git-on-webfaction/
and http://docs.webfaction.com/software/git.html
Webfaction and google apps
First register (for free) with standrad google apps
Create the random subdomain (under domains) that google gives you.
Then under DNS overides choose the new subdomain and complete the CNAME record to be google.com
Check that this has taken affect. when you press the I have done this button google then checks. If you hae not done this it will assume that you do not own the domain and not allow you to continue.
For easy access to your mailbox, create a new subdomain (under domains) mail.yourdomain.com. Then under DNS overides set the CNAME to ghs.google.com
Then under domains for yourdomain.com create these MX records
Create the random subdomain (under domains) that google gives you.
Then under DNS overides choose the new subdomain and complete the CNAME record to be google.com
Check that this has taken affect. when you press the I have done this button google then checks. If you hae not done this it will assume that you do not own the domain and not allow you to continue.
For easy access to your mailbox, create a new subdomain (under domains) mail.yourdomain.com. Then under DNS overides set the CNAME to ghs.google.com
Then under domains for yourdomain.com create these MX records
Domain Priority
ASPMX5.GOOGLEMAIL.COM 30
ASPMX4.GOOGLEMAIL.COM 30
ASPMX3.GOOGLEMAIL.COM 30
ASPMX2.GOOGLEMAIL.COM 30
ALT2.ASPMX.L.GOOGLE.COM 20
ALT1.ASPMX.L.GOOGLE.COM 20
ASPMX.L.GOOGLE.COM 10
Sunday, 14 March 2010
Setting Up on WebFaction
WebFaction is quite popular among the Python and Django community, recently it has simplified Rails and other Ruby web frameworks.
Unlike other Web hosts they do not bundle a domain name, but these can be bought quite cheaply from www.gandi.net. I would then forward the MX records to google and get a gmail handler for your mail. You do not have to get a domain straight away by default you can use username.webfactional.com
First I had to install Passenger (I think this is also called Rack), I set the name to passenger.
This means that if you ssh/sftp/ftp into your account you will see ~/webapps/passenger/
Then I entered the Websites section then created a new subdomain devel.username.webfactional.com and set this to be type:passenger location:/
I had to wait sometime before these setting became active.
There article can then be followed for setting up a basic Sinatra over passenger (Rack).
NB: for a sinatra app you only need to install Passenger (not rails) and gem install sinatra (plus sequel / activerecord etc).
Unlike other Web hosts they do not bundle a domain name, but these can be bought quite cheaply from www.gandi.net. I would then forward the MX records to google and get a gmail handler for your mail. You do not have to get a domain straight away by default you can use username.webfactional.com
First I had to install Passenger (I think this is also called Rack), I set the name to passenger.
This means that if you ssh/sftp/ftp into your account you will see ~/webapps/passenger/
Then I entered the Websites section then created a new subdomain devel.username.webfactional.com and set this to be type:passenger location:/
I had to wait sometime before these setting became active.
There article can then be followed for setting up a basic Sinatra over passenger (Rack).
NB: for a sinatra app you only need to install Passenger (not rails) and gem install sinatra (plus sequel / activerecord etc).
Saturday, 13 March 2010
Sinatra set_cookie started failing
I recently started getting this error [1] in my Sinatra web application (after upgrading from 0.9.4 to 0.9.6)
Basically instead of
Source gitr
[1] undefined method `set_cookie' for
Basically instead of
set_cookie("foo", "bar")We now have to use:
response.set_cookie("foo", "bar")
Source gitr
Thursday, 11 March 2010
VIM and whitespace
To view white space characters (except spaces)
To stop tab insertion and uses spaces
To set all types of tabs to 3 spaces
Further Info vimcasts.org 2
:set list
To stop tab insertion and uses spaces
set expandtab
To set all types of tabs to 3 spaces
set tabstop=3
set softtabstop=3
set shiftwidth=3
Further Info vimcasts.org 2
Tuesday, 9 March 2010
RubyGem version error: activesupport(1.4.4 not = 2.3.2)
I have been getting this error [1] when trying to set up a ORM lesson for ActiveRecord. Specifically trying to use active record inside of a Rake file.
[1]RubyGem version error: activesupport(1.4.4 not = 2.3.2)
activesupport 2.3.5 does seem to be present. but it was fixed by running:
$ gem install activesupport
[1]RubyGem version error: activesupport(1.4.4 not = 2.3.2)
$ gem list
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (2.3.5)
actionpack (2.3.5)
activerecord (2.3.5)
activeresource (2.3.5)
activesupport (2.3.5)
acts_as_taggable (2.0.2)
compass (0.8.17)
erubis (2.6.5)
feed-normalizer (1.5.1)
haml (2.2.17)
hoe (2.3.3)
maruku (0.6.0)
mbleigh-acts-as-taggable-on (1.0.5)
mysqlplus (0.1.1)
ncurses (0.9.1)
rack (1.0.1)
rails (2.3.5)
rake (0.8.7)
rubyforge (1.0.4)
sequel (3.8.0, 3.7.0)
simple-rss (1.2)
sinatra (0.9.4)
sqlite3-ruby (1.2.5)
syntax (1.0.0)
activesupport 2.3.5 does seem to be present. but it was fixed by running:
$ gem install activesupport
Sunday, 28 February 2010
HTML CSS id vs class
Working on some websites again, been away from HTML and CSS for a while and having to remind myself the difference between ids and class's.
id is for unique elements on a page. There should only ever be one of each id on a page.
class is for many elements which you want to apply a custom style
CSS for id:
CSS for class:
Original Source :
http://www.tizag.com/cssT/cssid.php
id is for unique elements on a page. There should only ever be one of each id on a page.
< d i v id="navigation">< / d i v>
class is for many elements which you want to apply a custom style
< p r e id="prettyprint">Code1< / p r e>
< p r e id="prettyprint">Code2< / p r e>
CSS for id:
div#navigation {background-color: white;}
CSS for class:
div.prettyprint {background-color: white;}
Original Source :
http://www.tizag.com/cssT/cssid.php
Wednesday, 24 February 2010
Disable Visio Auto Connect
I think it was in Visio 2007 a new feature called auto connect was added which adds blue triangles on the side of visio objects (Shown in image below) and if pressed will auto connect to some other object/shape. This can get quite furstrating as they are very easy to accidentally click.
To switch off this feature choose:
Visio -> Tools -> Options -> General Tab
Deselect the 'Enable AutoConnect' option
To switch off this feature choose:
Visio -> Tools -> Options -> General Tab
Deselect the 'Enable AutoConnect' option
Tuesday, 23 February 2010
.vimrc tweaks
Improving the Status line in Vim, get current file, directory, position etc.
~/.vimrc
~/.vimrc
"Setup the Status line
set showcmd " shows the command in the status line
set ch=2 " make command line 2 lines high
set ls=2 " status line always on
set statusline %<%f\ %h%m%r%=%{getcwd()}\ \ \ %-14.(%l,%c%V%)\ %P
Wednesday, 10 February 2010
Java right click menu example
I have just setup a new github project for java examples first source file is the basic structure of a right click menu.
PopupMenu.java
PopupMenu.java
Saturday, 6 February 2010
Sinartra limit blog posts displayed on a page
To limit the number of database elements returned in ActiveRecord is trivial but there is a little bit of work involved with getting the links setup to jump forward and backwards.
I have decided to use these [1,2,3] URLs to navigate the list of blog posts
[1] /blog : always the latest
[2] /blog/older : The next page of blog posts
[3] /blog/older/integer : a page of blog posts starting at integer the links provided will increment this by a fixed amount, but the route can accept any value.
NB: as allways I have inserted some extra space in to the code to get it to display rather than render, you may have to delete spaces after <.
My app.rb:
The views/blog/all.erb
I have decided to use these [1,2,3] URLs to navigate the list of blog posts
[1] /blog : always the latest
[2] /blog/older : The next page of blog posts
[3] /blog/older/integer : a page of blog posts starting at integer the links provided will increment this by a fixed amount, but the route can accept any value.
NB: as allways I have inserted some extra space in to the code to get it to display rather than render, you may have to delete spaces after <.
My app.rb:
require 'rubygems'
require 'sinatra'
require 'active_record'
$blogpath = "blog"
$blogs_per_page = 10
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => './db/blog.db'
)
class Posts < ActiveRecord::Base
end
get '/blog/?' do
@offset = 0
@posts = Posts.find(:all, :order => "id DESC", :limit => $blogs_per_page)
erb :'blog/all'
end
get '/blog/older/?' do
#This probably should be a redirect to /blog/older/$blogs_per_page
@offset = $blogs_per_page
@posts = Posts.find(:all, :order => "id DESC", :limit => $blogs_per_page, :offset => @offset)
erb :'blog/all'
end
get '/blog/older/:offset/?' do
@offset = params[:offset].to_i
@posts = Posts.find(:all, :order => "id DESC", :limit => $blogs_per_page, :offset => @offset)
erb :'blog/all'
end
The views/blog/all.erb
< %# This section adds control on top %>
< p>
< a href="/<%=$blogpath%>"> latest <%=$blogpath%>< /a>
<% if @offset>($blogs_per_page-1) %>
| < a href="/<%=$blogpath%>/older/<%=@offset-$blogs_per_page%>"> newer <%=$blogpath%>< /a>
<%end%>
| < a href="/<%=$blogpath%>/older/<%=@offset+$blogs_per_page%>"> older <%=$blogpath%>< /a>
< /p>
<%# This section lists all the Posts passed to it %>
<% for post in @posts %>
< h2>< a href="/<%=$blogpath%>/<%=post.id%>"> <%= post.title %>< /a>< /h2>
< p><%=post.body%>< /p>
<% end %>
Hyperlink to submit html forms
Some times you need a hyperlink to submit hidden form data. Example taken from javascript-coder.
This is a suggestion from VelocityReviews, just change the look of the button:
I ended up using a hyperlink to an URL that could then be intelligently parsed in my sinatra route, I would have had to have seperate get and post routes any way if I wantyed to stop the form appending ?lots=of&variab=les to the URL.
< form name="myform" action="handle-data.php">
Search: < input type='text' name='query' />
< a href ="javascript: submitform()">Search< / a>
< / form>
< script type="text/javascript">
function submitform()
{
document.myform.submit();
}
< / script>
This is a suggestion from VelocityReviews, just change the look of the button:
< input type="submit" value="Submit" style="Border: none; background: none">
I ended up using a hyperlink to an URL that could then be intelligently parsed in my sinatra route, I would have had to have seperate get and post routes any way if I wantyed to stop the form appending ?lots=of&variab=les to the URL.
Friday, 5 February 2010
Sinatra layouts vs templates
I must have missed this on my first pass of the Sinatra (sinatrarb) book. There is a very nice way to create a site template, called a layout.
Just create a file in views called layout.erb (or layout.haml if using haml) output yield where you want the body of the templates to be inserted. Class @variables can also be used.
This allows the basic layout of your site Headers, Footers and navigation panes to be controlled independently, a change in layout.erb is instantly applied across your whole site.
layout.erb
you app.rb (NB: no refference to layour.erb is made)
/views/about.erb
Just create a file in views called layout.erb (or layout.haml if using haml) output yield where you want the body of the templates to be inserted. Class @variables can also be used.
This allows the basic layout of your site Headers, Footers and navigation panes to be controlled independently, a change in layout.erb is instantly applied across your whole site.
layout.erb
< h t m l>
< h e a d>
< t i t l e><%= @title %>< / t i t l e>
< / h e a d>
< b o d y>
<%= yield %>
< / b o d y>
< / h t m l>
you app.rb (NB: no refference to layour.erb is made)
get '/about/?' do
@title = "About"
erb :about
end
/views/about.erb
Example about page
Sunday, 31 January 2010
SASS with Sinatra
Have started looking onto how to use use stylesheets with Sinatra. The easiest way way is to have a top level folder called Public with your main.css file.
This can be referenced from all pages as
Standard stylesheets have no have variables, they say they do but I could not get them to work. So I have started to look at compass which is a framwork for CSS! it based on haml which is another templating language like erb.
The Main Compass page. Integrating it with Sinatra.
Also see github for a basic example of using Sinatra and Compass.
Example of some SASS:
Compass uses SASS and is built on the blueprint layout system.
Blueprint Tutorials.
This can be referenced from all pages as
< h t m l>
< h e a d>
< t i t l e> example < / t i t l e>
< l i n k href="/main.css" rel="stylesheet" type="text/css" />
< / h e a d>
Standard stylesheets have no have variables, they say they do but I could not get them to work. So I have started to look at compass which is a framwork for CSS! it based on haml which is another templating language like erb.
The Main Compass page. Integrating it with Sinatra.
Also see github for a basic example of using Sinatra and Compass.
Example of some SASS:
!cdark = rgb(145, 129, 107)
!cdarker = rgb(125, 91, 95)
!clight = rgb(141, 189, 168)
!clighter = rgb(23 , 206, 143)
body
background-color: #{!cdark}
p
color: #{!clight}
Compass uses SASS and is built on the blueprint layout system.
Blueprint Tutorials.
Saturday, 23 January 2010
Java and Ant setup on Windows XP
Setting up a Windows XP machine for creating/testing java builds. These programs are required:
Java JDK
ant, for more automated builds (like make and rake)
JSmooth, creates .exe from jar files.
Zip Genius, for unpacking the .tar.gz source files.
Download and install the Java SDK.
Download ant, put contnets of .zip in C:/Program Files/ant/
Now go to Control Panel -> System -> Advanced tab and press the set Environment Variables
Create these two new variables
Edit Path to include ant bin and java JDK bin,
C:\Program Files\ant\apache-ant-1.8.0RC1\bin;C:\Program Files\Java\jdk1.6.0_18\bin;
JSmooth and zip Genius should download and install like standard windows programs
NB: I Kept getting this error when trying to run ant
> ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li
b\tools.jar
JAVA_HOME does not point to the bin folder but the folder above 'C:\Program Files\Java\jdk1.6.0_18' quotes not to be included.
Java JDK
ant, for more automated builds (like make and rake)
JSmooth, creates .exe from jar files.
Zip Genius, for unpacking the .tar.gz source files.
Download and install the Java SDK.
Download ant, put contnets of .zip in C:/Program Files/ant/
Now go to Control Panel -> System -> Advanced tab and press the set Environment Variables
Create these two new variables
Variables | Value |
JAVA_HOME | C:\Program Files\Java\jdk1.6.0_18 |
ANT_HOME | C:\Program Files\ant\apache-ant-1.8.0RC1 |
Edit Path to include ant bin and java JDK bin,
C:\Program Files\ant\apache-ant-1.8.0RC1\bin;C:\Program Files\Java\jdk1.6.0_18\bin;
JSmooth and zip Genius should download and install like standard windows programs
NB: I Kept getting this error when trying to run ant
> ant
Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre6\li
b\tools.jar
JAVA_HOME does not point to the bin folder but the folder above 'C:\Program Files\Java\jdk1.6.0_18' quotes not to be included.
VMware Fusion Disk Usage
The disk images for the operating systems are sparse, i.e. they expand as necessary. They unfortunately do not shrink automatically when you delete data.
For a windows image you have to install the VMware tools to shrink the disk.
VMware guide
http://www.vmware.com/support/ws5/doc/ws_disk_shrink.html
The VMware Tools are installed by: Start your virtual Operating system -> Move mouse to the top of the screen and select 'Virtual Machine' -> 'Install VMware Tools'
VMware Tools location
C:\Program Files\VMware\VMware Tools\VMwareControlPanel
For a windows image you have to install the VMware tools to shrink the disk.
VMware guide
http://www.vmware.com/support/ws5/doc/ws_disk_shrink.html
The VMware Tools are installed by: Start your virtual Operating system -> Move mouse to the top of the screen and select 'Virtual Machine' -> 'Install VMware Tools'
VMware Tools location
C:\Program Files\VMware\VMware Tools\VMwareControlPanel
Labels:
Boot,
Filesystem,
Leopard,
Linux,
Mac,
Microsoft,
Networking,
OS X,
Snow Leopard,
Storage,
Windows XP
Thursday, 21 January 2010
Java String Search and Replace
Java by default by default only searches for regular expressions and replaces with strings. The method below allows String search and string replace.
Why is regular expression search an issue ? if search for [ex] it will match 'e' and 'x' but not '[ex]' if you have control over thestring you could excape the special characters with '\[ex\]' but if you are loading from a config file and you know it is plain text then it would be nice if there was a simple search and replace function example supplied below:
Why is regular expression search an issue ? if search for [ex] it will match 'e' and 'x' but not '[ex]' if you have control over thestring you could excape the special characters with '\[ex\]' but if you are loading from a config file and you know it is plain text then it would be nice if there was a simple search and replace function example supplied below:
public String replaceString(String input, String find, String replace, boolean casesensitive){
String input_case_adjusted = input;
if (casesensitive == false) {
//For Case Insensitive searchs
//Lowercase everything (but replace in the original string)
input_case_adjusted = input.toLowerCase() ;
find = find.toLowerCase() ;
}
int startPosition = input_case_adjusted.indexOf(find);
String start = "";
String end = "";
if (startPosition >= 0) {
if (startPosition > 0) {
start = input.substring(0, startPosition);
}
end = input.substring(startPosition + find.length());
return start + replace + end;
} else {
return input;
}
}
Sunday, 17 January 2010
Java case insensitive regular search and replace
Java's Search and replace function on strings is:
To make this non-case sensitive / case insenitive:
new_string = old_string.replaceFirst(regularExpresionFind, textReplace);
To make this non-case sensitive / case insenitive:
new_string = old_string.replaceFirst("(?i)" + regularExpresionFind, textReplace);
Saturday, 9 January 2010
Audio File Tag Editor
The best MP3 tag editor I can find is Mp3tag (supports most audio files). The feature that I find most useful is its ability to parse the file name and writing it into the tags and vice versa. Unfortunately it is windows only.
Saturday, 2 January 2010
Happy New Year, Have some Tabs
File Explorer (my souceforge project) now has tabbed browsing and right click open folders in new window or new tab.
Subscribe to:
Posts (Atom)