Find that pc

2009/01/27

Assume that you are in a big network where the ip addresses are given via dhcp.
Assume also that you want to be able to communicate with the same pc which can change the ip address every time it reboots.

One easy and “legal” way to always find is using netbios, a protocol that makes a computer shout over the network it’s pairing Name -> IP address.

For windows and macosx this works out of the box, for linux/bsd machines you can just set a minimal smb.conf like this.

[global]
	workgroup = WORKGROUP
	server string = My Samba Server
	netbios name = koala

It’s useful to have the correct pairing right in /etc/hosts for every kind of command line program that doesn’t speak netbios.
So we’ll use nmblookup and sed for the task.
Just substitute the netbios name that you need here:

export koala=$(nmblookup koala | sed -n 2p | cut -d ' ' -f 1)
# Now I can substitute the right ip in /etc/hosts
sed "/koala/ s/.*/$koala\tkoala" < /etc/hosts > /tmp/hosts
sudo mv /etc/hosts /etc/hosts.bak
sudo mv /tmp/hosts /etc/hosts

Maybe you also want to modify sudoers to use it without inserting a password each time.


Automating the interaction

2009/01/22

A pretty nice feature of shell scripting is “<<" operator.
It allows basically to launch interactive commands within a bash script.

For example I wanted to add a small but very useful function to textmate, I want to be able to know all the possible informations about a whatever function or data type.

The default info function in the haskell bundle unfortunately is only able to retrieve informations about prelude functions or functions used with the full path.
(eg Data.List.lookup and not simply lookup ).

Using ghci I should load the file (which automatically loads also the needed libraries) and type :info.
This is really easily done using “<<".

I added a command “info about” with the following code in my haskell bundle and now if the file is correct (it compiles) you are sure that you’ll get the informations about the function you’re looking for.

GHCI << EOF
:load $TM_FILEPATH
:info ${TM_SELECTED_TEXT:-$TM_CURRENT_WORD}
EOF

I also think that there should be a better way to communicate with ghci (and using System.Enviroment to get the arguments) but I didn’t find any, this solution even if not really elegant works pretty well.

This “approach” can be used also with many interpreters, sometimes I find it really useful.


Life behing a proxy

2009/01/19

Staying behind a proxy can be very annoying, with macosx it’s nice and easy to set a global proxy.
Unfortunately command line programs don’t care about those settings, so we have to manually set them every time.

With the script you’ll find below we set globally the proxy for ftp, http, rsync and subversion:

Read the rest of this entry »


Multilanguage and multiparadigm navigator 3/n Python implementation

2009/01/14

Now it starts the interesting part, we’ll actually go to see one language a time the real program.
The program that given the input we’ve seen in the previous chapter gives us a kind of useful output.

The program is divided in a few different parts:

  • Parsing command line options
  • Setting up data structures needed
  • Executing Floyd Warshall algorithm
  • Building the output and writing it to file
  • Optionally we can also graph the result using the library pydot and passing the “-d” flag from the command line.

    Read the rest of this entry »


    Multilanguage and multiparadigm navigator 2/n Input generator

    2009/01/06

    In this second post we’ll see how to implement correct and configurable input generator for our problem.

    This script is used to generate two simple output files in the form:

  • Mapfile: [Number of cities] [List of cities] [Distance table]
  • PathFile: [List of cities]

    both separated by dots.

    For example the map file could be:

    5.CASALBELTRAME.FONTANILE.GASPERINA.INVERSO.MEANA.0.4.-1.-1.-1.4.0.8.6.9.-1.8.0.-1.-1.-1.6.-1.0.-1.-1.9.-1.-1.0.

    And the path file:

    INVERSO.CASALBELTRAME.MEANA.GASPERINA.INVERSO.

    The source code here below can also be downloaded together with a list of cities (necessary to make the randomization).

    Read the rest of this entry »


  • Follow

    Get every new post delivered to your Inbox.