Posts Tagged ‘git’

Website maintenance and tweaks

Keeping WordPress up to date

I originally installed WordPress using Subversion. This provides a really easy way for me to update WordPress:

svn switch http://core.svn.wordpress.org/tags/3.4.1

Replace 3.4.1 with the latest version number. Then I visit the admin panel of the blog and it will redirects me to perform any necessary database upgrades.

Use .htaccess to prevent access to the .svn directory:

# Prevent access to .svn directory
# From http://codex.wordpress.org/Installing/Updating_WordPress_with_Subversion
RewriteEngine On
RewriteRule ^(.*/)?\.svn/ - [F,L]
ErrorDocument 403 "Access Forbidden"

Compression

I’ve learned that content can be categorized into static content and dynamic content. There is an Apache module, mod_deflate, that can compress both types of content seamlessly. It only requires a configuration change in .htaccess, and no changes will need to be made to the application. However, it is inefficient because it recompresses the same content every time someone requests it. For this reason, my web host does not support mod_deflate. Instead, they recommend different tactics for each type of content.

On my blog, an example of dynamic content is the home page, http://www.rratliff.com/. This test or this test can test whether the home page is compressed. At time of writing, I have not found a good way to compress dynamic content.

On my blog, there are several static content files that are typically requested. For example, the CSS and JS files that WordPress includes in every page. Google Page Speed Insights is the a tool that tests compression of every resource needed for loading my blog’s home page, both the dynamic and static pages. I’m looking for a reliable way to compress the static content files that Google Page Speed Insights finds.

Deploying static content

I now have two sections of static content on my website, my Post Voting App and my Portfolio. I’ve adopted a simple solution to keep these sections up to date. Each section is maintained in a github repository. I have a matching repository on my own computer where I make changes, commit, and then push to the github repository. Then, to update the content on my website, I SSH to the host, cd to the directory, and do a git pull.

I reuse the .htaccess code above in order to prevent access to the .git subdirectory. See the .htaccess file for an example.

Backups

I created two scripts to backup the files and the database in my NearlyFreeSpeech site. The scripts aren’t fancy, they just contain one command each.

For the database, I created a non-privileged backup user who has permissions necessary to do a mysqldump on all the tables in my database. Here’s the gist of it. (It should be all one line. Lines wrapped for display purposes.)

ssh user@host mysqldump --user=nonprivilegeduser 
    --password=password --host=mysql_host 
    --all-databases | gzip > backup-file-name-$(date +%Y%m%d).sql.gz

Just change the underlined parts. The $(date) thing creates a filename like this:

backup-file-name-20131029.sql.gz

For the files, I use rsync with the options -aAXE --delete.

What I learned from Evolutionary Computing

875 lines of code and 55 hours. Evolutionary Computing was one of the most challenging courses I have taken at SCSU. These statistics come from our final project, which was a month-long research project. Our assignment was to build on previous projects and produce a 5-page paper suitable for publication at a conference.

I learned a lot while completing this project. My project studied spanning trees on complete graphs, and how to evolve them using a genetic algorithm. Maybe in a follow-up post I’ll introduce these concepts. For now, I want to show what I learned while writing those 875 lines of Python code.

  • Write a testing function for non-trivial tests. I was checking something by hand, and thought my program wasn’t working. Then I ended up spending several hours debugging something that was not in fact a bug.
  • Dropbox is an automated version control. Several times I used it to retrieve an old version of a file that I had not committed. This came in very handy.
  • In vim, you can do :edit! to reload a file from disk. (documentation here)
  • Time estimating is important when running your jobs on other people’s machines.
  • I learned how to profile code using cProfile. On Ubuntu, cProfile can be found in package python-profiler.

Git

In git, you can choose to commit only certain changes in a file. It can be done by using git gui. The GUI basically shows you the output of git diff for the changed files in your repo, and you can right click on a line in the diff and choose “Stage Line For Commit.”

I only used this a few times, but it is a lot better than doing the following:

$ cp dandelion.tex dandelion.tex.bak
$ git checkout -- dandelion.tex
$ #manually copy over the changes that you do want to commit
$ git add dandelion.tex
$ git commit -m "This is the hard way"

LaTeX

When writing tables in LaTeX, you must put the label in the caption in order for it to refer to a specific table number. If you don’t, your ref will only refer to the number of the section. Here is a working code snippet:

The times can be seen in Table ref{wallclock}.

begin{table}
caption{Wall clock times in seconds for a single
run of the genetic algorithm using the PyPy interpreter.
 label{wallclock}
}
begin{tabular}{l r}
...
end{tabular}
end{table}