Wednesday, July 31, 2013

Overwriting local changes with Git

Often I want to delete a file and pull the original back from my git repository. To do this properly you have to checkout the file from the "HEAD" tag.

$ git checkout HEAD <optional file name>
$ git checkout .

Tuesday, July 30, 2013

Pulling cross origin data within JavaScript

It took me a lot longer to figure this out than I thought it would, and the syntax has to be just so, minor changes cause failure due to same origin policy.

Using JQuery this code will allow you to pull data from an external website.
$.ajax({
    url: 'http://domain.com/data-request.php?foo=bar',
    dataType: 'jsonp',
    jsonp: 'jsoncallback',
    timeout: 5000,
    success: function(data, status){
        //data loaded
    },
    error: function(){
        //error loading data
    }
});
Data must be formatted in JSON format. I can't remember the site I found this on, but it gives a lot of detail on what's happening and why.

Friday, July 26, 2013

Using the Linux screen command to detach processes from terminal

A nice simple example based page on how to use the screen command in Linux.

http://www.thegeekstuff.com/2010/07/screen-command-examples/

Allows you to detach and later re-attach to SSH sessions without killing your processes.

Start screen session.
$ screen ./work_on_something.sh
Press CTRL+A and then "d" to detach.

List screen sessions.
$ screen -ls
There is a screen on:
21952.pts-0.debian-7 (07/26/13 23:25:29) (Attached)
1 Socket in /var/run/screen/S-user.

If detached, attach with -r
$ screen -r 21952.pts-0.debian-7

Wednesday, July 24, 2013

Removing invalid proxmox VM listings

The proxmox datacenter view sometimes shows a VM after the VM has been deleted. This is appears to be a bug where the configuration file is not deleted.

To remove the listing from the control panel, on the proxmox server:
# rm /etc/pve/nodes/<server_name>/openvz/<vmid>.conf

Friday, July 19, 2013

Turnkey Linux Service Credentials

I have noticed that several Turnkey Linux containers say the password for logging in is "set at first boot", but have not been able to see any such thing happening.

I found a post that says to use "turnkey" as default password and I'll be darned if it didn't work.

Apache proxy to redmine server

I've been struggling with this for awhile. I have a virtual apache server, and turnkey linux container with redmine running and I want the main server to delegate requests to the /redmine/ folder to the redmine server.

I set up the proxy statements on the primary server, but all the followup requests for css, js, images whatever would be looking back in the main server's root again instead of on the redmine sever.

I had to add the following line to the end of /var/www/redmine/config/environment.rb

ActionController::Base.relative_url_root = "/redmine"


And that did the trick.... I have no idea how rails does whatever it does.

Wednesday, July 17, 2013

Tagging versions in GIT

As stated in the title, I use this blog to remember stuff, so here is yet another GIT tip.

Adding a tag for a given version:

$ git tag -a v1.4 -m 'my version 1.4'

Displaying tagged versions:
$ git tag
v0.1
v1.3
v1.4

Monday, May 20, 2013

Using awk to work on data files

In order to average numbers in a file we can use awk as so:
$ cat meyer-heavy.txt | awk '{ sum+=$1;count++ } END {print sum/count}'
To find the largest value:
$ cat meyer-heavy.txt | awk 'BEGIN{max=-9999} $1 > max {print $1; max=$1}' 
Improved version (only prints largest value, not intermediate ones): 
$ cat meyer-heavy.txt | awk 'BEGIN{max=-9999} $1 > max {max=$1} END{print max}'
To find the smallest value:
$ cat meyer-heavy.txt | awk 'BEGIN{min=9999} $1 < min { print $1; min=$1 }' 
Fixed version (doesn't assign blank lines as min value): 
$ cat meyer-heavy.txt | awk 'BEGIN{min=9999} /\-[0-9]+/&&$1 < min { min=$1 } END{print min}'
Where $1 is for column 1, use $2 for column 2 etc...

Thursday, May 16, 2013

Grep and recursion

Grep has for a long time had a recursive option "-r" but I have never been able to get it to do what I want because if you write
$ grep -r test *.txt
The *.txt part specifies the files to look in, and since the folders I want to recurse don't end with .txt it doesn't recurse into them.
The correct way to cause grep to recurse is to specify file patterns separately.
$ grep -r test --include "*.txt" ./

Friday, May 10, 2013

Getting the correct default paper size in LibreOffice Writer


For years OpenOffice/LibreOffice has ticked me off by endeavoring to give me documents that after I walk down the hall to the printer, are asking for A4 sized paper, though I live in the US where we use "Letter" sized paper.

Even though I set the defaults for LibreOffice, and even though the printer and any printer settings are ALL set to Letter.

Well, I found this documentation of what is a really stupid way to have to make this change actually happen. Create a template, and set it as "default" and I guess this works.


  1. Create a document and the content and formatting styles that you want.
  2. Choose File - Templates - Save.
  3. In the New Template box, type a name for the new template.
  4. In the Categories list, select "My Templates", and then click OK.
  5. Choose File - Templates - Organize.
  6. In the Templates list, double-click the "My Templates" folder.
  7. Right-click the template that you created, and choose Set as Default Template.
  8. Click Close.

Now if I can only get Impress to stop setting my default language as Finnish...

Tuesday, May 7, 2013

Git tutorial

While on the subject of danielmiessler.com, I noticed his GIT tutorial which is really easy to read:
http://danielmiessler.com/study/git/

Using tcpdump

One thing I can never seem to remember is how to get tcpdump to show entire packets.

The option is -s (for snaplength). So either -s 1514 or -s 0 will cause tcpdump to capture entire packets.

More good info on using tcpdump is at danielmiessler.com/study/tcpdump/.