Software, Physics, Data, Mountains

...and other random associations

Sshfs-mount-from-python

#!/usr/bin/python
#
# from http://ubuntuforums.org/showthread.php?p=1932551
#

import os
import sys
import getopt

host = '10.37.129.2'

mount_points = [('/Users/dave/Music', '/home/dave/Music'),
        ('/Users/dave/Documents', '/home/dave/Documents'),
        ('/Users/dave/Pictures', '/home/dave/Pictures')]

def main(argv=None):
    if argv is None:
        argv = sys.argv
    try:
        opts, args = getopt.getopt(argv[1:], 'u', ['unmount'])
    except getopt.error, msg:
        print msg
        print 'for help use --help'
        sys.exit(2)
    mount_op = mount
    for option, a in opts:
        if option in ('-u', '--unmount'):
            mount_op = unmount
    mount_op()    
    return 0

def mount():
    argv = ['/usr/bin/sshfs', None, None]
    for mount in mount_points:
        argv[1] = '%s:%s' % (host, mount[0])
        argv[2] = mount[1]
        cmd = ' '.join(argv)
        print cmd
        os.system(cmd)

def unmount():
    argv = ['/usr/bin/fusermount', '-u', None]
    for mount in mount_points:
        argv[2] = mount[1]
        cmd = ' '.join(argv)
        print cmd
        os.system(cmd)

if __name__ == '__main__':
    sys.exit(main())

Google Cli

google picasa create --title="ParkCity"
google picasa post --title="ParkCity" *.*

Gource

From gource docs:

Linux / Mac

You can create a video of Gource using the –output-ppm-stream option. This creates an uncompressed sequence of screenshots in PPM format which can then be processed by another program (such as ffmpeg) to produce a video. The below command line will create a video at 60fps in x264 format (assumes you have ffmpeg with x264 support):

gource --disable-progress --stop-at-end --output-ppm-stream - | ffmpeg -y -b 3000K -r 60 -f image2pipe -vcodec ppm -i - -vcodec libx264 gource.mp4

Note: You may need to add one of ‘-vpre default’, ‘-vpre libx264-default’ or ‘-fpre /path/to/libx264-default.ffpreset’ to get ffmpeg to work. The arguments for ffmpeg may vary depending on the version you have. There is a good guide to using x264 with ffmpeg here.

You can also adjust the output frame rate with –output-framerate. Note you will need to adjust the frame rate used by the encoder (eg ffmpeg -r) as well.

Howto-nconf-ubuntu

go to

http://digitalcardboard.com/blog/2010/08/24/nagios-and-nconf-on-ubuntu-10-04-lucid-lynx/

Send Basecamp Message

This was cobbled together from other stuff… no longer have the links

require 'net/https'

class BasecampMessage

  #curl -H 'Accept: application/xml' -H 'Content-Type: application/xml' \
  #     -u hoodlum:up2n0g00d \
  #     -d '<todo-item><content>...</content></todo-item>' \
  #     http://url/todo_lists/123/todo_items.xml

  #https://agiledynamics.basecamphq.com/projects/<project_id>/posts

  # this works
  # curl -H 'Accept: application/xml' -H 'Content-Type: application/xml' -u <user>:<pass> https://agiledynamics.basecamphq.com/projects/<project_id>/posts

  #<request>
  #  <post>
  #    <category-id>#{category_id}</category-id>
  #    <title>#{title}</title>
  #    <body>#{body}</body>
  #    <private>1</private> <!-- only for firm employees -->
  #  </post>
  #  <notify>#{person_id}</notify>
  #  <notify>#{person_id}</notify>
  #  ...
  #  <attachments>
  #    <name>#{name}</name> <!-- optional -->
  #    <file>
  #      <file>#{temp_id}</file> <!-- the id of the previously uploaded file -->
  #      <content-type>#{content_type}</content-type>
  #      <original_filename>#{original_filename}</original-filename>
  #    </file>
  #  </attachments>
  #  <attachments>...</attachments>
  #  ...
  #</request>

  BASECAMP_SETTINGS = {
    :subdomain  => 'XXX',
    :username   => 'XXX',
    :password   => 'XXX',
    :ssl        => true
  }

  def self.update_message( environment, release, revision )

    http = Net::HTTP.new("#{BASECAMP_SETTINGS[:subdomain]}.basecamphq.com", BASECAMP_SETTINGS[:ssl] ? 443 : 80)

    # if using ssl, then set it up
    if BASECAMP_SETTINGS[:ssl]
      http.use_ssl = true
      http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    end

    begin
      request = Net::HTTP::Post.new("/projects/<project_id>/posts.xml?formatted=true", {'Content-type' => 'application/xml'})
      request.basic_auth BASECAMP_SETTINGS[:username], BASECAMP_SETTINGS[:password]
      request.body = "<post><title>What's on #{environment.to_s.capitalize}?</title><body>Changeset [sw:#{revision}] deployed on #{DateTime.parse(release)} (UTC).  You can see the [History for #{environment.to_s.capitalize}] (/projects/<project_id>/repositories/<repo_id>/history/#{environment.to_s}/ \"History for #{environment.to_s.capitalize}\").</body></post>"

      response = http.request(request)
      if response.code == "201"
        puts "Message Created: #{response['Location']}"
      else
        # hmmm...we must have done something wrong
        puts "HTTP Status Code: #{response.code}."
      end
    rescue => e
      puts "exception: #{e.to_s}"
      print e.backtrace
    end

  end
  
end

Google Spreadsheet

regular excel:

=Sheet1.A31

google spreadsheet:

=Sheet1!$A$31

Mimic Dropbox

this is from http://news.ycombinator.com/item?id=429573

#-------- ~/backup.command -----------

# Backup up home dir using git. Note the full path to git (needed for cron jobs):
cd ~/
/opt/local/bin/git add . 
/opt/local/bin/git commit -a -m "home dir backup"
/opt/local/bin/git pull
/opt/local/bin/git push

# Backup binary stuff using rsync
rsync -Cauvzd  /Users/Shared/Music/ user@server:/var/backups/music
rsync -Cauvzd  /Users/Shared/Photos/ user@server:/var/backups/photos

so the plan would be to clone the dropbox

git clone mydropbox@hawk:/home/mydropbox/var/MyDropBox.git

and copy over the sync script

scp mydropbox@hawk:/home/mydropbox/bin/sync-MyDropBox.sh .

and then run it in a cronjob…

SHELL=/bin/bash
PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin
MAILTO=mark.mims@agiledynamics.com
HOME=/home/mmm

# m h  dom mon dow   command

*/10 * * * *  $HOME/bin/sync-MyDropBox.sh

the sync script looks like

#!/bin/bash

MY_DROP_BOX=${HOME}/MyDropBox
MY_DROP_BOX_SERVER="mydropbox@hawk:/home/mydropbox/"
GIT=/usr/bin/git
RSYNC=/usr/bin/rsync

if [ -d $MY_DROP_BOX ]
then
  cd $MY_DROP_BOX
  $GIT add .
  $GIT commit -a -m'MyDropBox sync'
  $GIT pull
  $GIT push
fi

for directory in Downloads Music Photos Videos
do
  rsync -Cauvzd ${MY_DROP_BOX}/${directory} ${MY_DROP_BOX_SERVER}var/binary-data/${directory}
done

Rails on Ec2

http://ec2onrails.rubyforge.org/http://ec2onrails.rubyforge.org/

http://www.zabada.com/tutorials/deploying-a-rails-application-to-production-on-amazon-ec2.php

http://pauldowman.com/projects/ruby-on-rails-ec2/

http://davidcancel.com/rubber-complex-multi-instance-rails-ec2-deployments/

http://auser.github.com/poolparty/

http://wiki.opscode.com/display/chef/Home

http://wiki.github.com/wr0ngway/rubber/

Recover Grub

grub rescue> set

see what current settings are…

set prefix=(hd2,1)/boot/grub
set root=(hd2,1)

insmod /boot/grub/linux.mod
linux /vmlinuz root=/dev/sde1 ro
initrd /initrd.img
boot