Open Files With Long Lines in KWrite, Kate and Kile

In a recent KDE upgrade, the katepart text editor, which powers, kwrite, kile and kate, has been modified to open files with long lines as read only.
Sometimes it will tell you about this in a warning, sometimes you’ll just notice that you cannot modify the file.
It also turns out that the maximum line length is actually very short: 1024 characters. You will have no trouble finding log files with lines longer than this.

After some poking around we’ve figured out that the maximum line length is configurable:
Go to
settings > configure editor > open/save

There you can change the

line length limit

The value 0 means that there is no maximum.
Hit Ok and you’re good to go again.

As a side note: this is a very annoying change. Kate was working fine for us. This new change might fix some bug somewhere, but made the software unusable for our scenario, with absolutely no documentation or hint on how restore the previous behavior. Sometimes you don’t even get a warning that the file was loaded read only (many keyboards have suffered because of this)

Edit: Apparently Kile remembers the read only state of a document. It will keep a document read only if it was previously read only, even after you made the change in the settings. You can turn off read only mode for the active mode by deselecting it in the Tools menu. Kate and KWrite do have this issue.

Precompile pgfplots using tikzexternalize

Using pgfplots allows you to quickly create very beautiful plots, that look like they belong to your paper, by automatically using the correct fonts and styles. It does this by using the latex compiler to make the figures. This approach is very powerful but has a major drawback: the latex compiler was not made to do this. As a result, latex tends to run out of memory very fast, and projects with a lot of pgfplots tend to take a long time to compile.

We’ve previously shown how to increase the amount of memory latex has available, but this only solves half the problem.

A proper way to fix this is using the tikzexternalize command. It causes latex to compile the figures in a separate run, generating pdfs. These pdfs are then included in the main document, reducing both the memory requirements and the compilation time.

Using tikzexternalize is very simple, two step process

  1. Call latex with the “shell-escape” option.
    This looks like this on linux:

    pdflatex -shell-escape mydocument.tex

    The easiest way to do this is to modify the build command of your latex-editor of choice.

  2. Add the following lines of code to your latex preamble

    \usepgfplotslibrary{external} 
    \tikzexternalize[prefix=TikzPictures/]
    

    The first line loads the tikzexternalize library, the second line activates it. The second line also contains an option that specifies the folder where the resulting pdfs and intermediary files should be stored.

Latex will now externalize any tikzpicture you make. You can optionally use

\tikzsetnextfilename{name_of_resulting_pdf}

to specify a name for the resulting pdf file. This is strongly recommended, because latex will only recompile a figure if you remove the resulting pdf.

Useful Linux Scripts

We didn’t come up with this one, but it’s a very handy reference guide. In good medieval monastery style, we’re copying it here in order to safeguard this information for future generations.

PS command:

The PS command is useful to check for performance problems:

1) Displaying top CPU-consuming processes:

ps aux | head -1; ps aux | sort -rn +2 | head -10

2) Displaying top 10 memory-consuming processes:

ps aux | head -1; ps aux | sort -rn +3 | head

3) Displaying process in order of being penalized:

ps -eakl | head -1; ps -eakl | sort -rn +5

4) Displaying process in order of priority:

ps -eakl | sort -n +6 | head

5) Displaying process in order of nice value

ps -eakl | sort -n +7

6) Displaying the process in order of time

ps vx | head -1;ps vx | grep -v PID | sort -rn +3 | head -10

7) Displaying the process in order of real memory use

ps vx | head -1; ps vx | grep -v PID | sort -rn +6 | head -10

8) Displaying the process in order of I/O

ps vx | head -1; ps vx | grep -v PID | sort -rn +4 | head -10

9) Displaying WLM classes

ps -a -o pid, user, class, pcpu, pmem, args

10) Determinimg process ID of wait processes:

ps vg | head -1; ps vg | grep -w wait

11) Wait process bound to CPU (replace PID with the actual process number)

ps -mo THREAD -p PID

lsof Command:

1) List all open files:

lsof

2) List all open Internet, x.25 (HP-UX), and UNIX domain files:

lsof -i -U

3) List all open IPv4 network files in use by the process whose PID is 1234:

lsof -i 4 -a -p 1234

4) List all files using any protocol on ports 513, 514, or 515 of host wonderland.cc.purdue.edu:

lsof -i @wonderland.cc.purdue.edu:513-515

5) List all files using any protocol on any port of mace.cc.purdue.edu (cc.purdue.edu is the default domain)::

lsof -i @mace

6) List all open files for login name “abe”, or user ID 1234, or process 456, or process 123, or process 789:

lsof -p 456,123,789 -u 1234,abe

7) List all open files on device /dev/hd4:

lsof /dev/hd4

8) Find the process that has /u/abe/foo open:

lsof /u/abe/foo

9) Send a SIGHUP to the processes that have /u/abe/bar open:

kill -HUP `lsof -t /u/abe/bar`

10) Find any open file, including an open UNIX domain socket file, with the name /dev/log:

lsof /dev/log

11) Find processes with open files on the NFS file system named /nfs/mount/point whose server is inaccessible, and presuming your mount table supplies the device number for /nfs/mount/point:

lsof -b /nfs/mount/point

12) Do the preceding search with warning messages suppressed:

lsof -bw /nfs/mount/point

13) Ignore the device cache file:

lsof -Di

14) Obtain PID and command name field output for each process, file descriptor, file device number, and file inode number for each file of each process:

lsof -FpcfDi

15) List the files at descriptors 1 and 3 of every process running the lsof command for login ID “abe” every 10 seconds:

lsof -c lsof -a -d 1 -d 3 -u abe -r10

16) List the current working directory of processes running a command that is exactly four characters long and has an `o` or `O` in character three with this regular expression form of the -c c option:

lsof -c /^..o.$/i -a -d cwd

17) Find an IP version 4 socket file by its associated numeric dot-form address:

lsof -i@128.210.15.17   

18) Display list of open ports:

lsof -i

19) List information about TCP sessions on your server (specifically SSH in this example):

lsof -i tcp@`hostname`:22

20) List information about all TCP session:

lsof -i tcp@`hostname`

21) List information about all sockets using port 53 (will display named information on UDP/TCP)

lsof -i @`hostname`:53

22) List information about all UDP sessions

lsof -i udp@`hostname`

23) List all open files with “ssh” in them:

lsof -c ssh

24) List everything but with UIDs insted of the UID name from /etc/passwd:

lsof -l

25) List all open files with “ssh” and only the UIDs:

lsof -l -c ssh

26) List all open files for the /tmp dir. Very slow, but good for finding that nasty process that’s holding a file open (although: fuser -m /tmp, will do the same thing):

lsof +D /tmp 

fuser and netstat Commands:

1) Kill all processes accessing the file system /home in any way:

fuser -km /home 

2) Invoke something if no other process is using /dev/ttyS1:

if fuser -s /dev/ttyS1; then :; else something; fi 

3) Some Important Command to find DDOS Attack:

fuser telnet/tcp shows all processes at the (local) TELNET port.
netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr
netstat -ntu | grep -v TIME_WAIT | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr
netstat -an | grep :80 | awk '{print $5}' | cut -f1 -d":" | sort | uniq -c | sort -n

4) netstat command example:

netstat –listen

5) Display open ports and established TCP connections:

netstat -vatn

6) For UDP port try following command:

netstat -vaun

7) If you want to see FQDN then remove -n flag:

# netstat -vat

Fix matlab and latex file associations on KDE

KDE (and linux) in general has a very elaborate system of guessing the file type of your file, that depends on both the file extension and the file contents. In 99% of the cases these rules work, unfortunately the other 1% has been annoying me for quite some time.
If you create a matlab m-file that starts with comments (% some comment), KDE will think the file is a latex file and insist on opening it with a dedicated latex editor.
This behaviour can be changed by modifying the mime type definitions.
Open /usr/share/mime/packages/freedesktop.org.xml in your favourite text editor as root.
Find the node <mime-type type="text/x-tex">. This will have a subnode that looks like:

<magic priority="10">
   <match value="%" type="string" offset="0"/>
</magic>

Change the priority to something smaller than 10, so it has a lower priority than the matlab magic rule.
Now run

sudo update-mime-database /usr/share/mime

And that’s it. KDE will now see all your m-files as matlab scripts even if they start with a comment.

Import latex formulas into inkscape

Getting nice looking formulas in your presentations / posters is always a problem. Latex is great at producing nice looking formulas and text, but for presentations and posters it’s not really equipped.

You could however write your formulas in a latex document, then import the pdf into inkscape and cut out the formulas. Unfortunately, inkscape will insist on treating your formulas as text, and mess them up in the process.
With a minor sidestep to acrobat professional we can get around this in five easy steps:

1. Open the pdf in acrobat professional.
2. Add a watermark using Document -> Watermark -> add. Set its opacity to 0%
3. Open advanced -> Printing Production -> Flattener Preview
4. Check “convert text to paths” and hit apply
5. Save your pdf

The text has now been converted to a vector drawing, and can now be imported into inkscape without problems.
If you don’t add the watermark in acrobat professional, it’ll just ignore the “convert text to paths” option (don’t ask why). This trick can be used to import any fancy formatted text without running into font problems. (You do lose the ability to edit the actual text though)

Enjoy your nicely formatted formulas in your presentations / posters

Mendeley and KDE

Mendeley is a very convenient bibliography tool. It keeps track of all your references, you can easily import from tons of sites and it backs up your collection on their servers. It also works on all major operating systems thanks to the Qt library.

Their latest builds had a bug on KDE systems though: you can’t open a pdf in an external viewer, which is rather annoying because the internal one is rather limited.

Now it appears that you can solve this bug by remove the Qt library files that come with the mendeley installation. Just add .bak to all files that have “Qt” in their name in the mendeley install folder.
Mendeley will now use your systems Qt libraries and “open in external viewer” will work. As an added benefit Mendeley will now also better integrate in your desktop visualy.

Install gitorious on your own Fedora 11 server

We wanted to have a code repository that can be browsed from the web. We have chosen to install open source gitorious: http://www.gitorious.org. Unfortunately there are no ready made packages, nor is there an extensive amount of documentation on how to get it running.

This guide is heavily based on the excellent tutorial by cjohansen for ubuntu/debian.
We have just modified it to work with the fedora package manager and the fedora way of configuring/running services.

This is by no means a definitive guide: we didn’t start from a blank server and we didn’t double check everything, so we’re not responsible if your server blows up. These are just the steps we took to get it running on our fedora 11 machine. We already had a working apache and mysql server, so we’re not covering those steps. There are plenty of tutorials available online. When in doubt check the cjohansen tutorial or perform some extra googling.

First a small overview of the bits and pieces that you need to get working:

  1. A rails application gitorious that serves the website
  2. A git daemon that allows people to pull (but not push) code from the repos using the git port
  3. A messaging system that performs tasks that would take too long if they were handled by the webserver
  4. A poller daemon that actually performs the tasks the messaging system serves
  5. A search daemon

It’s a very long guide, so here is the table of contents, listing all the steps:

  1. Installing required packages
  2. ActiveMQ Messaging Server
  3. Memcache
  4. Installing The Gitorious Code
  5. Configure the git-daemon and git-ultrasphinx services
  6. Installing Gems And Working Folders
  7. Configuring The Gitorious Script
  8. Configuring The MySQL Database
  9. Start All The Services
  10. Test The Gitorious Server
  11. Migrate The Gitorious Server To Apache
  12. Extra: Running Gitorious In A Sub Folder
  13. Hints

Enough chatter, on to the real stuff. All commands are run as root, unless otherwise mentioned.

Installing required packages

Begin with installing some required packages
Gitorious is a web based hosting service for git based projects, so obviously, we need git

yum install git git-svn

Some other useful packages. Gitorious reminds you of special events by mail, so you will need sendmail.

yum install apg pcre pcre-devel sendmail zlib zlib-devel

Fedora configures the sendmail service, but doesn’t start it automatically, so let’s do that now:

service sendmail start

Gitorious is written in ruby.

yum install ruby ruby-devel ruby-ri ruby-rdoc ruby-irb

Some extra dependencies:

yum install oniguruma-devel libyaml-devel GeoIP-devel
yum install ImageMagick-devel ruby-RMagick

Allows gitorious to access a mysql database:

yum install mysql-devel ruby-mysql

Sphinx is the search daemon gitorious uses. Gems is a way to install ruby “packages”. It’s also the reason why gitorious is so difficult to package for fedora or debian.

yum install rubygems sphinx
gem install ultrasphinx --no-ri --no-rdoc

ActiveMQ Messaging Server

We need this to run the ActiveMQ messaging server

yum install java-1.6.0-openjdk

Download the ActiveMQ source from the apache website (you can get a newer version if you like by modifying the url). Then extract it into /usr/local/ to install it.

cd /tmp
wget http://www.powertech.no/apache/dist/activemq/apache-activemq/5.2.0/apache-activemq-5.2.0-bin.tar.gz
tar xzvf apache-activemq-5.2.0-bin.tar.gz  -C /usr/local/

Make the user that will run the ActiveMQ messaging server. Give it ownership over the ActiveMQ data folder, so it can modify the required files.

adduser --system --no-create-home activemq
chown -R activemq /usr/local/apache-activemq-5.2.0/data

Now let us configure the ActiveMQ daemon.

nano -w /usr/local/apache-activemq-5.2.0/conf/activemq.xml

Find the the networkconnectors tag and change it into:

 <!-- The store and forward broker networks ActiveMQ will listen to -->
 <networkConnectors>
   <!-- by default just auto discover the other brokers -->
   <!--  -->
   <!-- Example of a static configuration: -->
   <networkConnector name="localhost" uri="static://tcp://127.0.0.1:61616"/>
</networkConnectors>

Then, change the management context tag to:

<!-- Use the following to configure how ActiveMQ is exposed in JMX -->
<managementContext>
    <managementContext createConnector="true"/>
</managementContext>

By default ActiveMQ tries to use SSL. This didn’t work for us. Edit the bin/activemq macro to disable it:

if [ -z "$SUNJMX" ] ; then
  SUNJMX="-Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
  #SUNJMX="-Dcom.sun.management.jmxremote"
fi

Now that ActiveMQ is configured, we need to make it a service that runs in the background and starts up at boot.

Create the scripts that start and stop ActiveMQ:

cd /usr/local/apache-activemq-5.2.0
touch activemqstart.sh
touch activemqstop.sh

Add following to activemqstart.sh

#!/bin/bash
export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64
/usr/local/apache-activemq-5.2.0/bin/activemq-admin start &

Add following to activemqstop.sh

#!/bin/bash
export JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64
/usr/local/apache-activemq-5.2.0/bin/activemq-admin stop

Make these files executable

chmod +x activemqstart.sh
chmod +x activemqstop.sh

Now create the ActiveMQ service file:

cd /etc/init.d
touch activemq

Add this to activemq:

#!/bin/bash
#
# activemq       Starts ActiveMQ.
#
#
# chkconfig: 345 88 12
# description: ActiveMQ is a JMS Messaging Queue Server.
### BEGIN INIT INFO
# Provides: $activemq
### END INIT INFO

# Source function library.
. /etc/init.d/functions

[ -f /usr/local/apache-activemq-5.2.0/activemqstart.sh ] || exit 0
[ -f /usr/local/apache-activemq-5.2.0/activemqstop.sh ] || exit 0

RETVAL=0

umask 077

start() {
       echo -n $"Starting ActiveMQ: "
       daemon /usr/local/apache-activemq-5.2.0/activemqstart.sh
       echo
       return $RETVAL
}
stop() {
       echo -n $"Shutting down ActiveMQ: "
       daemon su -c /usr/local/apache-activemq-5.2.0/activemqstop.sh activemq
       echo
       return $RETVAL
}
restart() {
       stop
       start
}
case "$1" in
 start)
       start
       ;;
 stop)
       stop
       ;;
 restart|reload)
       restart
       ;;
 *)
       echo $"Usage: $0 {start|stop|restart}"
       exit 1
esac

exit $?

Make this file executable. Add it to the system as a service and then configure it so it starts up at boot:

chmod +x activemq
chkconfig --add activemq
chkconfig --levels 2345 activemq on

ActiveMQ can now be started using:

service activemq start

Memcache

Install, configure and start the memcache service for better performance:

yum install memcached
chkconfig --levels 2345 memcached on
service memcached start

Installing The Gitorious Code

Now that the required services are installed and running we can get on with installing the actual gitorious code.
Make a user git and group gitorious. Add the user git to the group gitorious.

adduser git --disabled-password
groupadd gitorious
usermod -a -G gitorious git

Make the folders that will hold the gitorious installation:

mkdir /var/www/git.myserver.com
chown git:gitorious /var/www/git.myserver.com
chmod -R g+sw /var/www/git.myserver.com

Get the latest and greatest gitorious code as the git user:

su - git
cd /var/www/git.myserver.com
mkdir log
mkdir conf
git clone git://gitorious.org/gitorious/mainline.git gitorious

Still as the git user, remove the .htaccess file (we’ll configure this later ourselves) and make some extra directories:

cd gitorious/
rm public/.htaccess
mkdir -p tmp/pids

Back as root, make sure the gitorious script (which allows users to push code into gitorious) is available as a system command, by symbolic linking it to /usr/local/bin
Then make all gitorious scripts executable and configure some extra permissions:

su root
ln -s /var/www/git.myserver.com/gitorious/script/gitorious /usr/local/bin/gitorious
chmod ug+x script/*
chmod -R g+w config/ log/ public/ tmp/

Configure the git-daemon and git-ultrasphinx services

The next few steps need to be performed as the git user again.
Edit the git-daemon service in /var/www/git.myserver.com/gitorious/doc/templates/ubuntu/git-daemon:

GIT_DAEMON="/usr/bin/ruby /var/www/git.myserver.com/gitorious/script/git-daemon -d"
PID_FILE=/var/www/git.myserver.com/gitorious/log/git-daemon.pid

Then edit the git-daemon script /var/www/git.myserver.com/gitorious/script/git-daemon
Find the line that says host = 0.0.0.0 and replace it with git.myserver.com (line 265 in our case). Do not use localhost or the daemon won’t listen to external calls.

Now link the git-daemon service and the sphinx service to init.d (as root)

ln -s \
  /var/www/git.myserver.com/gitorious/doc/templates/ubuntu/git-ultrasphinx \
  /etc/init.d/git-ultrasphinx
ln -s \
  /var/www/git.myserver.com/gitorious/doc/templates/ubuntu/git-daemon \
  /etc/init.d/git-daemon

Make both files executable and configure them to start up on boot:

chmod +x /etc/init.d/git-ultrasphinx 
chmod +x /etc/init.d/git-daemon
chkconfig --levels 2345 git-daemon on
chkconfig --levels 2345 git-ultrasphinx on

Installing Gems And Working Folders

Gitorious uses a ton of gems, so lets install some more of them

gem install --no-ri --no-rdoc rails mongrel mime-types textpow chronic ruby-hmac daemons mime-types oniguruma BlueCloth ruby-yadis ruby-openid geoip rspec rspec-rails RedCloth echoe

Make some working directories the directory that will hold the git repositories hosted in gitorious. These need to be owned by the git user:

su git
mkdir /var/git
mkdir /var/git/repositories
mkdir /var/git/tarballs
mkdir /var/git/tarball-work
chown -R git:git /var/git

Gitorious uses the authorized_keys file from the git user to identify users trying to push code. We need to make sure this file exists and has the right permissions

su git
mkdir ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys

Configuring The Gitorious Script

Still as the git user: create the configuration files from the supplied templates:

cd /var/www/git.myserver.com/gitorious
cp config/database.sample.yml config/database.yml
cp config/gitorious.sample.yml config/gitorious.yml
cp config/broker.yml.example config/broker.yml

Before we continue a small word about ruby/rails. This language works with the concept of environments. Basically this means that you can use different configurations for different purposes. Gitorious uses 3 configurations: development, testing and production. You can specify different settings for each of these environments. A different database for each environment will make sure you don’t mess up your live production database when testing new code. Unfortunately not all gitorious scripts default to running in the same environment, some will run in development others in production, which will result in incomplete or conflicting settings and tons of error messages. It’s not unlike user permission madness. We are not interesting in hacking on gitorious, just running the system so we will be working on the production environment. To avoid problems always explicitly specify the production environment for each ruby command you run.

Now that the disclaimer is out of the way, we can start editing the config files.
In the gitorious.yml we need to store a secret, so lets create one first. Copy it, make sure it’s all on one line and keep it somewhere ready to paste:

apg -m 64

Below we’ll print an example gitorious.yml file. The original gitorious.sample.yml contains explanations about all the various entries. An important line to notice is the gitorious_client_host line. We’re running this from apache so it says port 80. Later in the tutorial we’ll run the production environment from mongrel for testing. This one always runs on port 3000. So this line needs to be 3000 then. Later on when you migrate to apache change it back to 80.

production: 
  cookie_secret: paste_the_cookie_secret_you_made_here
  repository_base_path: "/var/git/repositories"
  extra_html_head_data:
  system_message:
  gitorious_client_port: 80
  gitorious_client_host: git.myserver.com
  gitorious_host: git.myserver.com
  gitorious_user: git
  exception_notification_emails: youradmin AT yourserver
  mangle_email_addresses: true
  public_mode: false
  locale: en
  archive_cache_dir: "/var/git/tarballs"
  archive_work_dir: "/var/git/tarball-work"
  only_site_admins_can_create_projects: false
  hide_http_clone_urls: false
  is_gitorious_dot_org: false

Configuring The MySQL Database

Edit config/database.yml by setting your favourite user names, passwords and database names. Afterwards create mysql stuff you just entered into config/database.yml:

mysql -uroot -p
> create database gitorious;
> create database gitorious_test;
> create database gitorious_dev;
> grant all privileges on gitorious.* to YOURUSER@localhost \
    identified by 'YOURPASSWORD';
> grant all privileges on gitorious_test.* to YOURUSER@localhost;
> grant all privileges on gitorious_dev.* to YOURUSER@localhost;

Once this is done, we can install some remaining gems (which I think autoconfigure themselves using some of the settings we’ve already made). You need to run this as root from the right folder to work!

su root
cd /var/www/git.myserver.com
rake gems:install

Configure the ruby scripts to work with your mysql configuration (mind your environment settings!):

su git
cd /var/www/git.myserver.com/gitorious
rake db:migrate RAILS_ENV=production

Create the admin user of the gitorious installation on the gitorious console (which is just a front for the mysqel console)

RAILS_ENV=production script/console
> user = User.first
> user.login = "git" # Change to your desired username
> user.activate
> user.accept_terms
> user.save

Other fun commands for the console you might want to use later on are user = User.find_by_login “user_login” and user.destroy to remove users from the database.

The database is now more or less set up. It’s time to configure the sphinx search daemon.
Edit /var/www/git.myserver.com/gitorious/config/ultrasphinx/default.base and replace 0.0.0.0 with localhost.

Next load these configurations into the ruby files

cd /var/www/git.myserver.com/gitorious
rake ultrasphinx:bootstrap RAILS_ENV=production

Set the permissions again, just to make sure:

su root
cd /var/www/git.myserver.com/gitorious
chown -R git:gitorious config/environment.rb script/poller log tmp
chmod -R g+w config/environment.rb script/poller log tmp
chmod ug+x script/poller

Start All The Services

Time to start the activemq server:

service activemq start

Start the git-daemon:

env RAILS_ENV=production /etc/init.d/git-daemon start

Test the poller daemon:

su git -c "cd /var/www/git.myserver.com/gitorious && env RAILS_ENV=production script/poller run"

Let it run for a few minutes. If you see no errors, ctrl+c the command and daemonize the process by running:

env RAILS_ENV=production script/poller start

Gitorious has a habbit of running as much as possible over ssl. This gives us problems with the login, so we’re going to disable this on our local install by adding the following to config/environments/production.rb (you might want to get this running on larger deployments)

SslRequirement.disable_ssl_check = true

Test The Gitorious Server

Everything is now configured. We’re going to test our gitorious install by running it in mongrel, a ruby webserver before migrating it to apache. This command always seems to run gitorious on port 3000 no matter what you have specified elsewhere. Like we mentioned before, this means that you have to specify gitorious_client_port 3000 in config/gitorious.yml for now.

su git -c "cd /var/www/git.myserver.com/gitorious && script/server -e production"

Open up a browser and surf to http://git.myserver.com:3000 and login using the gitorious admin account we created earlier in the gitorious console.

Gitorious uses your public ssh key to link your push request to a gitorious account. Go to the computer that you’ll be using to push code to gitorious. If you don’t already have a public ssh key run:

ssh-keygen

to generate one. Now do

cat .ssh/id_rsa.pub

and copy the output. Go to git.myserver.com:3000/~adminusernamehere/keys/new (where you substitute adminusernamehere for the admin user you logged in as). Paste the public key into the box and hit ok. Wait a minute or two and then refresh. The key should say “ready”. If it doesn’t after 2 minutes, delete the current one and try again; for some reason this doesn’t always work the first time.

The permissions on .ssh folder of the user uploading to gitorious are extremely important:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/*

Now try to pull a dumy repository to your workmachine and push some content to gitorious.

Migrate The Gitorious Server To Apache

If all the the previous things work, we can migrate our gitorious install from mongrel to apache.
We need the passenger apache modules to run ruby/rails on apache

su root
gem install passenger
passenger-install-apache2-module

Follow the installers instructions. If some bits and pieces are missing it will tell you. In our case we needed to install httpd-devel first

yum install httpd-devel

The last part is to set up a virtual host in apache to show the gitorious server.

cd /etc/httpd/conf.d
nano -w gitorious.conf

gitorious.conf:

NameVirtualHost git.myserver.com

<VirtualHost git.myserver.com>
        ServerName git.myserver.com
        DocumentRoot /var/www/git.myserver.com/gitorious/public
        ErrorLog /var/www/git.myserver.com/log/error.log
        CustomLog /var/www/git.myserver.com/log/access.log combined
</VirtualHost>

Restart apache and you’re done!

service httpd restart

Extra: Running Gitorious In A Sub Folder

The tutorial assumes that you will run gitorious on it’s own domain: git.myserver.com
In some cases you might want to run it in a subfolder, because you have other services running: myserver.com/git
This isn’t officially supported, but with some minor hacks you can easily get it done.

First make a /etc/httpd/conf.d/gitorious.conf with just the following content:

RailsBaseURI /git

This tells passenger that the subfolder git contains a rails app. Otherwise you just get a directory listing.

Next put a symbolic link of the public folder of gitorious into the html folder:

ln -s /var/www/git.myserver.com/gitorious/public /var/www/html/git

Now restart apache

service httpd restart

Normally this should be enough, but since the gitorious supposes you run at the domain root, you need to manually change a few lines.
Open /var/www/git.myserver.com/gitorious/public/stylesheets/base.css and replace all url(/images/whatever.jpg) with url(“../images/whatever.jpg”) (there are not too many).
Next open /var/www/git.myserver.com/gitorious/app/helpers/application_helper.rb
and on line 173 put git/ before images/default.gif (where git is the subdomain you’re running gitorious in)

And finally a very very ugly hack: in gitorious/lib/gitorious/ssh/client.rb change line 91 to:

query_url = "git/#{@project_name}/#{@repository_name}/config"

That should make gitorious play nice in a subfolder. These hacks are not very pretty and your install will probably break on an upgrade, so make sure you have a backup ready.

Hints

  • You can restart the gitorious app by doing (so you don’t need to restart the entire apache server)
    touch /var/www/git.myserver.com/gitorious/tmp/restart.txt
    
  • To get the times right in your install, set the timezone in config/environment.rb by changing the line
    config.time_zone = 'UTC'
    

    to

    config.time_zone = 'Your_City_Here'
    

    find out the usable values by running

    rake time:zones:local
    

    in /var/www/git.myserver.com/gitorious

Extending latex memory

Latex is a very powerful typesetting application. A powerful package to be used with this is pgfplots, which allows you to render your plots using the latex engine. Unfortunately the default latex settings assume you’re running latex on an ancient 20 MHz 486 with less ram than your average mobile phone. This is ok if you’re just asking it to process text, but if you’re using pgfplots it will run out of memory trying to draw your images.

The solution is to increase the amount of memory latex uses.

Windows – Miktex
We’re doing this in the windows command line. You can get to this by opening the start menu and do run .... Type cmd to start the terminal. On vista and up, you can just type cmd in the search field.

  1. Go the folder where Miktex is installed. Most likely this is C:\Program Files\Miktex 2.7\
  2. Go to the subfolder Miktex
  3. Go to the subfolder bin
  4. run
    initexmf --edit-config-file=pdflatex
    

    Replace pdflatex with latex or xetex if you’re using that.

  5. You’ll get a notepad screen with a file called pdflatex.ini. Add the line
    main_memory=2000000
    

    Don’t worry about the exact number, just make it big.

  6. Save the file
  7. run
    initexmf --dump=pdflatex
    
  8. That’s it. Enjoy your nice pgfplots figures

Linux – Texlive
Do the following things in a terminal as root.

  1. Find out where your texmf.cnf is located
    kpsewhich texmf.cnf
    

    This will most likely be /usr/share/texmf/web2c/texmf.cnf

  2. Open it and search for main_memory line and modify it to
    main_memory=2000000
    
  3. Save the file
  4. run
    fmtutil-sys --all
    

    to load the new settings

Latex formula as a native powerpoint object

It’s always a dilemma: latex is great for formulas but well, not so much at making slideshows or posters. Powerpoint on the other hand is great at the latter, but sucks balls at the first. No matter which tool you use to create your powerpoint, a lot of frustration, broken coffee mugs and hairloss ensues. Wouldn’t it be great if you could just typeset formulas in powerpoint using latex?

Enter: Tex 4 PPT
It renders your latex formula in the native ppt vector format. This means that it’ll look good at any resolution.

It requires a working Miktex install and microsoft’s .net framework.

Boot ISO files from USB with grub4dos

The goal is to make a universal bootable usb device with a small boot partition and a data partition on which we’ll store the iso files. This means you can just download almost any bootable iso and boot it without having to burn a cd or unpack the iso. We’ll install grub4dos as boot loader, using the ‘triple mbr’ feature to increase the compatibility with different mainboard and BIOS configurations. We’ll be using command line linux applications to reach our goal, any distro will do.

1) Find the path to your usb device, here we’ll use /dev/sdb
2) Optionally, to erase the usb device, issue the following commands as root:

shred -v -n0 -z /dev/sdb

3) Note down the size of the device in bytes:

fdisk -lu /dev/sdb

Disk /dev/sdb: 1031 MB, 1031798272 bytes

4) To make fdisk happy, partitions must end on cylinder boundaries. Here we’ll use the standard 63 sectors/track and 255 heads, so to calculate the number of cylinders and the last sector of the last cylinder, do the following:

num_cyl = floor( 1031798272 / 512 / 63 / 255 ) = 125
last_sector = num_cyl*255*63 - 1 = 2008124

5) We’ll make two partitions: a small boot partition with a ext2 filesystem and a second fat32 (or ntfs) partition to hold the iso files. Choosing ext2 as the boot filesystem hides it from windows systems, and makes the second fat32 partition visible. The boot partition only has to hold the ‘grldr’ and the ‘menu.lst’ file, so we set its size to 1 cylinder (or a little less if we take the first 95 boot sectors into account). The last sector of the first partition is 1*255*63-1 = 16064.

We use fdisk to set up the geometry of the device and make the first partition. Replace $num_cyl and $last_sector with the appropriate values.

fdisk /dev/sdb << EOF
x
s
63
h
255
c
$num_cyl
r
u
n
p
1
95
16064
n
p
2
16065
$last_sector
t
2
c
a
1
w
EOF

6) At this point, remove the usb device and plug it back in. The final layout should look like this:

fdisk -lu /dev/sdb

Disk /dev/sdb: 1031 MB, 1031798272 bytes
255 heads, 63 sectors/track, 125 cylinders, total 2015231 sectors
Units = sectors of 1 * 512 = 512 bytes
Disk identifier: 0x8d7751c5

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *          95       16064        7985  83  Linux
/dev/sdb2           16065     2008124      996030    c  W95 FAT32 (LBA)

7) Create the filesystems:

mke2fs -L boot /dev/sdb1
mkdosfs -F 32 -n data /dev/sdb2

8) As root, make a temporary working folder. Download the latest grub4dos and install boot code on the first partition:

cd
mkdir usbtemp
cd usbtemp
wget http://download.gna.org/grub4dos/grub4dos-0.4.4-2009-06-20.zip
unzip grub4dos-0.4.4-2009-06-20.zip
cd grub4dos-0.4.4
./bootlace.com --floppy=0 /dev/sdb1

9) Extract the first 96 sectors and create the triple MBR:

dd if=/dev/sdb of=boot.img bs=512 count=96
./bootlace.com boot.img
dd of=/dev/sdb if=boot.img bs=512 count=96

10) Mount the boot partition and copy the necessary grub4dos files:

mkdir /mnt/usbboot
mount /dev/sdb1 /mnt/usbboot/
cp grldr /mnt/usbboot/

11) As a test, we’ll boot the SliTaz LiveCD from the usb device. The iso will be saved to the second partition, and an entry in the ‘menu.lst’ file on the boot partition will make the iso available for booting.

mkdir /mnt/usbdata
mount /dev/sdb2 /mnt/usbdata
mkdir /mnt/usbdata/images
cd /mnt/usbdata/images
wget http://mirror.switch.ch/ftp/mirror/slitaz/iso/2.0/slitaz-2.0.iso
cd /mnt/usbboot/
umount /dev/sdb2
cat > menu.lst << EOF
title Boot SliTaz 2.0 LiveCD
find --set-root /images/slitaz-2.0.iso
map --mem /images/slitaz-2.0.iso (0xff)
map --hook
chainloader (0xff)
EOF
cd
umount /dev/sdb1

12) This should do it… To clean up just remove the ‘usbtemp’ folder.