Newspeak

March 19, 2009

How to not appear pretentious when sending email from your iPhone.

Filed under: howto, tech — Stephen Paulger @ 11:24 am

Unless you want everyone to groan and hate receiving email from you follow these simple steps to avoid looking like a pompous ass.

1. Click ‘Settings’.

2. Click ‘Mail, Contacts, Calendars’.

3. Scroll down to ‘Signature’ and click it.

4.  Delete ‘Sent from my iPhone’.

There, now you just need to get some some better in ear headphones that aren’t white and you won’t look like an Apple fan boy.

August 6, 2008

Week 3: Vim tricks - Indenting Code

Filed under: vim — Stephen Paulger @ 9:28 am

For a long time now I have known how to indent using Vim’s ‘>’ command to indent a block of text. I have learnt a few new tricks that might speed me up a bit. (more…)

July 29, 2008

Week 2: Vim tricks - Automatic code completion

Filed under: tech, vim — Stephen Paulger @ 4:20 pm

You may have used an IDE before that allows you to automatically complete parts of your code. In Microsoft’s Visual Studio this is called “intellisense”. It’s very handy for speeding up development and for exploring objects that you can’t quite remember the attributes of. This week I found out how to add it to Vim. (more…)

July 21, 2008

New Vim tricks

Filed under: vim — Stephen Paulger @ 5:05 pm

I’ve been using vim as my main text editor for over 5 years now and because I’m now dependent on it and using it every day at work I’ve decided to challenge myself to learn a new trick every week. Last week’s trick was sorting lines.

Sorting Lines

I actually learnt two new tricks to be able to do this. The first is selecting lines using visual mode.

By placing the cursor on the first line you wish to select then pressing Shift+V and moving the cursor the last line to select you select the range of lines between the two and you can do any of your normal ex commands on just the selected text.

To sort the selected lines type :sort, this runs the sort command and replaces the selection with the result. You notice if you try to sort lines with numbers they will be sorted alphanumerically, ie. 700 would come before 8, if you want to sort numerically use :sort n. You can also remove duplicates from a list by using :sort u, to remove duplicates and sort numerically use :sort un.

March 7, 2008

Optional arguments in Python

Filed under: code, tech — Tags: — Stephen Paulger @ 11:22 am

Optional arguments in python are obviously very useful allowing you to have default values so you don’t need to pass them every time. A simple hello world example always goes a long way…

def hello(to="world"):
    print "Hello,", to
>>> hello("Steve")
Hello, Steve
>>> hello()
Hello, world

Sometimes you’ll see people define an optional argument with a default value of None then override it in the function’s body. This might seem a strange thing to do at first, but there is a reason. Let’s say that we wanted to be able to say hello to a list of people and for it to automatically add “World” to the list.

def hello(to=[]):
    to.append("World")
    if len(to) > 1:
        greeting = "Hello, " + ", ".join(to[:-1]) + " and " + to[-1]
    else:
        greeting = "Hello, " + to[0]
    print greeting
>>> hello(["Steve", "Matt"])
Hello, Steve, Matt and World
>>> hello(["Steve", "Matt"])
Hello, Steve, Matt and World
>>> hello()
Hello, World
>>> hello()
Hello, World and World
>>> hello()
Hello, World, World and World

This happens because the value for the default argument is the same list every time, so when we modify it the function has the same modified list as the default argument when it is subsequently called. This is probably not the behaviour you would expect and you would rarely want to use this behaviour. The way around it is to define the default argument as None then override it.

def hello(to=None):
    to = to or []
    to.append("World")
    if len(to) > 1:
        greeting = "Hello, " + ", ".join(to[:-1]) + " and " + to[-1]
    else:
        greeting = "Hello, " + to[0]
    print greeting

>>> hello()
Hello, World

>>> hello()
Hello, World

>>> hello(["Steve", "Matt"])
Hello, Steve, Matt and World

>>> hello(["Steve", "Matt"])
Hello, Steve, Matt and World

Because None evaluates to false, setting the default value to None means it can be easily overridden to give us the default value we actually want if there wasn’t a passed value.

August 30, 2007

My steps for getting Ubuntu Feisty (7.04) the way I like it.

Filed under: howto, tech — Stephen Paulger @ 10:18 pm

Ubuntu is pretty good out of the box, but personally I need a few more things to make it feel like my computer. Before I start I install w32codecs and libdvdcss2 (on machines with a DVD drive) this allows me such wonders as DVD and MP3 playback.

Audio and Video

I remove

  • Rhythmbox,
  • Serpentine and
  • Totem

and install

  • Amarok,
  • Grip,
  • mplayer and
  • acidrip (on systems with a DVD drive)

sudo apt-get remove rhythmbox serpentine totem totem-gstreamer totem-xine totem-mozilla
sudo apt-get install grip lame amarok mplayer

Firefox

I install

  • Media Connectivity Plugin and point it to mplayer for playback and
  • Adblock Plus and subscribe it to EasyList in order to avoid having to waste my time and bandwidth on adverts.

Then I swap the Google search engine for the Google UK search engine by clicking on the search engine drop down and clicking “Manage Search Engines”. I do the same for the Ebay and Amazon search engines.

Vim

For some bizarre reason Ubuntu comes with a crippled version of Vim that it calls “vim-tiny”. I replace this with vim-full

sudo apt-get remove vim-tiny
sudo apt-get install vim-full

and put the following in my .vimrc

syntax on
set expandtab
set autoindent
set tabstop=4
set shiftwidth=4
set textwidth=78

That way vim works in a way suitable for pretty much everything I use it for as soon as I open it.

Remote Access

If I want to be able access the machine remotely I install sshd then if it’s open to the internet I use iptables to block bruteforce attacks.

If I think of anything else to add here I’ll update this post.

May 11, 2006

Last Exit: Ubuntu Package

Filed under: music, tech — Stephen Paulger @ 3:13 pm

I have packaged last exit with my modification as described in yesterday’s post.

You can just download the package and install it by typing

sudo dpkg -i last-exit_0.2-3_i386.deb or you can add my repository to your sources list and then you’ll automatically get updates when new versions are packaged.

If you want to add my repository open /etc/apt/sources.list in a text editor and add

deb http://www.newspeak.org.uk/repository/ binary/

(note: there is meant to be a space between “…repository/” and “binary/”)

Then type

sudo apt-get update
sudo apt-get install last-exit
last-exit

There are a number of bugs with last exit currently, such as the program segfaulting when you click on the information icon and when you close the program. If you have problems other than those feel free to leave a comment here but please bear in mind that I am not the original software author I have merely packaged it and made a minor alteration.

Older Posts »

Powered by WordPress