Sigmonsay

Musings and Banter

Breakdancing gorilla

without comments

What.

This primate has better moves than I do.

Breakdancing gorilla

Written by sig

June 23rd, 2011 at 9:55 pm

Posted in Uncategorized

Tagged with ,

Interesting links

without comments

Kinder egg banned in the US? Really, wtf USA.

http://www.eatliver.com/i.php?n=7410

http://news.blogs.cnn.com/2011/04/21/easter-reminder-kinder-eggs-banned-in-the-united-states/

Vancouver riots at loss

http://www.eatliver.com/i.php?n=7413

Making Love, Not War http://yfrog.com/z/h03elanp

I’m sure someone already is working on a “Will it Fry?” blog

http://www.wimp.com/friedkoolaid/

Now that’s fast, even though i’m not sure it hit 500km/h in this video..

http://www.wimp.com/maglevtrain/

I would do this in a heart beat. Although I’d be scared, the lion would sense that and likely bite
my head off.

http://www.wimp.com/lionnap/

Written by sig

June 21st, 2011 at 9:04 pm

Posted in Uncategorized

What Should I Do? Choosing SQL, NoSQL or Both

without comments

Written by sig

June 16th, 2011 at 7:29 pm

Posted in Uncategorized

Tagged with ,

how to use a phone

without comments

Written by sig

June 13th, 2011 at 6:44 am

Posted in Uncategorized

cholula, honey and rice

without comments

I was too lazy to make any real food and had some left over rice. Give it a try, it’s quite amazing.

Written by sig

June 4th, 2011 at 3:54 pm

Posted in Uncategorized

Excavator lifting itself to the top

without comments

Written by sig

June 3rd, 2011 at 10:33 pm

Posted in Uncategorized

drop dead simple HOME synchronization

without comments

Something that is always annoying to me is the setup, scripting and management of keeping a hosts files and scripts in a safe place. Well i’ve made various reincarnations of various scripts that attempt to do this. I’ll ommit the history here but wanted to drop a quick note of a drop dead simple solution that has worked pretty well for me.

drop the contents below into Makefile and git init it.

.PHONY: backup

all:
 @echo try 'make backup' or 'make restore'

backup:
 @echo backup file from system started
 rsync -arv --files-from manifest.txt / backup/
 python filemeta.py backup -P backup/
restore:
 @echo restore file to system started
 rsync -arv --files-from manifest.txt backup/ /
 python filemeta.py restore

Since git does not preserve file mode and permission I hacked up a quick script to handle backup and restore of the key file meta data (mode and ownership). Save the contents here as filemeta.py

import sys, os, stat
from optparse import OptionParser

_, cmd = sys.argv.pop(0), sys.argv.pop(0)

parser = OptionParser()
parser.add_option("-c", "--config", dest="config", help="config file", metavar="FILE", default=None)
parser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False)

parser.add_option("-f", "--file-meta", dest="file_meta", default="./file.meta", help="store file meta data path [%default]")
parser.add_option("-P", "--path", dest="path", default=".", help="path to scan [%default]")

if cmd == 'backup':
   (options, args) = parser.parse_args(sys.argv)
   path = os.path.realpath(options.path)
   file_meta = os.path.realpath(options.file_meta)
   file_meta_tmp = file_meta + ".tmp"

   fh = open(file_meta_tmp, "w+")
   for dirpath, dirnames, filenames in os.walk(path):

      st = os.stat(dirpath)
      fh.write("%d %d %d %s\n" % (st.st_mode, st.st_uid, st.st_gid, dirpath))

      for filename in filenames:
         fullpath = os.path.join(dirpath, filename)
         st = os.stat(fullpath)
         abspath = fullpath.replace(path, '')
         fh.write("%d %d %d %s\n" % (st.st_mode, st.st_uid, st.st_gid, abspath))

   fh.close()
   os.rename(file_meta_tmp, file_meta)
   print "Created", file_meta

elif cmd == 'restore':
   (options, args) = parser.parse_args(sys.argv)
   path = os.path.realpath(options.path)
   file_meta = os.path.realpath(options.file_meta)

   for line in file(file_meta):
      st_mode, st_uid, st_gid, abspath = line.split(None, 3)
      st_mode, st_uid, st_gid = int(st_mode), int(st_uid), int(st_gid)
      abspath = abspath.strip()

      if stat.S_ISDIR(st_mode) or stat.S_ISREG(st_mode):
         os.chmod(abspath, st_mode)
         os.chown(abspath, st_uid, st_gid)
      else:
         continue

else:
   raise Exception("invalid command: %s" % (cmd))

Now all you have to do is place the filenames to backup (files or directories) in manifest.txt and run ‘sudo make backup’ or ‘sudo make restore’. git commit or add backup/* and push it off to a origin of your choice. This is nothing that complex but the simple approach to this has made box recovery and migration a breeze. Lots of times you want to track something but don’t have a good place to put it. This is that place. all of those pesky $HOME/.bash_profile files are now in one place and can easily be fetched from a single location. I’ll leave branching and cherry picking to the reader.

Written by sig

May 23rd, 2011 at 1:26 am

Posted in Uncategorized

Google’s Disk Failure Experience

without comments

Written by sig

April 25th, 2011 at 3:10 pm

Posted in storage

LRU Cache in C with uthash

without comments

I thought this could be useful so i’m tagging it for later!

 

LRU Cache in C with uthash | jehiah.cz.

Written by sig

April 19th, 2011 at 11:49 pm

Posted in programming

Survey for 2-D packing algorithms

without comments

Written by sig

April 10th, 2011 at 5:21 pm

Posted in algorithms