Layers for WordPress


WordPress


Apache (apache2)


PHP (php5)


Mysql (mysql-server)


For inter-connections:
libapache2-mod-php5, php5-mysql

A test here: add <?php phpinfo(); ?> into the /var/www/testphp.php file
Open a web browser, visit http://localhost/testphp.php
You should be able to a webpage listing systme info

You need to create a user and database in mysql for WordPress to use:

[shell]
mysql -u root -p
Enter you password here:&lt;strong&gt;*&lt;/strong&gt;*
[/shell]

[shell]
create database wordpress;
create user ‘kaiyin’@’localhost’ identified by ‘some_password’
grant all privileges on wordpress.* to ‘kaiyin’@’localhost’
[/shell]

Then you should rename the file wordpress/wp-sample-config.php into wordpress/wp-config.php, and input your info accordingly:
[shell]
define(‘DB_NAME’, ‘wordpress’);
define(‘DB_USER’, ‘kaiyin’);
define(‘DB_PASSWORD’, ‘your_password’);
define(‘DB_HOST’, ‘localhost’);
[/shell]

Finally you can easily install by open this url in your web browser:
[html]
http://localhost/blog/wp-admin/install.php
[/html]

[py]
def a:
return a+1
[/py]

R data manipulation review: Work with sequences

To find out the unique values of a sequence, use the unique function, similarly, you can use the duplicated function to get a vector of boolean values indicating whether each of the element is duplicated, note the first appearance of a series of the same element is marked non-duplicated, which of course makes sense.
The rle function analyzes the run lengths of elements in the order of appearance.
Some examples:

 s1 = c(1,2,2,2,3,4)
 rle(s1)
Run Length Encoding
  lengths: int [1:4] 1 3 1 1
  values : num [1:4] 1 2 3 4
 s1 = c(1,2,2,2,3,4,2,2,2,2)
 rle(s1)
Run Length Encoding
  lengths: int [1:5] 1 3 1 1 4
  values : num [1:5] 1 2 3 4 2
 unique(s1)
[1] 1 2 3 4
 duplicated(s1)
 [1] FALSE FALSE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE
 s1.rle = rle(s1)
 any(s1.rle$values == 2 &amp;amp; s1.rle$lengths &amp;gt;3)
[1] TRUE
 s1.rle$values == 2 &amp;amp; s1.rle$lengths &amp;gt;3
[1] FALSE FALSE FALSE FALSE  TRUE
 index = which(s1.rle$values == 2 &amp;amp; s1.rle$lengths &amp;gt;3)
 cumsum(s1.rle$lengths)[index]
[1] 10

Vim command line options: execute commands without entering Vim

There are always times when you want to edit something real quick without bothering to open the editor. With vim, you can do it, here is a simple example:

=)echo -e "what\nwhat\ntarget\n" >/tmp/file
=)vi /tmp/file +/target +'s/$/ new text' +qall
=)cat /tmp/file
what
what
target new text

Actually I used this trick to automatically create blog titles.

R: generate data

The gl (read “generate levels”) function can be used to generate levels:

 thelevels = data.frame(group=gl(3,10,length=30), subgroup=gl(5,2,length=30), obs=gl(2,1,length=30))
 head(thelevels, 12)
   group subgroup obs
1      1        1   1
2      1        1   2
3      1        2   1
4      1        2   2
5      1        3   1
6      1        3   2
7      1        4   1
8      1        4   2
9      1        5   1
10     1        5   2
11     2        1   1
12     2        1   2

The first arg of al is the number of levels, the second arg is the repetition of each level. Note that all the columns generated by gl have the same length, and also

subgroup number of levels * subgroup number of repetition of each level = group number of repetitions of each level

The expand.grid function can used to quickly generate data frames. It accepts any number of sequences and generate unique combinations from them. Note the first sequence is the one that variates the fastest.

 x = expand.grid(factor1=1:5, factor2=1:2)
 x
   obs patient
1    1       1
2    2       1
3    3       1
4    4       1
5    5       1
6    1       2
7    2       2
8    3       2
9    4       2
10   5       2

We can further carry out some calculations by this data frame with the apply function, for example we can calculate the product of each row:

 res = apply(x, 1, function(row)row[1]*row[2])
 res
 [1]  1  2  3  4  5  2  4  6  8 10
 newx = cbind(x, res)
 newx
   obs patient res
1    1       1   1
2    2       1   2
3    3       1   3
4    4       1   4
5    5       1   5
6    1       2   2
7    2       2   4
8    3       2   6
9    4       2   8
10   5       2  10

To get a random sample from a population, use the sample function. With only one arg, what sample does is essentially reorder the vector in a random manner. You can of course specify the size of your desired sample, that’s what the second arg is for (or size=), you can also enable or disable replacement by the replace= arg.

 sample(1:10)
 [1]  8  2  7  3  4  5 10  6  9  1
 sample(1:10, 5)
[1] 8 7 5 9 1
 sample(1:10, 5, replace=T)
[1] 6 6 4 5 7
 sample(1:10, 5, replace=T)
[1]  3  5  8  8 10

Just for fun, let’s simulate the coin-flipping experiment:

 x = sample(c('heads', 'tails'), 1000000, replace=T)
 res = table(x)
 res
x
 heads  tails
500177 499823
 ratio = res[1]/sum(res)
 ratio
   heads
0.500177

Gnome keyring issue

Problem

Whenever I use git to push to a repo, the terminal issues a warning such as this:
WARNING: gnome-keyring:: couldn’t connect to: /tmp/keyring-*/pkcs11

Attempt 1 (Failed)

This is because I installed the Cinnamon desktop environment, and as a result altered the /etc/shell/autostart/gnome-keyring-pkcs11.desktop file. What we should is to make this file autostart in our target DE. Here is the edit (Note line 6):

Before:

[Desktop Entry]
Type=Application
Name=Certificate and Key Storage
Comment=GNOME Keyring: PKCS#11 Component
Exec=/usr/bin/gnome-keyring-daemon --start --components=pkcs11
OnlyShowIn=GNOME;Unity;
X-GNOME-Autostart-Phase=Initialization
X-GNOME-AutoRestart=false
X-GNOME-Autostart-Notify=true
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=gnome-keyring
X-GNOME-Bugzilla-Component=general
X-GNOME-Bugzilla-Version=3.2.2
NoDisplay=true
X-Ubuntu-Gettext-Domain=gnome-keyring

[Desktop Entry]
Type=Application
Name=Certificate and Key Storage
Comment=GNOME Keyring: PKCS#11 Component
Exec=/usr/bin/gnome-keyring-daemon --start --components=pkcs11
OnlyShowIn=GNOME;Unity;Mate
X-GNOME-Autostart-Phase=Initialization
X-GNOME-AutoRestart=false
X-GNOME-Autostart-Notify=true
X-GNOME-Bugzilla-Bugzilla=GNOME
X-GNOME-Bugzilla-Product=gnome-keyring
X-GNOME-Bugzilla-Component=general
X-GNOME-Bugzilla-Version=3.2.2
NoDisplay=true
X-Ubuntu-Gettext-Domain=gnome-keyring

Attempt 2 (Success)

Uninstall gnome-keyring, edit the ‘/etc/pkcs11/modules/gnome-keyring-module’ file, and comment out the ‘module: gnome-keyring-pkcs11.so’ line.

# The file is installed/loaded from the default module p11-kit directory
# module: gnome-keyring-pkcs11.so
# And where to store and lookup trust objects
x-trust-store: pkcs11:library-manufacturer=GNOME%20Keyring;serial=1:XDG:DEFAULT
x-trust-lookup: pkcs11:library-manufacturer=GNOME%20Keyring

Learning Dutch from EM

Gewoon héél goede vrienden.
Just very good friends.

Vuilnisbelt wordt speelparadijs.
Garbage dump is playground.

Plagiërende studenten: straffen en opvoeden.
Plagiarist students: punish and educate.

De ideale kandidaat
The ideal candidate

Academisch niveau
Academic level

Goed sociale vaardigheden
Good social skills

Coververhaal
Cover story

Achtergrond
Background

En verder
And further

Eerste wedstrijd op nieuwe roeibaan.
First game on new rowing course.

Twintig euro per persoon.
Twenty euros per person.

Vragen aan
Ask

Gemeentehuis
Town hall

Feestelijke
Festive

en dan dit nog
and then this is

Prijzige tolk voor u-raad.
Expensive interpreter for the university board.

In landen als China en India is het gebruikelijke om je behoefte te doen boven een hurktoilet.
In countries such as China and India, it’s customary that you have to do it over a squat toilet.

iedere vrouw
every woman

alles wat ik doe
all that I do

wetenschap
science

wetenschap kort
science brief

wetenschapsfraude
science fraud

gebeurd
happend

Learning Dutch

1

jongen: boy
wakker: wake
De jongen wordt in de ochtend wakker.

2

vrouw: woman
poetsen: brush
tanden: teeth
De vrouw is haar tanden aan het poetsen.

3

meisje: girl
wassen: wash
gezicht: face (facebook should be gezichtboek? Haha~)
Het meisje is haar gezicht aan het wassen.

4

eten: eat
tafel: table
De familie is aan de tafel aan het eten.

5

drinken: drink
De vrouw is water aan het drinken.

Subscribe to Dutchpod10

Learning Dutch

1

vader: father
thuiskomen: coming home
De vader komt thuis.

2

familie: family
televisie: television
kijken: see, look
De familie is televisie aan het kijken.

3

man: man
ochtend: morning
douchen: shower
De man is in de ochtend aan het douchen.

4

broer: brother
baden: bath
badkuip: bathtube
De broers zijn aan het baden in de badkuip.

5

slapen: sleep
deken: blanket
De baby is op het deken aan het slapen.

Learning Dutch

1

vader: father
thuiskomen: coming home
De vader komt thuis.

2

familie: family
televisie: television
kijken: see, look
De familie is televisie aan het kijken.

3

man: man
ochtend: morning
douchen: shower
De man is in de ochtend aan het douchen.

4

broer: brother
baden: bath
badkuip: bathtube
De broers zijn aan het baden in de badkuip.

5

slapen: sleep
deken: blanket
De baby is op het deken aan het slapen.