Archive

Archive for the ‘linux’ Category

Raspberry Pi for research labs (1)

September 30th, 2013

Raspberry Pi for research labs (3)
Raspberry Pi for research labs (2)

Raspberry Pi is a mini and incredibly cheap PC. The size is like a credit card, and the price is $35. See how small it is compared to my hand.

If you connect Pi with a TV (or monitor), a keyboard, a mouse, an internet cable, a SD card, then it becomes a full fledged PC. Pi is ideal for students to learn computer languages and other educational purposes. But many people are very creative in using Pi as a digital photo frame, a media center, a internet radio station etc. Pi’s performance is like a a 300MHz Pentium 2.

Can Pi be used in human behavior and brain imaging research labs?  Our specific goal is to see if we can integrate Pi in our Near Infrared Spectroscopy (NIRS) research. In this first part of experiment, we will see if we can get Pi running at all as a regular computer.

Joe in our lab and I rush into Fry’s to purchase some items needed to run Pi:

  1. Power adapter. Yes, Pi needs power. The adapter is actually identical to my smartphone (android) charger.
  2. SD card and reader. It is like the hard disc of a regular computer and is where data (including OS) is saved.
  3. HDMI to VGA adapter (to connect to a monitor)
  4. We already have a monitor, a USB mouse, and a USB keyboard.
1. let’s format the SD card and put OS in.
I am using a Windows computer so I follow the following instructions.
  1. Download the SD Association’s Formatting Tool from
    https://www.sdcard.org/downloads/formatter_4/eula_windows/
  2. Install and run the Formatting Tool on your machine
  3. Set “FORMAT SIZE ADJUSTMENT” option to “ON” in the “Options” menu
  4. Check that the SD card you inserted matches the one selected by the Tool
  5. Click the “Format” button
Then download NOOBS software from http://downloads.raspberrypi.org/noobs. It is a zip file, extract it and put the contents to the formatted SD card. Note, put the contents inside NOOBS_v1_3 folder to the SD card, but not the NOOBS_v1_3 folder itself.
2. Connect hardware to Pi.
Plug in the SD card to Pi, connect keyboard and mouse, HDMI to VGA adapter (then to monitor), Ethernet cable, and power adapter. As soon as you connect the power adapter, Pi will start to run. We have an option to select which OS to run, and we selected Raspbian, a version of Linux.
A close view of the hardware connected to Pi.
A far view of Pi and the keyboard/mouse, monitor etc. You can see the big juicy raspberry on the screen.
3. Surfing internet
Looks like it’s ready. Now let’s do something real - surfing internet. I opened Midori (a web browser) and can successfully go to any website I like.
Conclusions:
We successfully set up Raspberry Pi as a computer running Linux. The next step is to see if we can use it for research purpose.
Author: Xu Cui Categories: brain, linux, programming, web Tags:

Amf3Broker error and fix

June 27th, 2009

I encounter this error in an AIR application which uses amfphp for remoting:

The class {Amf3Broker} could not be found under the class path {/var/htdocs/amfphp/services/amfphp/Amf3Broker.php}

I googled and found several links, but their suggestions doesn’t work. I finally find the cause in the error log files of apache:

PHP Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 2502231 bytes) in /var/www/html/…/amfphp2/core/amf/io/AMFBaseSerializer.php on line 98

So the cause is not amfphp, but instead my setting in php. So I edited /etc/php.ini, set memory_limit to a larger value. The problem solved.

If this doesn’t solve your problem, you may try the following links:
http://www.sephiroth.it/weblog/archives/2007/10/amfphp_and_mbstring.php
http://www.gotoandlearnforum.com/viewtopic.php?f=17&t=23708&p=109112

Author: Xu Cui Categories: adobe air, linux, php, web Tags:

phpBB 3 spam filter

May 18th, 2009

Standard phpBB captcha is broken. I modify it such that the user need to add the numbers in captcha images and enter the result (e.g. 1+2+3=6), instead of enter the original characters (e.g. ‘123′).

Enter folder /includes/ucp

edit file ucp_confirm.php: around line 75, find $captcha->execute($row … ) and change to $captcha->execute(’123′,…)

edit file ucp_register.php:

around line 191 (’confirm_code’ = > …), change the mimum # of characters to 1 (instead of 5).

around line 489, find $code = gen_rand_string(mt_rand … and change to $code = ‘6′

Enter folder /

edit file posting.php: around line 755, find line if(empty($confirm_row … and change $confirm_row['code'] = ‘6′

Enter folder /language/en/common.php, change ‘CONFIRMATION_CODE_EXPLAIN’ strings to ‘Add all the numbers and enter the result’

Author: Xu Cui Categories: linux, php, web Tags:

X11 with PuTTY

October 27th, 2008

X window doesn’t work with PuTTY (download) alone.

  1. Download, install and run xming (~2M).
  2. Check “Enable X11 forwarding” in PuTTY configuration window, and ssh to your server.
  3. Check if X window works by run command “xclock”.

refer to: http://serendip.brynmawr.edu/scienceinsociety/node/38

Author: Xu Cui Categories: linux Tags:

vim cheetsheet

October 23rd, 2008

http://www.tuxfiles.org/linuxhelp/vimcheat.html

Author: Nana Långstedt < nana.langstedt at gmail.com >

Working with files
Vim command Action
:e filename Open a new file. You can use the Tab key for automatic file name completion, just like at the shell command prompt.
:w filename Save changes to a file. If you don’t specify a file name, Vim saves as the file name you were editing. For saving the file under a different name, specify the file name.
:q Quit Vim. If you have unsaved changes, Vim refuses to exit.
:q! Exit Vim without saving changes.
:wq Write the file and exit.
:x Almost the same as :wq, write the file and exit if you’ve made changes to the file. If you haven’t made any changes to the file, Vim exits without writing the file.
These Vim commands and keys work both in command mode and visual mode.
Vim command Action
j or Up Arrow Move the cursor up one line.
k or Down Arrow Down one line.
l or Right Arrow Right one character.
h or Left Arrow Left one character.
e To the end of a word.
E To the end of a whitespace-delimited word.
b To the beginning of a word.
B To the beginning of a whitespace-delimited word.
0 To the beginning of a line.
^ To the first non-whitespace character of a line.
$ To the end of a line.
H To the first line of the screen.
M To the middle line of the screen.
L To the the last line of the screen.
:n Jump to line number n. For example, to jump to line 42, you’d type :42
Inserting and overwriting text
Vim command Action
i Insert before cursor.
I Insert to the start of the current line.
a Append after cursor.
A Append to the end of the current line.
o Open a new line below and insert.
O Open a new line above and insert.
C Change the rest of the current line.
r Overwrite one character. After overwriting the single character, go back to command mode.
R Enter insert mode but replace characters rather than inserting.
The ESC key Exit insert/overwrite mode and go back to command mode.
Deleting text
Vim command Action
x Delete characters under the cursor.
X Delete characters before the cursor.
dd or :d Delete the current line.
Entering visual mode
Vim command Action
v Start highlighting characters. Use the normal movement keys and commands to select text for highlighting.
V Start highlighting lines.
The ESC key Exit visual mode and return to command mode.
Editing blocks of text
The Vim commands marked with (V) work in visual mode, when you’ve selected some text. The other commands work in the command mode, when you haven’t selected any text.
Vim command Action
~ Change the case of characters. This works both in visual and command mode. In visual mode, change the case of highlighted characters. In command mode, change the case of the character uder cursor.
> (V) Shift right.
< (V) Shift left.
c (V) Change the highlighted text.
y (V) Yank the highlighted text. In Winblows terms, “copy the selected text to clipboard.”
d (V) Delete the highlighted text. In Winblows terms, “cut the selected text to clipboard.”
yy or :y or Y Yank the current line. You don’t need to highlight it first.
dd or :d Delete the current line. Again, you don’t need to highlight it first.
p In Winblows terms, “paste” the contents of the “clipboard”. In Vim terms, you “put” the text you yanked or deleted. Put characters after the cursor. Put lines below the current line.
P Put characters before the cursor. Put lines above the current line.
Undo and redo
Vim command Action
u Undo the last action.
U Undo all the latest changes that were made to the current line.
Ctrl + r Redo.
Vim command Action
/pattern Search the file for pattern.
n Scan for next search match in the same direction.
N Scan for next search match but opposite direction.
Replace
Vim command Action
:rs/foo/bar/a Substitute foo with bar. r determines the range and a determines the arguments.
The range (r) can be
nothing Work on current line only.
number Work on the line whose number you give.
% The whole file.
Arguments (a) can be
g Replace all occurrences in the line. Without this, Vim replaces only the first occurrences in each line.
i Ignore case for the search pattern.
I Don’t ignore case.
c Confirm each substitution. You can type y to substitute this match, n to skip this match, a to substitute this and all the remaining matches (”Yes to all”), and q to quit substitution.
Examples
:452s/foo/bar/ Replace the first occurrence of the word foo with bar on line number 452.
:s/foo/bar/g Replace every occurrence of the word foo with bar on current line.
:%s/foo/bar/g Replace every occurrence of the word foo with bar in the whole file.
:%s/foo/bar/gi The same as above, but ignore the case of the pattern you want to substitute. This replaces foo, FOO, Foo, and so on.
:%s/foo/bar/gc Confirm every substitution.
:%s/foo/bar/c For each line on the file, replace the first occurrence of foo with bar and confirm every substitution.
Author: Xu Cui Categories: linux Tags: