Yogsototh

GitHub behind the evil corporate firewall

Posted in Uncategorized by yogsototh on June 10, 2009

Thanks to github providing git using port 443, because it is mostly open.

Simple and efficient, create an ssh alias

> cat ~/.ssh/config
Host github
User git
Port 443
Hostname ssh.github.com

edit the file .git/config into your project :

...
[remote "github"]
url = git@github:user/Project.git
fetch = +refs/heads/*:refs/remotes/github/*

Multi-line grep

Posted in script by yogsototh on May 4, 2009

After many, many times I use many different tricks to implement a multi-line grep, I’ve done one myself I called it <code>mlegrep</code>:


#!/usr/bin/env zsh

separator='\n\n'
while [[ ${1[1]} = '-' ]]; do
    case ${1[2]} in
        F) separator="${1[3,-1]}" ; shift ;;
        *) print "unknown option : $1" >&2; exit 2 ;;
    esac
done

if (($#>1)); then
    print   "usage: $0:t [-Fseparator] REGEXP [FILE ...]" >&2
    exit 1
fi

value="$1"
shift
perl -ne 'BEGIN{$/="'$separator'";} if ( $_ =~ m/'$value'/ ) { print }' "$@"

hope this help,
Y.

YPassword v1.4

Posted in Uncategorized by yogsototh on April 2, 2009

I updated the last version of YPassword to 1.4, mostly bug correction.

More informations or direct download.

Blogged with the Flock Browser
Tagged with:

get disk usage by file type

Posted in geek by yogsototh on March 18, 2009

A simple and usefull script to evaluate usage of your disk by filetype. Should be improved
to manage extension with more than 3 letters. For this you can just replace the /\.{2,3}$/ by

/\..{2-6}$/ to accepts extension from 2 to 6 letters long.


#!/usr/bin/env zsh
if (($#<1)); then
    cible='.'
else
    cible=( "$@" )
fi
find $cible -type f -exec du -k {} \;  |  awk --posix '
{
    if ($2 ~ /\.[^/]{2,3}$/) {
        ext=$2;
        sub(/.*\./,"",ext);
    } else {
        ext="withoutExtension";
    }
    taille[ext]+=$1 ;
    nb[ext]++ ;
}
END{
    for (x in taille) {
        printf "%10d ", nb[x];
        print x" for "taille[x]" Ko";
    }
}' | sort -n

hope this is usefull

Blogged with the Flock Browser
Tagged with: , , ,

Better passwords for YPassword

Posted in geek, security by yogsototh on March 17, 2009

I recently updated YPassword to 1.3. Just added the base64 output in order to make my password shorter. See my blog entry on yannesposito.com.

From fluid to fixed layout and why

Posted in geek by yogsototh on March 14, 2009

I recently changed my mind about fixed layout in web design. Click to see why.

How to manage accessibility with iWeb

Posted in geek by yogsototh on March 2, 2009

I discovered this week-end iWeb use JavaScript to manage the navigation bar. The resulting problem is: no blog post is referenced in Google.

Now I did manage the problem with a simple trick.

  • First I opened the Web directory in the interface (I have a bug, and have to remove the Web link). It then reappear and create a second mount: yannesposito-1 which contain the Web directory on my iDisk.
  • My site’s name is YBlog

Once my iDisk Web folder was mounted then I opened a terminal and did :

cd /Volumes/yannesposito-1/Web/Sites/

{
print '<div style="display: none">'
for fic in YBlog/**/*.html(.); do
    print '<a href="/'$fic'">'$fic:t'</a><br/>'
done
print '</div>'
} > /tmp/hiddenReferences.txt

I then “copy/paste” the content of /tmp/hiddenReferences.txt into an HTML snippet in my “welcome” page.

But tonight, I’ll do a much better thing (to automatize a little more), and to prevent the problem that, in fact the iFrame is not searched by Google.

I’ll make a simple text box, relatively small and hidden, containing only one link to:

http://yannesposito.com/hiddenReferences.html

And I’ll create a script called updateiWebReferences.sh with the following content

#!/usr/bin/env zsh
WebDirectory="/Volumes/yannesposito-1/Web/Sites"
cd $WebDirectory

{
: ###### Print XHTML 1.0 Strict prefix #####
cat << END_TAG
<?xml version="1.0" encoding="utf-8"?>'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>all site references</title>
    </head>
    <body>
       <h1>All pages of my site</h1>
       <ul>
END_TAG

: ###### Add all pages with their title #####
for fic in YBlog/**/*.html(.); do
    pageTitle=$( perl -pe 'if(m#<title>(.*)</title># ) {
            if ( $1 ) { $_=$1."\n";}
            else { $_="" ; } }
        else { $_=""; }' <  $fic )
    if [[ $pageTitle = "" ]]; then
        pageTitle=span style="font-weight:bold;color:#aa55aa;">"$fic:t:gs#_# #"
    fi
    print '<li><a href="/'$fic'">'$pageTitle'</a></li>'
done

: ###### End of the XHTML page #####
cat << END_TAG
        </ul>
    </body>
</html>
END_TAG
} > $WebDirectory/hiddenReferences.html

And I’ll just have to launch this script once per new blog entry, or each time I change a blog post title, just after I published my iWeb website. And now all my blog entries are referenced in google.

Tell me if you founded this trick usefull.

Blogged with the Flock Browser

join in zsh

Posted in script by yogsototh on December 23, 2008

Unlike the join utility which make a join similar to SQL ones. Here is a function to make the same work as the join function in javascript, Perl or Python:

> join ';' 'hello world!' "I'm here!" "I'm happy"
hello world!;I'm here!;I'm happy

Here is a short solution:

function join {
    local res=""
    if (($#>0)); then
        local sep="$1"
        shift
        if (($#>0)); then
            res=$1
            shift
            while (($#>0)); do
                res=$res$sep$1
                shift
            done
        fi
    fi
    print $res
}
Blogged with the Flock Browser
Tagged with: , ,

My two cents on Cappuccino

Posted in geek by yogsototh on December 17, 2008

Here is one of my long post: My two cents on Cappuccino.

This was my first impression of Cappuccino after trying to do the tutorials.

In substance: I like the concept and I dislike the implementation. But there is very few to add to convince me.

Blogged with the Flock Browser

Redirection Wizardry

Posted in geek, script by yogsototh on December 9, 2008

or How to make two parallel pipes

Hi all,

Goal: understand the following script and why it is usefull:

{
    print "Standard"
    print "Error" >&2
    print "Main" >&3
} > >(awk '{print "BUF1: "$0}') \
2> >(awk '{print "BUF2: "$0}') \
3> >(awk '{print "BUF3: "$0}')

Problem

I write a script with:

echo "first step"
launch a complex sub command

echo "second step"
launch a complex sub command

...

It’s output should be:

first step
hello, I'm a big long complex
command which output this
And I write many things.
Here is an error message.
second step
therefore
It is difficult to see where I end

My main logs are difficult to discern and therefore should be unnoticed :-( . Most of time the sub command is not mine, and therefore, it is not easy to manage their appearance.

First solution: redirect command output

Prefix each output of the complex sub command

echo "first step"
complexSubcommand | awk '{print "\tcomplexSubcommand: "$0}'

echo "second step"
complexSubcommand2 | awk '{print "\tcomplexSubcommand2: "$0}'

OK, it is far better now:

first step
    complexSubcommand: hello, I'm a big long complex
    complexSubcommand: command which output this
    complexSubcommand: And I write many things.
Here is an error message.
second step
    complexSubcommand2: therefore
    complexSubcommand2: It is difficult to see where I end

Unfortunately the standard error is not redirected.

Second solution: redirect everything

One can do:

echo "first step"
complexSubcommand 2>&1 | awk '{print "\tcomplexSubcommand:"$0}'

echo "second step"
complexSubcommand2 2>&1 | awk '{print "\tcomplexSubcommand2:"$0}'

output is now:

first step
    complexSubcommand: hello, I'm a big long complex
    complexSubcommand: command which output this
    complexSubcommand: And I write many things.
    complexSubcommand: Here is an error message.
second step
    complexSubcommand2: therefore
    complexSubcommand2: It is difficult to see where I end

This is better, but error is lost in the flow of standard output. This is why it would be good to prefix the standard output by some string and standard error by another more visible string.

But it is not possible to implement that only with pipe or even redirection between standard output and error.

Complete solution: using named pipe

Then, a final solution is to use named pipe.
One named pipe for standard output, one for standard error and one for main messages.

Here is an example:

#!/usr/bin/env zsh

Creation of the fifos: /tmp/y/fifo1, fifo2, fifo3

fifo="/tmp/y/fifo"
mkdir -p $(dirname $fifo)
for n in 1 2 3; do
    if [[ ! -p "fifo$n" ]]; then
        mkfifo $fifo$n
    fi
done
# will print what is written in the fifo
# prefix all string written in fifoX by BUF X:
for n in 1 2 3; do
    awk "{print \"BUF $n:\"\$0}" < $fifo$n &
done
# here begins the program
{
    print "Standard"
    print "Error" >&2
    print "Main" > ${fifo}3
    # close the standard output and error
    2>&- >&-
# redirect all standard output to fifo1
# and all standard error to fifo2
} >${fifo}1 2>${fifo}2
# once the program ended
# delete the fifos
for n in 1 2 3; do
    \rm $fifo$n
done

Here is the result:

BUF 1:Standard
BUF 2:Erreur
BUF 3:Main

Final solution: use zsh syntax

Finally I recently found a way to do exactly the same with a much clearer and compact syntax. Thanks zsh:

{
    print "Standard"
    print "Error" >&2
    print "Main" >&3
} > >(awk '{print "BUF1: "$0}') \
2> >(awk '{print "BUF2: "$0}') \
3> >(awk '{print "BUF3: "$0}')

Here is the result:

BUF 1:Standard
BUF 2:Erreur
BUF 3:Main
Blogged with the Flock Browser
Tagged with: , ,