Tuesday, August 25, 2015

Explore the Beta Distribution

Here is the R code:

plotbeta = function(a, b) {
    x = seq(0, 1, by=.002)
    dat = NULL
    for(ai in a) {
        for(bi in b) {
            y = dbeta(x, ai, bi, log=T)
            dat_ab = data.frame(x, y, ai, bi)
            dat = rbind(dat, dat_ab)
        }
    }
    dat
}

a = c(.01, .1, .9)
b = a
dat = plotbeta(a, b)
p = ggplot(dat, aes(x, y)) +
    geom_line() +
    facet_grid(ai &#126 bi) +
    ylab("Log density of beta")
ggsave(file="/tmp/beta1.pdf", plot=p)


a = c(1.10023, 5, 50)
b = a
dat = plotbeta(a, b)
p = ggplot(dat, aes(x, y)) +
    geom_line() +
    facet_grid(ai &#126 bi) +
    ylab("Log density of beta")
ggsave(file="/tmp/beta2.pdf", plot=p)


a = c(1.10023, 5, 50)
b = c(.01, .1, .9)
dat = plotbeta(a, b)
p = ggplot(dat, aes(x, y)) +
    geom_line() +
    facet_grid(ai &#126 bi) +
    ylab("Log density of beta")
ggsave(file="/tmp/beta3.pdf", plot=p)

Tuesday, August 11, 2015

Set up PostgreSQL on OSX

Install

brew install postgresql
==> Downloading https://homebrew.bintray.com/bottles/postgresql-9.4.4.yosemite.b
########################################### 100.0%
==> Pouring postgresql-9.4.4.yosemite.bottle.tar.gz
==> Caveats
If builds of PostgreSQL 9 are failing and you have version 8.x installed,
you may need to remove the previous version first. See:
  https://github.com/Homebrew/homebrew/issues/2510

To migrate existing data from a previous major version (pre-9.4) of PostgreSQL, see:
  https://www.postgresql.org/docs/9.4/static/upgrading.html

To have launchd start postgresql at login:
  ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
  launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
  postgres -D /usr/local/var/postgres
==> Summary
/usr/local/Cellar/postgresql/9.4.4: 3014 files, 40M

Initialize

This will create a user (same name as the OS user) and initialize the data directory:
initdb ~/postgres

Create user (optional)

initdb has created a user for you, but if you want to create additional users (for example, Wordpress user), you can do the following:
# --pwprompt Password prompt
createuser --pwprompt newUser

Create a database

-O means owner.
createdb -Ouser testdb
Your login account (the default) will be used if no owner is specified.
createdb -Ouser testdb

Start/stop the SQL server

# use `stop` instead when you want to stop
pg_ctl -D ~/postgres/ start
# specify a logging file
pg_ctl -D ~/postgres/ -l ~/.postgre.log start

Access database

User login, with the testdb database we have created in the last step.
# -U: User
# -W: passWord
psql -U user -W testdb

Monday, August 10, 2015

Font fix for openjdk in Ubuntu (Intellij IDEA needs this especially)

Install the patched openjdk (PPA: openjdk-fontfix)

Edit idea64.vmoptions

For me this file is in /home/kaiyin/opt/ideac/bin/idea64.vmoptions, add the following lines.

-Dawt.useSystemAAFontSettings=lcd
-Dswing.aatext=true
-Dsun.java2d.xrender=true

It might be even better to put these options in HOME/.profile ~/.bashrc etc:

# make sure intellij uses openjdk
export IDEA_JDK="/usr/lib/jvm/java-8-openjdk-amd64"
export _JAVA_OPTIONS="-Dswing.aatext=true -Dawt.useSystemAAFontSettings=lcd  -Dsun.java2d.xrender=true -Xms1g -Xmx75g"

Saturday, August 8, 2015

Font fix for openjdk in Ubuntu (Intellij IDEA needs this especially)

Install openjdk-8 from this link.

To fix Intellij, do the following:

Edit idea64.vmoptions

For me this file is in /home/kaiyin/opt/ideac/bin/idea64.vmoptions, add the following lines.

-Dawt.useSystemAAFontSettings=lcd
-Dswing.aatext=true
-Dsun.java2d.xrender=true

It might be even better to put these options in ~/.profile ~/.bashrc etc:

# make sure intellij uses openjdk
export IDEA_JDK="/usr/lib/jvm/java-8-openjdk-amd64"
export _JAVA_OPTIONS="-Dswing.aatext=true -Dawt.useSystemAAFontSettings=lcd  -Dsun.java2d.xrender=true -Xms1g -Xmx75g"