2012
01.27

Producteev API

My first shot at a ruby gem and api client any feedback would help.

Producteev Api

2011
11.10

As i use mutt at work i had no way to lookup email address for other people. Well now i have with some nasty hacky ruby. I may clean it up etc when i have time but for now it works.
Simply add this to your mutt config


set query_command = "ruby -W0 {location of below script} '%s'"

The -W0 is needed as there is a bug in the curb gem that i am using.

require "rubygems"
require "uri"
require "curb"
require 'yaml'
require "rexml/document"
c = Curl::Easy.new("https://yourexchangeurl/ews/Exchange.asmx")
c.http_auth_types = :ntlm
c.username = 'yourusername'
c.password = 'yourpassword'
resolve_names_xml = "<?xml version='1.0' encoding='utf-8'?>
        <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
        xmlns:xsd='http://www.w3.org/2001/XMLSchema'
        xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'
        xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types'>
        <soap:Body>
        <ResolveNames xmlns='http://schemas.microsoft.com/exchange/services/2006/messages\'
        xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types\'
        ReturnFullContactData='true'>
        <UnresolvedEntry>#{ARGV[0]}</UnresolvedEntry>
        </ResolveNames>
        </soap:Body>
        </soap:Envelope>"

c.post_body=resolve_names_xml
c.headers = "Content-Type:text/xml"
c.perform

doc = REXML::Document.new(c.body_str)
displayname = ""
email = ""
puts ""
doc.root.each_recursive do |elem|
        if elem.name == "DisplayName"
                displayname = elem.text.to_s
        end
        if elem.name == "EmailAddress"
                email = elem.text.to_s
        end

        if displayname != "" and email != ""
                puts email + "  " + displayname + "     "
                email = ""
                displayname = ""
        end
end
2011
06.24

If you remove a package from a debian package and for get to add the –purge argument the package will leave its configurations files on your system. In order to view all the packages that have done this you can simply run. sudo dpkg -l | egrep "^rc" If you wish remove those configurations files you can simple run sudo aptitude purge ~c .

2011
06.12

Zotac zBox HD-ID11

After trying to get hdmi to work for the last 30 minutes, you can do the following

Change it to the deafult card you can update /usr/share/alsa/alsa.conf and change these lines:

defaults.ctl.card 0
defaults.pcm.card 0
defaults.pcm.device 0

to this:

defaults.ctl.card NVidia
defaults.pcm.card Nvidia
defaults.pcm.device 7

Once the machine reboot check that the configs are correct in gnome mixer and it should just work.

2010
10.19

DD + Lzo = superfast

I recently purchased a new laptop, (Hp Envy 14) that came pre-installed with windows. After leaving it on the hard drive for some time i finally needed the space. I shrank the partition as small as it could go but alas i have a SSD and every GB is expensive and needed.

I thought to myself what’s the best way to back this up, dd + nc was the way to go i thought. So i fired up

 dd if=/dev/sda1 | nc 192.168.1.1 

and went away. After 2 minutes i came back and did a iotop only to find it running at 22MB per second. Interesting I thought, why is it so slow running over gigabyte Ethernet to another machine.

Arrrr the other machine has a spinning metal disk storage system. So lets try this again,

 dd if=/dev/sda1 | pv | gzip -c | nc 192.168.1.1 

I added the PV so i could see what was going on ( read more about pv here ). Ok now its running at 25MB per second, WTF its eating all my CPU and that’s now the limiting factor.

Ok after some time I thought what about lzo, OK it’s not amazing at compressing things, but its relatively CPU inexpensive. I only really knew about this after working with it on the Hadoop cluster at work. After compiling lzop i gave it a shot.

dd if=/dev/sda1 | pv | lzop -c |nc 192.168.1.1 8000 

After watching it for 1 minutes the normal throughput was abut 52MB per second. Giving me a massive speed increase, doubling the throughput. The limiting factor now is the disk at the other end. I could start playing with LZO compression options as my CPU is only running at 50% but its faster enough for me now.

2010
09.03

Here is the xf86-input-synaptics driver portage overlay needed to work with the kernel patch in my previous post. xf86-input-synaptics

2010
09.03

Here is a patch set that will get the envy14 working correct with gentoo and linux-2.6.34-gentoo-r6. They are mostly patches that i have found of the net, with some of mine sprinkled in, id credit the original authors but i have lost the links.
Please comment on this posts if you know where they came from and ill give credit to the original authors. linux-patches-envy14-inux-2.6.34-gentoo-r6.tar

2010
09.02

After purchasing a new wireless card of ebay. I found out that it was a preproduction knock off. You can see Intels view on this . In order to get it working on linux you need to hack the driver. This is a hack and i mean a hack, it took me 2 seconds but now my wireless card is working.

iwl-eeprom.c.patch


--- linux-2.6.34-gentoo-r1-orig/drivers/net/wireless/iwlwifi/iwl-eeprom.c	2010-05-16 23:17:36.000000000 +0200
+++ linux-2.6.34-gentoo-r1/drivers/net/wireless/iwlwifi/iwl-eeprom.c	2010-09-02 19:04:12.672222822 +0200
@@ -618,10 +618,10 @@
 	eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
 	calib_ver = priv->cfg->ops->lib->eeprom_ops.calib_version(priv);

-	if (eeprom_ver < priv->cfg->eeprom_ver ||
+/*	if (eeprom_ver < priv->cfg->eeprom_ver ||
 	    calib_ver < priv->cfg->eeprom_calib_ver)
 		goto err;
-
+*/
 	return 0;
 err:
 	IWL_ERR(priv, "Unsupported (too old) EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
2010
06.17

I only wanted to run a script if the machine had a specific network access so i constructed this below.

How to find the machines ip address

ifconfig eth0 | grep "inet addr" | awk -F: '{ print $2 }' | awk '{ print $1 }'

Then find out if its on a network we care about

ifconfig eth0 | grep "inet addr" | awk -F: '{ print $2 }' | awk '{ print $1 }' |  grep -qE '172\.24|25\.[0-9]{1,3}\.[0-9]{1,3}' ; echo $?

Another option would be to use facter to get your IP address.

2010
06.12

Have you ever had the need to read standard input in a bash script, for example

cat /var/log/message | mycoolbashscript.sh

Well i did when wrapping msmtp for use with mutt see the example bellow

#!/bin/bash
all=`cat "/dev/stdin"`

if `/sbin/ifconfig eth0 | /bin/grep "inet addr" | /usr/bin/awk -F: '{ print $2 }' | /usr/bin/awk '{ print $1 }' |  /bin/grep -qE '172\.31|32\.[0-9]{1,3}\.[0-9]{1,3}'`; then
echo "$all" | tsocks msmtp -a account $*
else
echo "$all" | msmtp -a account $*
fi

I then setup mutt to use this as the sendmail binary

set sendmail="~/utils/sendmail.sh"

This basically reads, if im in the network 172.31 or 172.32 then run msmtp through tsocks if not then just run msmtp, this allowed me to use tsocks to proxyfy msmtp under certain circumstances. But i could also do other things like read the from header and switch the account msmtp uses to send the mail. It passes all standard input to the msmtp binary as well as all the command arguments passed to my sendmail.sh.

Although im sure other people can create more interesting uses.