<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Moiristo's Weblog</title>
	<atom:link href="http://moiristo.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://moiristo.wordpress.com</link>
	<description>We can't stop here, this is bat country!</description>
	<lastBuildDate>Mon, 05 Oct 2009 15:58:59 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='moiristo.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/f2a7fa173c552c72a3d68397be79d3b8?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Moiristo's Weblog</title>
		<link>http://moiristo.wordpress.com</link>
	</image>
			<item>
		<title>Samba: Logging User Activity</title>
		<link>http://moiristo.wordpress.com/2009/08/10/samba-logging-user-activity/</link>
		<comments>http://moiristo.wordpress.com/2009/08/10/samba-logging-user-activity/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 10:52:35 +0000</pubDate>
		<dc:creator>moiristo</dc:creator>
				<category><![CDATA[samba]]></category>
		<category><![CDATA[activity]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[monitoring]]></category>

		<guid isPermaLink="false">http://moiristo.wordpress.com/?p=127</guid>
		<description><![CDATA[Ever wondered why Samba seems to log so many things, except what you&#8217;re interested in? So did I, and it took me a while to find out that 1) there actually is a solution and 2) how to configure this. Here&#8217;s how.
The solution to logging what a user is actually doing can be achieved with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=127&subd=moiristo&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Ever wondered why Samba seems to log so many things, except what you&#8217;re interested in? So did I, and it took me a while to find out that 1) there actually is a solution and 2) how to configure this. Here&#8217;s how.</p>
<p>The solution to logging what a user is actually doing can be achieved with <a href="http://us5.samba.org/samba/docs/man/Samba-HOWTO-Collection/VFS.html">Stackable VFS Modules</a>, which is available since Samba 3. Unfortunately, the link there does not describe the <code>full_audit</code> module, which I highly recommend using instead of <code>audit </code> or <code>extd_audit</code>. The reason for this is that I couldn&#8217;t get those modules to log simple things like a file upload by a user, unless I chose VFS log level 10.</p>
<h2>Using the Full_audit VFS Module</h2>
<p>If you&#8217;re running Debian unstable like I do, then <a href="http://www.z4.cn/kit/man?command=vfs_full_audit">full_audit</a> is included when installed from the APT. To find out which modules you have, take a look in <code>/usr/lib/samba/vfs</code>. When you&#8217;re sure you have the module, configure it as follows in <code>smb.conf</code>:</p>
<pre class="brush: bash;">
    vfs objects = full_audit

    full_audit:prefix = %u|%I|%m|%S
    full_audit:success = mkdir rename unlink rmdir pwrite
    full_audit:failure = none
    full_audit:facility = LOCAL7
    full_audit:priority = NOTICE
</pre>
<p>Let&#8217;s go through it one line at a time.</p>
<ul>
<li><code>vfs objects</code>: we&#8217;d like to use the full_audit module. </li>
<li><code>full_audit:prefix</code>: Every line that full_audit outputs will be prefixed by this line, in which you can use <a href="http://www.faqs.org/docs/samba/ch06.html#samba2-CHP-6-TABLE-2">Samba variables</a>. This line will prefix the username, IP, machine name and share name, separated by pipes.</li>
<li><code>full_audit:success</code>: This specifies which actions will actually be logged when it has successfully been completed. <code>unlink</code> is in this case a delete action and <code>pwrite</code> is an upload action.</li>
<li><code>full_audit:failure</code>: Specifies which actions should be logged, but which have resulted in a failure. Since a failure will often mean that nothing has been changed, I found that it is not interesting to log any of these actions.</li>
<li><code>full_audit:facility</code>: By default, full_audit will only write to the system syslog, but you can specify a different &#8217;syslog facility&#8217; to write all output to a different log file. Custom syslog facilities should be named <code>local[number]</code>, where <code>number</code> is a number between 0 and 7 (don&#8217;t ask me why syslogd doesn&#8217;t support any name). I&#8217;ll get back on this later.</li>
<li><code>full_audit:priority</code>: This line sets the severity of the log messages that are generated, like &#8216;notice&#8217;, &#8216;info&#8217;, &#8216;warning&#8217;, &#8216;debug&#8217;, &#8216;alert&#8217;. There are probably more, but these are the most well-known ones.</li>
</ul>
<h2>Creating a Syslogd Facility</h2>
<p>To specify a custom log file to which full_audit should write, you should create a new syslogd facility. A facility can be described in <a href="http://linux.die.net/man/5/syslog.conf">syslog.conf</a>. Since I had chosen the facility <code>local7</code>, I can add that facility to the configuration like this:</p>
<pre class="brush: bash;">
local7.*                        /var/log/samba/log.audit
</pre>
<p>This line means that all log messages of facility <code>local7</code> will be written to <code>/var/log/samba/log.audit</code>. The star is needed to say that I&#8217;d like to log messages of any severity to the same log file. Finally, restart the <code>syslogd</code> daemon: <code>/etc/init.d/sysklogd restart<br />
</code></p>
<h2>Final Words</h2>
<ul>
<li>When things don&#8217;t seem to be working, ensure you have restarted/reloaded syslogd and samba.</li>
<li>If there is anything bad you could say about full_audit, then it would be that it can&#8217;t output log messages to the log file specified in smb.conf. I always found it very useful that Samba could log by machine name by specifying <code>log file = /var/log/samba/log.%m</code>, but full_audit cannot use this. If you find a way though, please let me know!</li>
<li>Other references: A blog in a language I can&#8217;t read where I took the configuration part from: <a href="http://kannyd.multiply.com/journal/item/48/Monitoring_Aktivitas_Samba">Monitoring Aktivitas Samba</a></li>
</ul>
<h2>Output Example</h2>
<p>Here is an example of what the configuration just explained generates:</p>
<pre class="brush: bash;">
Aug 10 11:52:52 rhino smbd_audit: moiristo|123.45.67.89|moiristo|moiristo|unlink|ok|public/Upload/hypnotoad.gif
Aug 10 11:52:59 rhino smbd_audit: moiristo|123.45.67.89|moiristo|moiristo|pwrite|ok|public/Upload/hypnotoad.gif
Aug 10 11:53:41 rhino smbd_audit: moiristo|123.45.67.89|moiristo|moiristo|rename|ok|public/Upload/hypnotoad.gif|public/Upload/hypnotoads.gif
Aug 10 11:53:51 rhino smbd_audit: moiristo|123.45.67.89|moiristo|moiristo|rename|ok|public/Upload/hypnotoads.gif|public/Upload/hypnotoad.gif
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moiristo.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moiristo.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moiristo.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moiristo.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moiristo.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moiristo.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moiristo.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moiristo.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moiristo.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moiristo.wordpress.com/127/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=127&subd=moiristo&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://moiristo.wordpress.com/2009/08/10/samba-logging-user-activity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">moiristo</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby: Checking if a string is all letters</title>
		<link>http://moiristo.wordpress.com/2009/06/04/ruby-checking-if-a-string-is-all-letters/</link>
		<comments>http://moiristo.wordpress.com/2009/06/04/ruby-checking-if-a-string-is-all-letters/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 12:07:06 +0000</pubDate>
		<dc:creator>moiristo</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby string letters]]></category>

		<guid isPermaLink="false">http://moiristo.wordpress.com/?p=115</guid>
		<description><![CDATA[Looking at the stats on my previous post, I noticed a lot of people are wrongly redirected when they&#8217;re looking for a solution to check if a ruby string is all letters. For those, I&#8217;d like to post my solution, which is imo a clean way of doing it:

def all_letters(str)
	# Use 'str[/[a-zA-Z]*/] == str' to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=115&subd=moiristo&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Looking at the stats on my previous post, I noticed a lot of people are wrongly redirected when they&#8217;re looking for a solution to check if a ruby string is all letters. For those, I&#8217;d like to post my solution, which is imo a clean way of doing it:</p>
<pre class="brush: ruby;">
def all_letters(str)
	# Use 'str[/[a-zA-Z]*/] == str' to let all_letters
	# yield true for the empty string
	str[/[a-zA-Z]+/]  == str
end
</pre>
<p>Analogous, we can do this with digits as well:</p>
<pre class="brush: ruby;">
def all_digits(str)
	str[/[0-9]+/]  == str
end

def all_letters_or_digits(str)
	str[/[a-zA-Z0-9]+/]  == str
end
</pre>
<p>Of course, it&#8217;s even better if you make these methods a core extension of String itself <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moiristo.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moiristo.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moiristo.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moiristo.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moiristo.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moiristo.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moiristo.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moiristo.wordpress.com/115/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moiristo.wordpress.com/115/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moiristo.wordpress.com/115/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=115&subd=moiristo&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://moiristo.wordpress.com/2009/06/04/ruby-checking-if-a-string-is-all-letters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">moiristo</media:title>
		</media:content>
	</item>
		<item>
		<title>Successor: Ruby String.succ For Java</title>
		<link>http://moiristo.wordpress.com/2009/05/26/successor-ruby-stringsucc-for-java/</link>
		<comments>http://moiristo.wordpress.com/2009/05/26/successor-ruby-stringsucc-for-java/#comments</comments>
		<pubDate>Tue, 26 May 2009 09:23:47 +0000</pubDate>
		<dc:creator>moiristo</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[lexicographic]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[successor]]></category>

		<guid isPermaLink="false">http://moiristo.wordpress.com/?p=105</guid>
		<description><![CDATA[For my master thesis I&#8217;m working on a Java application that should allow you to specify string intervals. A string interval can be specified by defining a start string and an end string, from which the system should be able to generate a list of successive strings in lexicographical order. 
Knowing of the function string.succ [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=105&subd=moiristo&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>For my master thesis I&#8217;m working on a Java application that should allow you to specify string intervals. A string interval can be specified by defining a start string and an end string, from which the system should be able to generate a list of successive strings in lexicographical order. </p>
<p>Knowing of the function string.succ in Ruby and the ability to specify string ranges, I figured that something similar would also exist in Java. After browsing the webs for hours, I didn&#8217;t find anything however. Moreover, even C# with all its extra convenience methods doesn&#8217;t come with this (see also Mack Allen&#8217;s post <a href="http://allen-mack.blogspot.com/2008/07/c-succ.html">here</a>)! </p>
<p>The code below is my stab at creating string.succ in Java. It (mostly) does exactly the same thing as the Ruby version. Mostly I say, try for example the range <code>("test1".."test10")</code> in irb and <code>Successor.range("test1","test10",false)</code> in a java console. </p>
<p>See the <code>main()</code> function for examples! </p>
<p>Update 5-6-2009: Made it a lot shorter by getting rid of the helper classes, which turned out to be overkill.</p>
<pre class="brush: java;">
/**
 * Successor.java: A utility class for generating string successors.
 *
 * Copyright (c) 2009, R de Lange
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
import java.util.*;
import java.io.*;

/**
* The Successor utility class can be used to find string successors or
* to generate lists of successive strings.
*
* @author    R de Lange
* @created   June 5, 2009
*/
public class Successor {

	/**
	*	Main class to test Successor. Examples taken from Ruby string#succ.
	*
	*	Call						should yield
	*	Successor.succ(&quot;abcd&quot;)      #=&gt; &quot;abce&quot;
	*	Successor.succ(&quot;THX1138&quot;)   #=&gt; &quot;THX1139&quot;
	*	Successor.succ(&quot;&lt;&lt;koala&gt;&gt;&quot;) #=&gt; &quot;&lt;&lt;koalb&gt;&gt;&quot;
	*	Successor.succ(&quot;1999zzz&quot;)   #=&gt; &quot;2000aaa&quot;
	*	Successor.succ(&quot;ZZZ9999&quot;)   #=&gt; &quot;AAAA0000&quot;
	*	Successor.succ(&quot;***&quot;)       #=&gt; &quot;**+&quot;
	*
	*	- For an interactive console interface for testing Successor.succ(str), specify the -i argument
	*	- To test successor ranges using Successor.range(str), specify the -r argument. Adding an arbitrary
	*	extra argument (e.g. -r e) will toggle the 'exclusive' boolean for successor ranges.
	*/
	public static void main(String[] args) throws Exception{
		if(args.length == 0){
			System.out.println(&quot;Running Successor examples...&quot;);
			System.out.println(&quot;abcd #=&gt; &quot; + Successor.succ(&quot;abcd&quot;));
			System.out.println(&quot;THX1138 #=&gt; &quot; + Successor.succ(&quot;THX1138&quot;));
			System.out.println(&quot;&lt;&lt;koala&gt;&gt; #=&gt; &quot; + Successor.succ(&quot;&lt;&lt;koala&gt;&gt;&quot;));
			System.out.println(&quot;1999zzz #=&gt; &quot; + Successor.succ(&quot;1999zzz&quot;));
			System.out.println(&quot;ZZZ9999 #=&gt; &quot; + Successor.succ(&quot;ZZZ9999&quot;));
			System.out.println(&quot;*** #=&gt; &quot; + Successor.succ(&quot;***&quot;));
		}
		else {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			String command = args[0];
			if(command.equals(&quot;-i&quot;)) {
				String line = &quot;&quot;;
				while(!line.equals(&quot;quit&quot;)){
					System.out.print(&quot;String? &quot;);
					line = in.readLine();
					if(!line.equals(&quot;quit&quot;)) System.out.println(Successor.succ(line));
				}
			}
			else if(command.equals(&quot;-r&quot;)) {
				String left = &quot;&quot;, right=&quot;&quot;;
				while(true){
					System.out.print(&quot;Left? &quot;);
					left = in.readLine();
					System.out.print(&quot;Right? &quot;);
					right = in.readLine();
					System.out.println(Arrays.deepToString(Successor.range(left, right, args.length == 2).toArray()));
				}
			}
		}
	}

	/**
	* Returns the successor to str. The successor is calculated by incrementing characters starting from the rightmost
	* alphanumeric (or the rightmost character if there are no alphanumerics) in the string. Incrementing a digit always
	* results in another digit, and incrementing a letter results in another letter of the same case. Incrementing
	* nonalphanumerics uses the system default character set's collating sequence. If the increment generates a 'carry',
	* the character to the left of it is incremented. This process repeats until there is no carry, adding an additional
	* character if necessary.
	*/
	public static String succ(String str){
		char[] cstr = str.toCharArray();
		if(cstr.length == 0) return &quot;&quot;;

		int letterOrDigitIndex = getLastLetterOrDigitIndex(cstr, cstr.length-1);
		if(letterOrDigitIndex &gt;= 0)
			return alphanumSucc(cstr, letterOrDigitIndex);
		else {
            // Increment rightmost character
            cstr[cstr.length-1] = (char) (cstr[cstr.length-1] + 1);
            return new String(cstr);
        }
	}

	/**
	* Alias of Successor.succ(str)
	*/
	public static String next(String str){ return Successor.succ(str); }

	/**
	* Returns a range of string successors as a list. Starting from str1, this method will add all successors
	* to a list until the successor string equals str2. If the 'exclusive' boolean is true, str2 will be included
	* in the resulting list, otherwise excluded. If the successor str2 is not found after generating half a million
	* successors, the range is assumed to be invalid, in which case it will return an empty list.
	*/
	public static List&lt;String&gt; range(String str1, String str2, boolean exclusive){
		int counter, limit = 500000;
		ArrayList&lt;String&gt; result = new ArrayList&lt;String&gt;();

		result.add(str1);
		String currentSuccessor = str1;
		for(counter = 0;counter&lt;=limit &amp;&amp; !currentSuccessor.equals(str2); counter++){
			currentSuccessor = Successor.succ(currentSuccessor);
			if((currentSuccessor.equals(str2) &amp;&amp; !exclusive)|| !currentSuccessor.equals(str2))
				result.add(currentSuccessor);
		}
		if(counter &gt; limit) {
			System.err.println(&quot;Range could not be created, level too deep.&quot;);
			result.clear();
		}
		return result;
	}

	/**
	* Calculates the successive string for strings that contain alphanumeric characters.
	* See the description of Successor.succ(str) for more informtionon this function
	*/
	private static String alphanumSucc(char[] cstr, int lastLetterOrDigitIndex){
		char succ = charSucc(cstr[lastLetterOrDigitIndex]);

		int currentIndex = lastLetterOrDigitIndex;
        cstr[currentIndex] = succ;

		// Loop while we have a carry
		while(succHasCarry(succ) &amp;&amp; lastLetterOrDigitIndex &gt;= 0){
			lastLetterOrDigitIndex = getLastLetterOrDigitIndex(cstr, lastLetterOrDigitIndex-1);
			if(lastLetterOrDigitIndex &gt;= 0) {
				currentIndex = lastLetterOrDigitIndex;
				succ = charSucc(cstr[currentIndex]);
				cstr[currentIndex] = succ;
			}
		}

		// Check if we still have a carry left
		if(succHasCarry(succ)) cstr = insertCarry(cstr, succ, currentIndex);

		// Finished!
		return new String(cstr);
	}

	/**
	* Create a new array in which the given carry is inserted at the given index
	* @return A new char array of length cstr.length+1, which contains all values of
	* cstr + the carry char inserted at the given index.
	*/
	private static char[] insertCarry(char[] cstr, char carry, int index){
		char[] result = new char[cstr.length+1];
		System.arraycopy(cstr,0,result,0,index+1);
		result[index] = carry;
		System.arraycopy(cstr,index,result,index+1,cstr.length);
		return result;
	}

	/**
	* Determines whether the given char array contains alphanumeric characters
	* @return the highest index at which an alphanumeric character can be found, or -1 if none were found
	*/
	private static int getLastLetterOrDigitIndex(char[] cstr, int lastIndex){
		int result = -1;
		for(int i=lastIndex;i&gt;=0 &amp;&amp; result &lt; 0;i--) {
			if(Character.isLetterOrDigit(cstr[i])) result = i;
		}
		return result;
	}

    /**
     * Determines if a given *successor* character (returned by charSucc(char c)) is a
     * character with a carry.
     *
     * @param c - the successor char
     * @return true if c is '0', 'a' or 'A'.
     */
    private static boolean succHasCarry(char c){
        return c == '0' || c == 'a' || c == 'A';
    }

    /**
     * Determines the successor of the given char
     * @param c - the char
     * @return the successor of char c
     */
    private static char charSucc(char c) {
        char result;

        switch(c) {
            case '9': result = '0'; break;
            case 'z': result = 'a'; break;
            case 'Z': result = 'A'; break;
            default: result = (char) (c + 1);
        }

        return result;
    }
}
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moiristo.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moiristo.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moiristo.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moiristo.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moiristo.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moiristo.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moiristo.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moiristo.wordpress.com/105/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moiristo.wordpress.com/105/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moiristo.wordpress.com/105/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=105&subd=moiristo&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://moiristo.wordpress.com/2009/05/26/successor-ruby-stringsucc-for-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">moiristo</media:title>
		</media:content>
	</item>
		<item>
		<title>Executing smbstatus as non-root user</title>
		<link>http://moiristo.wordpress.com/2009/02/16/executing-smbstatus-as-non-root-user/</link>
		<comments>http://moiristo.wordpress.com/2009/02/16/executing-smbstatus-as-non-root-user/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 22:58:45 +0000</pubDate>
		<dc:creator>moiristo</dc:creator>
				<category><![CDATA[samba]]></category>
		<category><![CDATA[smb]]></category>

		<guid isPermaLink="false">http://moiristo.wordpress.com/?p=95</guid>
		<description><![CDATA[I found that after upgrading to samba 3 (Debian 2.6.15 unstable), I was unable to execute smbstatus as a non-root user. This was very inconvenient, since I was using a PHP script to track which users are connected to my server (see my previous post). The error that occurs looks as follows:

ERROR: Failed to initialise [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=95&subd=moiristo&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I found that after upgrading to samba 3 (Debian 2.6.15 unstable), I was unable to execute <code>smbstatus</code> as a non-root user. This was very inconvenient, since I was using a PHP script to track which users are connected to my server (see my previous post). The error that occurs looks as follows:<br />
<code><br />
ERROR: Failed to initialise messages database: Permission denied<br />
messaging_tdb_init failed: NT_STATUS_ACCESS_DENIED<br />
messaging_init failed<br />
</code></p>
<p>Making <code>smbstatus</code> suid root unfortunately didn&#8217;t do the trick. Taking a closer look at the error suggested that it got to do with the *.tdb files that samba is using. So, I went to the folder containing these files (for me <code>/var/run/samba/*.tdb</code>). All these database files were chmodded to 644, so only enabled rw permissions to root. </p>
<p>By changing the permissions of <code>messages.tdb</code> to 666 (rw permissions on world, if you find this to devil-ish, 646 would also do the trick <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ) a normal user can also open the database file and thus everything worked again. Of course, you should keep in mind that this may pose a security risk.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moiristo.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moiristo.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moiristo.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moiristo.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moiristo.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moiristo.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moiristo.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moiristo.wordpress.com/95/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moiristo.wordpress.com/95/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moiristo.wordpress.com/95/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=95&subd=moiristo&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://moiristo.wordpress.com/2009/02/16/executing-smbstatus-as-non-root-user/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">moiristo</media:title>
		</media:content>
	</item>
		<item>
		<title>Monitoring Samba from a web page using smbstatus</title>
		<link>http://moiristo.wordpress.com/2008/12/14/monitoring-samba-using-smbstatus/</link>
		<comments>http://moiristo.wordpress.com/2008/12/14/monitoring-samba-using-smbstatus/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 12:22:11 +0000</pubDate>
		<dc:creator>moiristo</dc:creator>
				<category><![CDATA[samba]]></category>
		<category><![CDATA[monitor]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[smbstatus]]></category>

		<guid isPermaLink="false">http://moiristo.wordpress.com/?p=77</guid>
		<description><![CDATA[A long time ago, I found that I needed something to be able to see which users are logged in using samba and kick users as necessary. The usual way is to check the currently logged in users using smbstatus and kicking users by killing the smb process belonging to a user. To make this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=77&subd=moiristo&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>A long time ago, I found that I needed something to be able to see which users are logged in using samba and kick users as necessary. The usual way is to check the currently logged in users using smbstatus and kicking users by killing the smb process belonging to a user. To make this a bit easier, I made a small webpage in *cough*PHP*cough*. Hey, it was 2 years ago! <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Anyway, I still find it very useful, so maybe it&#8217;s useful to you, too.</p>
<pre class="brush: php;">
&lt;?
error_reporting(0);

if(isset($_GET['kill'])){
	echo shell_exec(&quot;sudo /scripts/smbkill &quot;.$_GET['kill'].&quot; 2&gt;&amp;1&quot;);
	}

exec(&quot;smbstatus -S&quot;,$log);
exec(&quot;smbstatus -L&quot;,$lock);

$pid_us = array();
for($i=3;$i&lt;sizeof($log);$i++)
	if(!trim($log[$i])==&quot;&quot;) {
		$users[] = split(&quot;[ ]+&quot;,$log[$i],4);
		$pid_us[$users[sizeof($users)-1][1]] = $users[sizeof($users)-1][2];
		}
for($i=3;$i&lt;sizeof($lock);$i++)
	if(!trim($lock[$i])==&quot;&quot;) {
			$line = split(&quot;[ ]+&quot;,$lock[$i],7);
			$usr = $pid_us[$line[0]];
			if(trim($usr)==&quot;&quot;) $usr = $line[0];
			$locks[$line[0]][] = array($line[0],$usr,substr_replace($line[6],&quot;&quot;,-25));	//Remove date (25 chars from the right
		}

//die(&quot;&quot;);

echo &quot;&lt;br /&gt;&quot;;
echo &quot;&lt;font style=\&quot;font-family: Verdana;\&quot;&gt;Connected users:&lt;/font&gt;\n&quot;;
echo &quot;&lt;br /&gt;&lt;br /&gt;&quot;;
echo &quot;&lt;table&gt;\n&quot;;
foreach($users as $user){
	list($service,$pid,$mach,$date) = $user;
	echo &quot;&lt;tr\n&gt;&quot;;
	echo &quot;&lt;td&gt;&lt;a onclick=\&quot;return confirm('Kick this user?');\&quot; href=\&quot;&quot;.$PHP_SELF.&quot;?kill=&quot;.$pid.&quot;\&quot;&gt;&lt;img border=\&quot;0\&quot; src=\&quot;remove.gif\&quot; /&gt;&lt;/a&gt;&lt;/td&gt;\n&quot;;
	echo &quot;&lt;td class=\&quot;user\&quot;&gt;&quot;.$mach.&quot;&lt;/td&gt;\n&quot;;
	echo &quot;&lt;td class=\&quot;pid\&quot;&gt;&quot;.$pid.&quot;&lt;/td&gt;\n&quot;;
	echo &quot;&lt;td&gt;&quot;.$service.&quot;&lt;/td&gt;\n&quot;;
	echo &quot;&lt;td&gt;&quot;.$date.&quot;&lt;/td&gt;\n&quot;;
	echo &quot;&lt;/tr&gt;\n&quot;;
}
echo &quot;&lt;/table&gt;\n\n&quot;;

echo &quot;&lt;br /&gt;&lt;br /&gt;&quot;;
echo &quot;&lt;font style=\&quot;font-family: Verdana;\&quot;&gt;Locked files:&lt;/font&gt;\n&quot;;
echo &quot;&lt;br /&gt;&lt;br /&gt;&quot;;
echo &quot;&lt;table&gt;\n&quot;;

$cuser = &quot;&quot;;
$first = true;
foreach($locks as $l){
	foreach($l as $lck){
		list($pid, $user,$file) = $lck;
		if($user != $cuser){
			if(!$first){
				echo &quot;&lt;tr&gt;\n&quot;;
				echo &quot;&lt;td&gt;&amp;nbsp;&lt;/td&gt;\n&quot;;
				echo &quot;&lt;td&gt;&amp;nbsp;&lt;/td&gt;\n&quot;;
				echo &quot;&lt;td&gt;&amp;nbsp;&lt;/td&gt;\n&quot;;
				echo &quot;&lt;/tr&gt;\n&quot;;
				}
			echo &quot;&lt;tr&gt;\n&quot;;
			echo &quot;&lt;td class=\&quot;pid\&quot;&gt;&lt;a onclick=\&quot;return confirm('Kick this user?');\&quot; href=\&quot;&quot;.$PHP_SELF.&quot;?kill=&quot;.$pid.&quot;\&quot;&gt;&lt;img border=\&quot;0\&quot; src=\&quot;remove.gif\&quot; /&gt;&lt;/a&gt; &quot;.$pid.&quot;&lt;/td&gt;\n&quot;;
			echo &quot;&lt;td class=\&quot;user\&quot;&gt;&quot;.$user.&quot;&lt;/td&gt;\n&quot;;
			echo &quot;&lt;td&gt;&quot;.$file.&quot;&lt;/td&gt;\n&quot;;
			echo &quot;&lt;/tr&gt;\n&quot;;
			$cuser = $user;
			}
		else {
			echo &quot;&lt;tr&gt;\n&quot;;
			echo &quot;&lt;td&gt;&amp;nbsp;&lt;/td&gt;\n&quot;;
			echo &quot;&lt;td&gt;&amp;nbsp;&lt;/td&gt;\n&quot;;
			echo &quot;&lt;td&gt;&quot;.$file.&quot;&lt;/td&gt;\n&quot;;
			echo &quot;&lt;/tr&gt;\n&quot;;
			}
		$first = false;
		}
}
echo &quot;&lt;/table&gt;\n&quot;;
?&gt;
</pre>
<p>Note that you should of course make sure that only you are able to access the page and execute the kill command, so you&#8217;ll need to get creative with <code>sudo</code> and <code>htaccess</code> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Image used: <img src="http://moiristo.files.wordpress.com/2008/12/remove.gif?w=13&#038;h=13" alt="remove" title="remove" width="13" height="13" class="alignnone size-full wp-image-85" /></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moiristo.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moiristo.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moiristo.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moiristo.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moiristo.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moiristo.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moiristo.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moiristo.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moiristo.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moiristo.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=77&subd=moiristo&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://moiristo.wordpress.com/2008/12/14/monitoring-samba-using-smbstatus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">moiristo</media:title>
		</media:content>

		<media:content url="http://moiristo.files.wordpress.com/2008/12/remove.gif" medium="image">
			<media:title type="html">remove</media:title>
		</media:content>
	</item>
		<item>
		<title>Sorting IMAP Mail with Imapfilter</title>
		<link>http://moiristo.wordpress.com/2008/11/18/sorting-imap-mail-with-imapfilter/</link>
		<comments>http://moiristo.wordpress.com/2008/11/18/sorting-imap-mail-with-imapfilter/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 16:19:08 +0000</pubDate>
		<dc:creator>moiristo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sort]]></category>

		<guid isPermaLink="false">http://moiristo.wordpress.com/?p=73</guid>
		<description><![CDATA[The situation is as follows: I have multiple IMAP mail accounts on multiple servers and access these mailboxes from multiple computers using different e-mail clients. Per mailbox, I have multiple folders that contain messages regarding a certain subject. To be sure that new mail appears in the folder it belongs to, I have set up [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=73&subd=moiristo&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The situation is as follows: I have multiple IMAP mail accounts on multiple servers and access these mailboxes from multiple computers using different e-mail clients. Per mailbox, I have multiple folders that contain messages regarding a certain subject. To be sure that new mail appears in the folder it belongs to, I have set up message filters on every e-mail client. The trouble is, for every new folder I had to alter the filters on every client. </p>
<p>As a solution, I left one computer always running with Thunderbird active, but since I already have a linux server running (terminal access only), I was thinking whether there was something available that was able to sort my messages, which I can alter from the command line and doesn&#8217;t involve a graphical frontend. </p>
<p><a href="http://imapfilter.hellug.gr/">Imapfilter</a> did the job for me. Although I don&#8217;t have any experience in Lua, in which it is written, I managed to successfully sort my mail. You can install it from source, but there is also a Debian package available from the apt (at least, from repository unstable). Below I&#8217;ll describe how I configured imapfilter, since there is not much information around on this (there are however some small examples described in a sample config file).</p>
<p>After install, first run imapfilter as a normal user. This will create the directory <code>~/.imapfilter</code> with appropriate permissions. Enter that directory and create a new file  named <code>config.lua</code>. In this file, you should first define some global options, then your IMAP accounts, followed by the filters (rules) that should be applied to the messages in your mailboxes.</p>
<p>The global options are defined in a lua table variable named <code>options</code>. A table in lua is much like a hash in Ruby. I have defined the following options:</p>
<pre class="brush: ruby;">
  options.timeout = 120
  options.subscribe = true
</pre>
<p>The meaning of these options is described on the imapfilter homepage.<br />
Definitions of IMAP accounts look like this:</p>
<pre class="brush: ruby;">
account1 = IMAP {
	   	server = 'imap.example.com',
		username = 'user',
		password = 'pass',
		ssl = 'ssl3'
	}

account2 = IMAP {
	   	server = 'imap2.example.com',
		username = 'user',
		password = 'pass'
	}
</pre>
<p>As you can see, imapfilter also supports SSL (you need to have OpenSSL installed though). You can define all your IMAP accounts like this.</p>
<p>Next, I define the sorting rules. Note that I mostly move messages from the inbox of an account to a folder of the same account. This is however not necessary, it is also possible to transfer messages from one account to the other. Example 1:</p>
<pre class="brush: ruby;">
   msgs = account1.INBOX:contain_from('MediaPortal')
   account1.INBOX:move_messages(account1.MediaPortal, msgs)
</pre>
<p>The first example is simple: find all messages in the INBOX in which the sender contains the name MediaPortal and move those messages to the MediaPortal folder.<br />
Now, a more complex example:  </p>
<pre class="brush: ruby;">
 msgs = 	account2.INBOX:contain_from('Cron') +
		account2.INBOX:contain_from('Log') +
		account2.INBOX:contain_subject('yum')
 account2.INBOX:mark_seen(msgs)
 account2.INBOX:move_messages(account2['Maildir/Admin Notifications'], msgs)
</pre>
<p>What you need to know here is that the &#8216;+&#8217; operator means &#8216;or&#8217;. So, I put all messages that are from &#8216;Cron&#8217;, &#8216;Log&#8217; or have the subject &#8216;yum&#8217; in the variable <code>msgs</code>, I mark all those messages as read and finally move them to the &#8216;Admin Notifications folder&#8217;. As you can see, this account uses the Maildir directory.</p>
<p>You can debug your configuration by running <code>imapfilter -d</code> or <code>imapfilter -v</code>. To run these rules frequently, I finally had to run this code in daemon mode. To achieve this, I had to enclose all the above code in a function and pass that function in the become_daemon() function:</p>
<pre class="brush: ruby;">
-- global options

function sortMail()
   -- IMAP account definitions
   -- rules
end

become_daemon(300, sortMail)
</pre>
<p>Note that I had to include the account definitions in the function; it seems the accounts are also initialized when defined and it wouldn&#8217;t work anymore when these definitions were outside the function. The above example will run imapfilter as a daemon and execute the sortMail function every 300 seconds.</p>
<p>Some final remarks that may save you some time:</p>
<ul>
<li>There are problems selecting/searching messages when you&#8217;re running an Exchange server. I tried several things to get it working properly, but nothing worked. This could be dependent on the configuration or version of the Exchange server however.</li>
<li>Be sure you add the IMAP definitions to the function called in daemon mode</li>
<li>if you don&#8217;t know exactly which folders you have or should define, you can add some debugging code to find out:</li>
</ul>
<pre class="brush: ruby;">
-- Inbox information
account1.INBOX:check_status()

-- Get and print available mailboxes and folders
mailboxes, folders = account1:list_all()
table.foreach(mailboxes,print)
table.foreach(folders,print)
</pre>
<p>Fore more information and examples, see also the imapfilter homepage: <a href="http://imapfilter.hellug.gr">http://imapfilter.hellug.gr</a></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moiristo.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moiristo.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moiristo.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moiristo.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moiristo.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moiristo.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moiristo.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moiristo.wordpress.com/73/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moiristo.wordpress.com/73/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moiristo.wordpress.com/73/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=73&subd=moiristo&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://moiristo.wordpress.com/2008/11/18/sorting-imap-mail-with-imapfilter/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">moiristo</media:title>
		</media:content>
	</item>
		<item>
		<title>Snippet: Binary to YAML</title>
		<link>http://moiristo.wordpress.com/2008/11/01/snippet-binary-to-yaml/</link>
		<comments>http://moiristo.wordpress.com/2008/11/01/snippet-binary-to-yaml/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 14:21:00 +0000</pubDate>
		<dc:creator>moiristo</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://moiristo.wordpress.com/?p=71</guid>
		<description><![CDATA[Recently, I was looking for a piece of code that could easily convert a file to YAML data. Here is what I use now. It follows the format described in http://yaml.org/type/binary.html.

def binary_to_yaml(file, indent_level = 1)
  if File.exists?(file)
    indent = &#34;&#34;
    indent_level.times{ indent &#60;&#60; &#34; &#34; }
   [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=71&subd=moiristo&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Recently, I was looking for a piece of code that could easily convert a file to YAML data. Here is what I use now. It follows the format described in http://yaml.org/type/binary.html.</p>
<pre class="brush: ruby;">
def binary_to_yaml(file, indent_level = 1)
  if File.exists?(file)
    indent = &quot;&quot;
    indent_level.times{ indent &lt;&lt; &quot; &quot; }
    data = File.open(file,'rb').read
    #YAML Generic binary representation, see http://yaml.org/type/binary.html
    &quot;!binary |\n#{indent}#{[data].pack('m').gsub(/\n/,&quot;\n#{indent}&quot;)}\n&quot;
  end
end
</pre>
<p>The indent level describes how many spaces should be prepended. A binary value for a key that is unnested should have indent level 1. See the example below:</p>
<pre class="brush: ruby;">
user: # indent level 1
 name: John Doe # indent level 2
 address:
  street: Sunset Blvd # indent level 3
  number: 2034
 thumbnail: &lt;%= binary_to_yaml('files/thumb.jpg',2) %&gt; # indent level 2

user: # indent level 1
 name: Jane Doe # indent level 2
 ...
</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moiristo.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moiristo.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moiristo.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moiristo.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moiristo.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moiristo.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moiristo.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moiristo.wordpress.com/71/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moiristo.wordpress.com/71/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moiristo.wordpress.com/71/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=71&subd=moiristo&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://moiristo.wordpress.com/2008/11/01/snippet-binary-to-yaml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">moiristo</media:title>
		</media:content>
	</item>
		<item>
		<title>RailsConf 2008: LowPro</title>
		<link>http://moiristo.wordpress.com/2008/10/11/railsconf-2008-lessons-learned-part-1-lowpro/</link>
		<comments>http://moiristo.wordpress.com/2008/10/11/railsconf-2008-lessons-learned-part-1-lowpro/#comments</comments>
		<pubDate>Sat, 11 Oct 2008 16:34:22 +0000</pubDate>
		<dc:creator>moiristo</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[lowpro]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[unobtrusive js]]></category>

		<guid isPermaLink="false">http://moiristo.wordpress.com/?p=67</guid>
		<description><![CDATA[Although my colleagues agreed RailsConf 2008 was &#8216;less interesting than the last time&#8217;, there were some interesting presentations I&#8217;d like to give some extra attention. 
First and foremost, I was very excited about a presentation of LowPro, an extension to prototype to easily ajaxify your webapp with unobtrusive javascript. Forget about link_to_remote, submit_to_remote and remote_form_for, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=67&subd=moiristo&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Although my colleagues agreed RailsConf 2008 was &#8216;less interesting than the last time&#8217;, there were some interesting presentations I&#8217;d like to give some extra attention. </p>
<p>First and foremost, I was very excited about a presentation of LowPro, an extension to prototype to easily ajaxify your webapp with unobtrusive javascript. Forget about link_to_remote, submit_to_remote and remote_form_for, which yield blocks of ugly inline javascript. Instead, consider this script to send a form using AJAX:</p>
<pre class="brush: ruby;">
Event.addBehavior({
  '#add_form' : function() {
    this.hide();
  },
  '#add_new_link:click' : function() {
    $('add_form').toggle();
    return false;
  },
  '#add_form' : Remote.Form
});
</pre>
<p>Using <code>Event.addBehavior</code>, you can add behaviors to elements specified by CSS selectors. When this piece of code is included in your static, non-javascript webapp, it will &#8216;hijack&#8217; click and submit events only when javascript is enabled.<br />
I have done something similar in a project of my own, which should update a page when a month was selected in a combobox. Note that this example does not use LowPro itself. If javascript was disabled, a button should be displayed to manually submit the form containing the combobox. So, my static page (<code>statistics.html.erb</code>) would look like this:</p>
<pre class="brush: ruby;">
&lt;% form_tag example_url, :method =&gt; :get, :id =&gt; 'months-form', :class =&gt; 'months-form' do %&gt;
  &lt;div&gt;
	&lt;%= select_tag :month, @available_months.collect{ |month| &quot;&lt;option value=\&quot;#{month.to_s}\&quot; #{(@curr_moneht.same_month?(month)) ? 'selected=&quot;selected&quot;' : '' }&gt;#{month.strftime(&quot;%B %Y&quot;)}&lt;/option&gt;&quot; }.join %&gt;
	&lt;%= submit_tag 'view', :id =&gt; 'submit-button' %&gt;
  &lt;/div&gt;
&lt;% end %&gt;
</pre>
<p>To add a dash of Javascript to this without touching this perfectly fine code, I just need to include a javascript file that should handle the form submission. Let&#8217;s call it <code>statistics.js</code>:</p>
<pre class="brush: ruby;">
&lt;% content_for :content_for_js do %&gt;
   &lt;%= javascript_include_tag 'statistics' %&gt;
&lt;% end %&gt;
</pre>
<p>And finally, the javascript that should prevent manual form submission and hide the view button when javascript is available:</p>
<pre class="brush: ruby;">
Event.observe(window, 'load', observeMonthField);

function observeMonthField() {
    $('submit-button').hide();
    $('month').observe('change', function(event) {
      $('months-form').submit();
    });
}
</pre>
<p>Easy peasy lemon squeezy!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moiristo.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moiristo.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moiristo.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moiristo.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moiristo.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moiristo.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moiristo.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moiristo.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moiristo.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moiristo.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=67&subd=moiristo&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://moiristo.wordpress.com/2008/10/11/railsconf-2008-lessons-learned-part-1-lowpro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">moiristo</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby Core &amp; Ruby on Rails CHM Documentation</title>
		<link>http://moiristo.wordpress.com/2008/08/28/ruby-core-ruby-on-rails-chm-documentation/</link>
		<comments>http://moiristo.wordpress.com/2008/08/28/ruby-core-ruby-on-rails-chm-documentation/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 00:04:45 +0000</pubDate>
		<dc:creator>moiristo</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[chm]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rdoc]]></category>

		<guid isPermaLink="false">http://moiristo.wordpress.com/?p=55</guid>
		<description><![CDATA[Today, my company&#8217;s internet provider managed to cut off the internet connection for the whole day! This made me wonder why I always use the online available Ruby &#38; RoR APIs, while having them offline would give me faster loading times and doesn&#8217;t require an internet connection (although that situation is probably the same as [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=55&subd=moiristo&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Today, my company&#8217;s internet provider managed to cut off the internet connection for the whole day! This made me wonder why I always use the online available Ruby &amp; RoR APIs, while having them offline would give me faster loading times and doesn&#8217;t require an internet connection (although that situation is probably the same as being cut off from water for most of us <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  ). </p>
<h2>Download</h2>
<p>There is a <a href="http://rubyforge.org/frs/?group_id=5928">project page</a> on sourceforge that contains CHM documentation for Ruby 1.8.6 and Rails 2.3.</p>
<h2>Do it yourself</h2>
<p>Rdoc provides you with four possible formats to create your own documentation: html, xml, ri and chm. </p>
<p>To create the documentation for Ruby, go to the Ruby source directory (\src\ruby-x.x.x-pxxx) in the console and enter: <code>rdoc -f [format] -o [destination-folder]</code>.</p>
<p>To create the documentation for Rails, go to the ruby gems directory (i.e. \lib\ruby\gems\1.8\gems) and enter: <code>rdoc -f [format] -x test/* -x template/* -o [destination-folder] action* active* rails-* </code>.</p>
<p>The extra argument <code>-x template/*</code> is needed here to prevent errors from occurring during compilation, as discussed <a href="http://dirk.net/2007/12/30/generate-ruby-on-rails-chm-documentation/">here</a>. This problem occurs for both html and chm compilation.</p>
<p>Update 16-12-2008: When generating the Rails documentation, a good idea is to also add <code>-x test/*</code> to the command, since you&#8217;ll probably don&#8217;t need the documentation of Rails&#8217;s test classes, which are included in the gems. </p>
<p>If you are using windows, you might like the CHM format (the Windows Helpfile format). To be able to create CHM files, you&#8217;ll need <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/htmlhelp/html/vsconHH1Start.asp">HTML Help Workshop</a>. Install it in C:\Program Files\HTML Help Workshop\, even if you are running Windows x64. </p>
<p>Update 16-12-2008: A small list of locations of gem home directories:</p>
<ul>
<li>Windows:
<ul>
<li>C:\ruby\lib\ruby\gems\1.8\gems</li>
</ul>
</li>
<li>Mac OS X
<ul>
<li>/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/user-gems/1.8/gems (included version)</li>
<li>/usr/local/lib/ruby/gems/1.8/gems/</li>
</ul>
</li>
</ul>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/moiristo.wordpress.com/55/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/moiristo.wordpress.com/55/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moiristo.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moiristo.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moiristo.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moiristo.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moiristo.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moiristo.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moiristo.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moiristo.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moiristo.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moiristo.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=55&subd=moiristo&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://moiristo.wordpress.com/2008/08/28/ruby-core-ruby-on-rails-chm-documentation/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">moiristo</media:title>
		</media:content>
	</item>
		<item>
		<title>Content_for Sorta Nested Layouts</title>
		<link>http://moiristo.wordpress.com/2008/08/16/content_for-sorta-nested-layouts/</link>
		<comments>http://moiristo.wordpress.com/2008/08/16/content_for-sorta-nested-layouts/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 09:07:19 +0000</pubDate>
		<dc:creator>moiristo</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[rails content_for nested layouts]]></category>

		<guid isPermaLink="false">http://moiristo.wordpress.com/?p=49</guid>
		<description><![CDATA[For my latest project, I needed to insert a small piece of code into all views belonging to a controller. At first, I had solved this by adding a partial to every view, but I thought it would be nice to DRY it up a little more and create some sort of nested layout within [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=49&subd=moiristo&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>For my latest project, I needed to insert a small piece of code into all views belonging to a controller. At first, I had solved this by adding a partial to every view, but I thought it would be nice to DRY it up a little more and create some sort of nested layout within the main layout. <a href="http://www.mattmccray.com/archive/2007/02/19/Sorta_Nested_Layouts">This article</a> by Matt McCray explained how I could easily achieve this by yielding within a partial, specified by a sub_layout method in the controller. The only disadvantage I found was that content_for constructions within the nested layout were not evaluated in this way, while the small piece of extra layout had its own css and javascript, too.</p>
<p>In order for content_for blocks to be evaluated, it needs to be yielded. The simple solution I therefore came up with was to yield the nested-layout-partial itself from a content_for defined in the main layout:</p>
<pre class="brush: ruby;">
&lt;% content_for :with_nested_layout, render(:partial=&gt; &quot;layouts/#{controller.sub_layout}&quot;) %&gt;
&lt;html&gt;
 &lt;head&gt;
  &lt;title&gt;Nested layout example&lt;/title&gt;
  &lt;%= stylesheet_link_tag 'common', 'clearfix' %&gt;
  &lt;%= javascript_include_tag :all %&gt;
  &lt;%= yield :content_for_css %&gt;
  &lt;%= yield :content_for_js %&gt;
 &lt;/head&gt;
 &lt;body&gt;
  &lt;div id=&quot;main&quot; class=&quot;clearfix&quot;&gt;
   &lt;%= yield_flash_messages -%&gt;
   &lt;%= yield :with_nested_layout %&gt;
  &lt;/div&gt;
 &lt;/body&gt;
&lt;/html&gt;
</pre>
<p>This way, I can specify <code>content_for :content_for_css</code> and <code>:content_for_js</code> in the nested layout, which are evaluated because the partial itself is yielded, too. Of course this can be considered as a &#8216;dirty hack&#8217;, and I do agree to some extent, but it&#8217;s only two lines of code and it works like a charm, so I forgave myself for implementing it this way <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/moiristo.wordpress.com/49/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/moiristo.wordpress.com/49/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/moiristo.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/moiristo.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/moiristo.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/moiristo.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/moiristo.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/moiristo.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/moiristo.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/moiristo.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/moiristo.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/moiristo.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=moiristo.wordpress.com&blog=4269683&post=49&subd=moiristo&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://moiristo.wordpress.com/2008/08/16/content_for-sorta-nested-layouts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="" medium="image">
			<media:title type="html">moiristo</media:title>
		</media:content>
	</item>
	</channel>
</rss>