Recommended books

How to install Nginx from source, Ruby Enterprise Edition, and Phusion Passenger

Shell Script (Bash) posted 10 months ago by christian

Ruby Enterprise Edition:

   1  cd /usr/local/src
   2  wget thttp://rubyforge.org/frs/download.php/66162/ruby-enterprise-1.8.7-2009.10.tar.gz
   3  tar zxvf ruby-enterprise-1.8.7-2009.10.tar.gz
   4  ./ruby-enterprise-1.8.7-2009.10/installer
   5  
   6  ln -fs /opt/ruby-enterprise-1.8.7-2009.10 /opt/ruby-enterprise/
   7   

Nginx:

   1  wget -P http://sysoev.ru/nginx/nginx-0.7.63.tar.gz
   2  tar -xzf nginx-0.7.63.tar.gz
   3   

Phusion Passenger:

   1  gem install passenger
   2  /opt/ruby-enterprise/bin/passenger-install-nginx-module --auto --nginx-source-dir=/tmp/nginx-0.7.63 --prefix=/opt/nginx --extra-configure-flags=--with-http_ssl_module
   3   

Tagged nginx, install, passenger, ree

Handy dwm scripts.

Shell Script (Bash) posted 10 months ago by marko

Some handy dwm scripts.

Ruby gmail checker /home/marko/bin/gmail_checker.rb, which I run from cron every 5 minutes and redirect the output to /home/marko/tmp/mail. The gmail checker script is adapted from a wmii gmail checker plugin

crontab entry

   1  */5 * * * * ruby "/home/marko/bin/gmail_checker.rb" > /home/marko/tmp/mail

/home/marko/bin/gmail_checker.rb

   1  CERTPATH = '/etc/ssl/certs'
   2  def gmail_check(username, password)
   3    req = Net::HTTP::Get.new '/mail/feed/atom'
   4    req.basic_auth(username, password)
   5  
   6    http = Net::HTTP.new('mail.google.com', 443)
   7    http.use_ssl = true
   8    #http.verify_mode = OpenSSL::SSL::VERIFY_PEER
   9    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  10    http.ca_path = CERTPATH
  11  
  12    res = http.request req
  13  
  14    doc = REXML::Document.new res.body
  15    entries = doc.root.get_elements('/feed/entry')
  16    return nil if entries.length == 0
  17    title = entries[0].elements['title'].text
  18    email = entries[0].elements['author/email'].text
  19    name = entries[0].elements['author/name'].text
  20    [ title, email, name, entries.length ]
  21  end
  22  
  23  require 'net/https'
  24  require 'rexml/document'
  25  
  26  require 'timeout'
  27  begin
  28    timeout(2) do
  29      username = "myemailaddress@aktagon.com"
  30      password = "p4ssw0rd"
  31  
  32      first = gmail_check(username, password)
  33      if first
  34        title, email, name, count = first
  35        user, domain = email.split('@')
  36        puts("(#{count}) #{user}:#{title}")
  37      end
  38    end
  39    rescue Timeout::Error
  40  end
  41  

Battery status checker in Ruby. Adapted for dwm from wmii-ruby standard plugin

/home/marko/bin/batstat.rb (updated to use acpi for wider support)

   1  #!/usr/bin/ruby
   2  fd = IO.popen("/usr/bin/acpi")
   3  acpi_status = fd.readlines.to_s.chomp
   4  fd.close
   5  status = '='
   6  status = '^' if acpi_status =~ /harging/
   7  status = 'v' if acpi_status =~ /ischarging/
   8  percentage = /\d+(?=%)/.match(acpi_status)[0].to_i
   9  if acpi_status =~ /ischarging/ && percentage <= 5
  10    system("echo 'Critical battery' | xmessage -center -buttons quit:0 -default quit -file - &")
  11  elsif acpi_status =~ /ischarging/ && percentage <= 8
  12    system("echo 'Low battery' | xmessage -center -buttons quit:0 -default quit -file - &")
  13  end
  14  puts status + percentage.to_s + "%" + status

Then finally the status bar, which is run from .xinitrc.

/home/marko/bin/status

   1  #!/bin/bash
   2  echo "$(cat ~/tmp/mail) | $(date +"w%U %d.%m.%Y %R") | $(ruby ~/bin/batstat.rb)"

/home/marko/.xinitrc

   1  xscreensaver-command -exit
   2  xscreensaver -no-splash &
   3  while true
   4  do
   5  xsetroot -name "$(status)"
   6    sleep 1m
   7  done &
   8  xrandr --output VGA --mode 1920x1200 --right-of LVDS
   9  #xrandr --output VGA --mode 1920x1080 --left-of LVDS
  10  
  11  exec dwm

Tagged dwm, gmail checker, status bar, ruby battery status

Xen templates

Shell Script (Bash) posted 10 months ago by christian

Description here…

   1  # Docs
   2  http://wiki.debian.org/Xen?highlight=((DebianInstaller|Xen))#DomU.28guest.29
   3  
   4  # 20 Gb disk image
   5  dd if=/dev/zero of=/srv/xen/mailserver.img oflag=direct bs=1M seek=20470 count=1
   6  
   7  # Copy template
   8  cp template.cfg domu.cfg
   9  
  10  # Edit template
  11  xxx
  12  
  13  # Start domU
  14  xm create -c domu.cfg

Tagged xen, template

Easy todo script

Shell Script (Bash) posted 10 months ago by marko

Create this into your path, edit the paths in the script, make it executable and start using it. Props to Niklas for sharing this idea!

I created the file as ~/bin/note and created symlinks from it to ~/bin/contact, ~/bin/password and ~/bin/todo.

   1  #!/bin/bash
   2  note=$(basename $0)
   3  tmp_file=/tmp/$(date +%d%m%Y-%T-%N)
   4  note_file=/work/real_work/$note
   5  gvim -f $tmp_file
   6  echo "=== $(date +%d%m%Y-%T) ===" >> $note_file
   7  cat $tmp_file >> $note_file
   8  rm $tmp_file

Tagged simple todo list, simple contact management, simple password management, simple notes

How to install memcached on OSX Snow Leopard

Shell Script (Bash) posted 11 months ago by christian

These instructions are from wincent.com:

   1  cd /usr/local/src
   2  curl -O http://www.monkey.org/~provos/libevent-1.4.12-stable.tar.gz
   3  tar xzvf libevent-1.4.12-stable.tar.gz 
   4  cd libevent-1.4.12-stable
   5  ./configure
   6  make
   7  make verify
   8  sudo make install
   9  
  10  
  11  cd /usr/local/src
  12  curl -O http://memcached.googlecode.com/files/memcached-1.4.1.tar.gz
  13  tar xzvf memcached-1.4.1.tar.gz 
  14   cd memcached-1.4.1
  15  ./configure
  16  make
  17  make test
  18  sudo make install
  19  
  20  memcached -d -P pidfile -l 127.0.0.1

Tagged memcached, install, snowleopard