Line

sshfs timeout fix

0 January 28th, 2012

FUSE sshfs is a great module, but with the defaults in ssh_config, it behaves poorly. After ~5 minutes of inactivity the service will timeout without reconnecting. Totally freezes all open files in the virutal sshfs. Only recourse is kill -9

I must have fixed this on a previous system, but forgotten. Now my arch guest in Virtual Box is behaving bad as result. Hope I remember it now!

Add these lines to /etc/ssh_config:

ServerAliveInterval 15
ServerAliveCountMax 3

Increase if necessary.

Colorize thread numbers in log4net output

0 December 29th, 2011

Working with multi-threaded applications is a PITA. Especially in C#. We use log4net a lot, so I cooked up this perl script to help with debugging the mutli-threaded logs.

It just colorizes the thread number in the textual log4net output. Could be easily modified to colorize other things as well.

#!/bin/perl

# colorize thread numbers in textual log4net output
# usage like:
#   tail -n 40  | perl threads.pl
#   tail -n 200 | perl thread.pl | less

# adjust these colors as necessary to get pretty ones.
my @colors = (5, 20, 30, 40, 60, 80, 90);

my %cmap = ();

while (<>) {
    for ($i = 0; $i < 15; $i++) {
        if (m/\[$i\]/g) {
            my $color;
            if (exists($cmap{$i})) {
                $color = $cmap{$i};
            }
            else {
                $color = shift(@colors) . "m";
                $cmap{$i} = $color;
            }
            #print $color . " ";
            s/(\[$i\])/\x1b[48;5;$color$1\x1b[0m/g;
        }
    }
    print $_;
}

So we get this:
color

rxvt-unicode hacks

0 June 24th, 2011

I posted this awhile on linuxquestions.org:

http://www.linuxquestions.org/questions/slackware-14/rxvt-unicode-hacking-800818/

For any command-line junkies who favor rxvt-unicode, after years of struggle, here are a couple of things that changed my life:

256-color support and clickable URLs:
http://heipei.net/2009/01/04/rxvt-unicode-906-with-256-colors-and-clickable-links/

Disable horizontal scroll mode, i.e. make long commands word-wrap in rxvt-unicode:
http://lists.freebsd.org/pipermail/freebsd-bugs/2007-October/026337.html
[Solved by adding an entry for urxvt in /etc/termcap]

Some other useful resources for using the full power of 256 colors ! :
http://graypine.com/data/colorstuff.zip
Include is:
256color.pl – displays all colors in a grid
colortest – displays color, hex name, decimal name

Now truly rxvt-unicode is the ultimate, since xterm (afaik) doesn’t have transparency OR click-able links.

Very happy slacker.

PHP 5.3 Slackware 13.37 – ERROR: ‘phpize’ failed with pecl install dbase

0 June 24th, 2011

When using ‘pecl install dbase’ I got that error listed.  There is a patch here: http://kai.mactane.org/blog/2009/05/11/workaround-for-pearpecl-failure-with-message-error-phpize-failed/

for Builder.php which worked wonders, fixed it real good.

Thanks, coyote!

Perl Enlightenment

0 June 2nd, 2011

Some good reading… been getting very curious about the internals and implementations of data-structures in various high-level languages. Certainly a good sign.

http://stackoverflow.com/questions/3130336/how-are-arrays-implemented-in-perl

http://perldoc.perl.org/index-internals.html

http://www.perlmonks.org/?node_id=17890

http://perldoc.perl.org/perlguts.html#NAME

One-click post to facebook

0 February 25th, 2011

The goal here is to make a one-click button which will do the following.

- Determine if the user is logged into Facebook, and if not present them with a login session.
- Ask user for permission to post to their wall.
- Post a pre-determined message to the user’s wall

Luckily, this is all really easy using the Facebook Graph API.  There is a well written Facebook PHP SDK of the api implemented, that’s what I’m using.

First, you’ll need to register your app with facebook, somewhere here:
http://www.facebook.com/developers/apps.php
You’ll receive an App Id and a App Secret from facebook.

Next, download the php sdk to your webserver:

$ curl -L http://github.com/facebook/php-sdk/tarball/master | tar xvz

Make sure to include facebook.php.

echo "Posting to facebook..";

require './fb_src/facebook.php';

$facebook = new Facebook(array(
  'appId'  => 'YOUR_APP_ID',
  'secret' => 'YOUR_SECRET',
  'cookie' => true,
));

$session = $facebook->getSession();
$me = null;
if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    header('Location: ' . $facebook->getLoginUrl(array('req_perms' => 'publish_stream')));
    error_log($e);
  }
}
else {
  header('Location: ' . $facebook->getLoginUrl(array('req_perms' => 'publish_stream')));
}

print_r($me);

try {
  $feed = $facebook->api('/me/feed', 'post', array('message' => 'Hello world!', 'cb' => ''));
} catch (FacebookApiException $e) {
  print($e);
}
print_r($feed);

The above code will do just that, log in and post “Hello World!” to the user’s wall.

Useful links:

http://thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/
http://developers.facebook.com/docs/reference/api/post/

NotifyPropertyChanged with PostSharp Attribute

0 February 23rd, 2011

Using WPF, I end up implementing INotifyPropertyChanged in my classes a lot. It gets pretty repetitive weaving the event handler into all my property setters. PostSharp to the rescue!

using System;
using System.ComponentModel;
using System.Reflection;
using PostSharp.Aspects;

namespace Bityip
{
    [Serializable]
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
    public sealed class NotifyAttribute : OnMethodBoundaryAspect
    {
        public override void OnExit(MethodExecutionArgs eventArgs)
        {
            if (eventArgs == null)
                return;

            //Why are property sets not properties? they are methods?
            if ((eventArgs.Method.MemberType & MemberTypes.Method) == MemberTypes.Method &&
                eventArgs.Method.Name.StartsWith("set_"))
            {
                var theType = eventArgs.Method.ReflectedType;
                var propertyName = eventArgs.Method.Name.Substring(4);

                // get the field storing the delegate list that are stored by the event.
                var fields = theType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
                FieldInfo field = null;
                foreach (FieldInfo f in fields)
                {
                    if (f.FieldType == typeof (PropertyChangedEventHandler))
                    {
                        field = f;
                        break;
                    }
                }

                if (field != null)
                {
                    // get the value of the field
                    var evHandler = field.GetValue(eventArgs.Instance) as PropertyChangedEventHandler;

                    // invoke the delegate if it's not null (aka empty)
                    if (evHandler != null)
                    {
                        evHandler.Invoke(eventArgs.Instance, new PropertyChangedEventArgs(propertyName));
                    }
                }
            }
        }
    }
}

Implement INotifyPropertyChanged as usual. Usage like:

        [Notify]
        public double X { get; private set; }

        [Notify]
        public double Y { get; private set; }

        [Notify]
        public double Z { get; private set; }

So much cleaner.

Beautiful traditional indigenous music

0 February 23rd, 2011

Check out http://zangomusic.com/lasuandsa.html

And http://www.lightningboltchichakos.com/ for some more contemporary stuff.  In fact, everything on his website is definitely worth reading.

This is also an awesome resource I just found: http://www.heyokamagazine.com/

I guess that’s not just about music, but close enough?

Oh, and here’s a great dictionary I just found: http://lakota-indians.narod.ru/Lakota_English.html

GMail Data API Secure AuthSub Session

0 February 23rd, 2011

The goal here is to retrieve a list of contacts, a list of groups, and organize them for presentation to the user with one request. Therefore we can’t use a single-use AuthSub token as in the previous post, but must upgrade to a secure session.

Info on retrieving groups here.

Format of XML for parsing group membership data from a contact entry here. Thus the name of the child node in the xml document we’re looking for is “groupmembershipinfo”, and the “href” attribute will contain the group id.

We need to make two requests. The first for the list of the user’s groups. From this we parse the group id and the group title to present to the user.

The second it the list of all contacts. In this list each contact entry will be associated with a group id, but not the group title, which is why need to make the first request.

Recommend making a AuthSubSession so the user doesn’t have to click “Allow” twice.

In order to do this, you must sign your token properly, info here: http://code.google.com/apis/accounts/docs/AuthSub.html#signingrequests

First you’ll need to create a certificate, follow this: http://www.ipsec-howto.org/x595.html
Then you can find some example php code here: http://gdatatips.blogspot.com/2008/07/secure-authsub-in-php.html
There is also a blog entry for using the Zend library instead of curl.

Get contacts from Gmail Contacts API

0 February 15th, 2011

Using the Gmail Data API to get contacts is really easy. The documentation is found here: http://code.google.com/apis/contacts/docs/3.0/developers_guide_protocol.html
Though I found it a bit lacking.

First, you need to register your domain with google, here:
https://www.google.com/accounts/ManageDomains

Your link should look something like this; requests the user to login, or simply grant permission to access their contacts if already logged in.


Note the ‘next=”http//www.example.com/foo?provider=gmail”‘ parameter. This must be the same as the the page set above in Google Accounts Domain Management page. This requests a one-time use token which you can now exchange for contacts. Token will be in the URL as ‘token=”xxxx”‘:

 $auth = $_GET['token'];

 $curl_headers = array();
 $curl_headers[] = 'Authorization: AuthSub token="'. $auth .'"';

 $ch = curl_init("https://www.google.com/m8/feeds/contacts/default/full?max-results=10000");
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
 curl_setopt($ch, CURLOPT_HTTPGET, true);
 curl_setopt($ch, CURLOPT_FAILONERROR, true);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_HTTPHEADER, $curl_headers);

 $res = curl_exec($ch);
 print_r($res);
 curl_close($ch);

Quick, simple, and easy!