Wednesday, October 10, 2012

Use Meld as a diff tool for git

To view git diff through meld, my favorite diff viewing tool, do the following:

  1. Write a small script in ~/bin/gitdiff, or wherever you like to store your scripts
    #!/bin/bash
    meld $2 $5


  2. git config --global diff.external ~/bin/gitdiff
Done!

RESTful API development using Node

Below are some helpful things I've come across while developing a RESTful API for a project of mine. I'll be updating this as I go.
  • REST-esting using curl -- a guide to using curl for testing RESTful API's
  • Postman Chrome Extension. Much better than using curl, in my opinion. 
  • Apigee is a web service meant to serve as a middleman between your server and clients. Useful for things like rate limiting, limited JSON->XML conversion, and even load balancing. 

Thursday, September 20, 2012

Fixing Penn State Wireless Network Stability Issues on Linux

On Linux Mint (and I'm assuming most Gnome-based distributions of Linux), NetworkManager does a bad job staying connected to the new psu network that has spread to most of campus.
wicd is an alternative network manager that seems to relieve a lot of the problems that NetworkManager had.

Install wicd
$ sudo apt-get install wicd
Then edit or create an encryption template "psu" as /etc/wicd/encryption/templates/psu. Note that this file may exist already but is probably outdated (as of today, mine was outdated). Find my version of the psu encryption template here: https://bitbucket.org/zachwolfe/dotfiles/src/2dc9a24fbc7b/etc/wicd/encryption/templates/psu
Then open the wicd-gtk client and connect to the "psu" network using the "psu" encryption template you just defined. You should also select the "use these settings for all networks sharing this essid" checkbox as well for obvious reasons.

Saturday, September 15, 2012

HP dm4 laptop right click fix

On Linux Mint Cinnamon, (and probably most Ubuntu versions at or before 12) my hp dm4's synaptics touchpad did not automatically detect that it has a right a left button.

To fix this, create the directory /etc/X11/xorg.conf.d/

$ sudo mkdir -p /etc/X11/xorg.conf.d

Then place this file into /etc/X11/xorg.conf.d:
https://bitbucket.org/zachwolfe/dotfiles/src/88321594ef20/etc/X11/xorg.conf.d/50-synaptics.conf

Restart the X Server (Ctrl Alt Backspace or log out or reboot)

Wednesday, August 1, 2012

nginx HTTP/HTTPS setup

Setting up nginx SSL is pretty easy. I'm running nginx/1.0.10.

Use make-ssl-cert to make your SSL certificate.
make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/ssl/private/zachwolfe.org.crt Copy this file to /etc/ssl/private/zachwolfe.org.key and /etc/ssl/certs/zachwolfe.org.crt.

Modify /etc/ssl/private/zachwolfe.org.key to only include the key (as follows):
-----BEGIN CERTIFICATE-----
...key text is here....
-----END RSA PRIVATE KEY-----


Modify /etc/ssl/certs/zachwolfe.org.crt to only include the certificate (as follows):
-----BEGIN RSA PRIVATE KEY-----
...certificate text is here....
-----END CERTIFICATE-----


nginx setup:
File /etc/nginx/conf.d/zachwolfe.org.ssl.conf
server {
    listen       443;
    server_name  zachwolfe.org;

    ssl                  on;
    ssl_certificate      /etc/ssl/certs/zachwolfe.org.crt;
    ssl_certificate_key  /etc/ssl/private/zachwolfe.org.key;

    ssl_session_timeout  5m;

    ssl_protocols  SSLv2 SSLv3 TLSv1;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;

    location / {
        root /var/www/;
        index  index.html index.htm;
    }
}


File /etc/nginx/conf.d/zachwolfe.org.conf
server {
    listen       80;
    server_name  zachwolfe.org;
    access_log /var/log/nginx/zachwolfe.org.access.log;

    location / {
        root /var/www/;
        index  index.html index.htm;
}

Wednesday, June 27, 2012

Running vim as a server without X

So far, running vim as a server without X is impossible as far as I know. I don't understand why vim depends on X at all, especially for this case.

$ vim --servername foobarbaz
doesn't work, and even worse, silently fails. No warnings, errors, etc.

I thought it could be that vim didn't have some kind of compile option, but:
$ vim --version | grep client
+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments


The only way to use vim's built in server is to give it a valid DISPLAY value at startup. This makes vim behave a little slower, which is especially noticeable at startup.

DISPLAY=:11 vim --servername foobarbaz





To start a server:
DISPLAY=:0.0 vim --servername mainVim

To edit a file on an already running vim server:
DISPLAY=:0.0 vim --servername MAINVIM --remote-tab-silent `find -type f -name filename`

Wednesday, June 13, 2012

Compiling GNU/screen with vertical split support

Yum (on RHEL5) GNU/screen doesn't come with the vertical split patch. We just need a newer version.
git clone git://git.savannah.gnu.org/screen.git
$ cd screen/src
$ ./autogen.sh
$ ./configure
$ make
# make install

Monday, May 21, 2012

Workaround for ssh session git pushes failing

$ git push origin master

(gnome-ssh-askpass:22648): Gtk-WARNING **: cannot open display:

This occurs because the SSH_ASKPASS environment variable is set to "/usr/libexec/openssh/gnome-ssh-askpass", which is the nice gtk window that pops up when you're running gnome. I don't want this, because I do most of my work over SSH, so simply change SSH_ASKPASS to something else. In my ~/.bashrc
alias git="SSH_ASKPASS='' git"

Then: $ source ~/.bashrc

Fixes it up.

Sunday, April 15, 2012

Running PyBrain in a virtual environment

I recently worked on a class project using Neural Networks and PyBrain. Because my university gives High Performance Computing cluster accounts to students that request them, I decided it would be a good idea to put them to use.

To install PyBrain on a machine with no python installation or administrator access:

  1. Download and compile python 2.6.x
  2. Download virtualenv
  3. Create a virtualenv using the aforementioned python binary.
    python virtualenv -p /path/to/python2.6 ENV
  4. Source the virtual environment's environment
    source ENV/bin/activate
  5. Download and compile BLAS. Ensure to use -fPIC if your system requires it. Make sure NOOPTS and OPTS are correct.
  6. Download and compile LAPAC.
  7. Use pip to install numpy
    LAPACK=~/lapack-3.4.0/liblapack.a BLAS=~/BLAS/libfblas.a ~/scratch/work/ENV/bin/pip install numpy
  8. Download and compile scipy. set the --fcompiler option to gnu95, to ensure numpy and scipy use the same compiler.
    LAPACK=~/lapack-3.4.0/liblapack.a BLAS=~/BLAS/libfblas.a ~/scratch/work/ENV/bin/python setup.py build --fcompiler=gnu95
  9. Use pip to install pybrain.
    ~/scratch/work/ENV/bin/pip install pybrain
  10. Test pybrain.
    python
    >>import pybrain


Tuesday, March 13, 2012

Automount NTFS partition using Ubuntu 11.10

To automount an NTFS partiton, add the following to /etc/fstab:
15 UUID=58C7049A417B945D /media/media ntfs rw,auto,users,exec,nl=utf8,umask=003,gd=46,uid=1000 0 2

Substituting your partition's UUID and mount point (I chose /media/media). To find your partiton's UUID, run sudo blkid


Then, test with:
mount /media/media
This yields an error:
mozach@dm4:~$ mount /media/media
Mount is denied because setuid and setgid root ntfs-3g is insecure with the
external FUSE library. Either remove the setuid/setgid bit from the binary
or rebuild NTFS-3G with integrated FUSE support and make it setuid root.
Please see more information at
http://tuxera.com/community/ntfs-3g-faq/#unprivileged


To fix this we must recompile ntfs-3g to include FUSE support.
Download ntfs-3g source:
zach@dm4:~/ntfs$ wget http://tuxera.com/opensource/ntfs-3g_ntfsprogs-2012.1.15.tgz
Decompress:
zach@dm4:~/ntfs$ tar -xvzf ntfs-3g_ntfsprogs-2012.1.15.tgz
Configure (including internal FUSE support):
zach@dm4:~/ntfs/ntfs-3g_ntfsprogs-2012.1.15$ ./configure --with-fuse=internal
Compile:
zach@dm4:~/ntfs/ntfs-3g_ntfsprogs-2012.1.15$ make
Install:
zach@dm4:~/ntfs/ntfs-3g_ntfsprogs-2012.1.15$ sudo make install

Reboot and /media/media should be mounted automatically.

Friday, February 10, 2012

Fedora Core 16 bash hanging on 'command not found'

$ sasdasd
bash: sasdasd: command not found...
*wait for a few seconds*

Fedora thought the feature of attempting to look up an invalid command in the yum database was good to enable by default. I see how this is useful, but I find it really annoying (simply because it's slow).

To remove (as root):
sed -i 's/SoftwareSourceSearch=true/SoftwareSourceSearch=false/' /etc/PackageKit/CommandNotFound.conf