fredag 25. november 2011

terminal not recognizing the Enter/Esc key? Imitate them in vim

Bind a key mapping for the program you are using, for instance in VIM:
(in the .vimrc file if you want it to stay this way):
:imap qq <Esc> and :imap @@ <Enter> where good mappings for me. You have to type two q's very quick to imitate the Esc-key while in insert mode, and the same for the @-key. Both are close to the key they represent. you can, ofcourse change the keys if you want - just replace them with something else, like :imap cornflower <Esc>, and everytime you type cornflower...

fredag 18. november 2011

How to stream audio from VLC through AirPlay


I have a setup where my stereo speakers are connected to an Airport Express. This way I can listen to music from my iPhone and my Mac without switching cables. Problem is, however - the airPlay service only works easily with apple-made software so far, but making it work for VLC is actually very simple.

Update your VLC version
I tried this using vlc 1.0.2 and the codec we need to use to stream the audio wasn't recognised by vlc, so I upgraded to 1.1.12.

Edit VLC settings
Go into Preferences, select "all" to view all the avaliable controls and navigate to Stream output and edit the Default stream output chain to contain something like this: #duplicate{dst="transcode{acodec=alac,channels=2,samplerate=44100}:raop{host=10.0.1.1,volume=175}",dst=display{no-audio,delay=3500}}

this will display a movie on the computer screen while sending audio through airPlay.
Edit the IP-adress after "host=" to match the IP of your airplay-device, and edit the delay so that the video matches the audio. For my setup, 3500 is perfect, but it might not be enough or be too much for your network. tweak it until perfection :)

torsdag 17. november 2011

Why the voice search feature is meant for Google

If you've used android earlier, you might have opted-out of sending usage statistics to improve googles services. Have you ever thought about how important the user data is to the improvement of recognition and usage-related programs? Take speech recognition, for example. The technology has existed for ages, but only recently have they been useful. Thousands of voice samples are needed to sucessfully recognise voice from so many different people. Let's say you want a recipe for baked cucumber in honey sauce, and you find the speech search interesting. Since you have a strong accent, Google thinks you're asking for something completely different, cinema shows in Bangladore next Tuesday. If you then correct the recognised sentence in google and hit search, it is registered as user statistics and is used to improve their speech recognition-programme to compete with other software companies delivering similar software. And all the time we thought google did this for us.. :)

 I have no sources for this post, everything is my own scandalous conspiracy.

søndag 2. oktober 2011

Filter Annoying emails in gmail

Do you recieve lots of emails wanting you to take a super-quick survey that you never care about?
This is how to solve it, and it's easy: (replace "Spørreundersøkelse" with "Survey", or to mark all newsletters as read, replace with "Unsubscribe". I've done both! )




mandag 19. september 2011

VIM hacks: quick tips for coding in VIM

Initial setup for a programming environment inside VIM
I prefer having line numbers and syntax highlighting in my code. to get this, you simply write :syntax on for syntax highlighting and :set nu for line numbers. Turning them off would be :syntax off and :set nu! .
both (or all, really) commands in vim can be set to automatically run when you start vim, by writing them in the /home/$USER/.vimrc file, one command each line.

Using vim for programming
Note: every command must be issued in command mode, not insert mode where you enter text. get to command mode by hitting <Esc>.
Highlighting
Hover over a parenthesis or a brace and hit % to find the matching paren or brace.
Hover over any word and hit * to highlight all words that match the current word.
Remove hightlights by typing ":nohl" (no highlight)


Search/Replace
searching is done by using the s-command, and works like this:
:<from>,<to>s/searchpattern/replacepattern/g where from and to are line numbers and the optional /g replaces all occurences on the same line if there are more than one. without /g the first occurence is replaced.

- Example unrelated to programming: 
Search patterns are powerful. By using regular expressions, the user can do all sorts of things with the search/replace function in vim. For instance, say you have a text file listing 100 mp3-files in the following format:
artist_song.mp3
You want the lines to look better, and you issue this search and replace-command:
:1,100s/\(.*\)_\(.*\).mp3/\2, by \1
and you get the result:
song, by artist

A few quick life-saving commands:
G=gg Auto-indent the whole document
:v/./d  Remove all blank lines in the document
u        undo
:!        execute external program. e.g: ":!gcc this.c"
:sh     open a shell, return to vim by pressing <Ctrl>+d


Reference:
http://www.brezeale.com/technical_notes/vim_notes.shtml

VIM hacks: code completion


Code completion is one of the features I use the most in vim, and makes the task of writing a for-loop as easy as writing "for" and hitting <Tab>. it writes out html-tags for me and writes the main method automatically. 
This is not built-in, so you have to fetch the snipMate-plugin from vim.org here: http://www.vim.org/scripts/script.php?script_id=2540.

Installation:
  1. Unzip it into your /home/$USER/.vim/ -directory
  2. Open your /home/$USER/.vimrc-file and add ":filetype plugin on" on a separate line.
Now, depending on what your files end with, you get completion for a lot of tags and snippets! Try creating a .html-file and write "html" and press<Tab>, or even better - "head" and <Tab>.


VIM hacks: window management

Opening more windows and navigating between them inside vim is easy, it all just takes a bit of getting used to. Here are the commands we use for creation/navigation and movement:
open a new window with a new or existing file inside vim:
(everything in command mode, <Esc> to get there.)
:new filename.html
Move the window left/right:
<Ctrl>+w H (left) / <Ctrl>+w L (right)
Navigate between the windows:
<Ctrl>+w h (left) / <Ctrl>+w l (right) / <Ctrl>+w j (down) / <Ctrl>+w k (up)
Exiting a window?
- it's just like any other file: :q to quit without saving, :wq to write the changes, then quit.
Resizing windows (applies to current window):

  • <Ctrl>+w + (more height)
  • <Ctrl>+w - (less height)
  • <Ctrl>+w > (increase width) 
  • <Ctrl>+w < (decrease width)

Like all commands in vim, it can be multiplied by putting a number before the last symbol (e.g <Ctrl>+w 5< would decrease the width five times the default value).


These are some of the commands I find most important, for more visit http://vimdoc.sourceforge.net/htmldoc/windows.html#window-resize