July 31, 2010

Desktop (at) Jul 31 2010

I organize my Desktop on III trends:
  • increasing comfort;
  • decreasing effort;
  • keeping productivity constant.

Currently I sit on two screens with same X11 but no Xinerama.
All stuff orchestrated by `Ion3 Window Manager.

It feels just right despite it's 5 dimensions which I thought would be to much to use subconsciously because of my 3D habits.

My front view has Screen1 ++ Screen2,
 Each screen has Windows on `X and Desktops on `Z,
  Windows divided into Frames (`X-horizontal or `Y-vertical),
 Frame has Tabs like in Firefox which slice `X ones more.

Screen 1 Screen 2

Left monitor smaller then right. I do reading from it.

Right is for work.

Desktops organized by themes on Screen1 (Office, RTFM's etc.) and tasks on Screen 2. Tasks have usually one or two application which need full screen (Eclipse, Remote Desktop to Windows machine or remote X Session) and some small frames with terminal app's and scripts.
Fulscreeners are collapsed initially  and only when I'm focusing on the task they goes big on `Z so I still have all stuff on 2D distance. Themes also adjusted to the task to extract me required info.



Before I used Window Managers with overlapped windows. Normally it consume 5-6 desktops times 2 monitors.
Now, just 5-6 on both monitors in any time. It's contra intuitive but tiling WM save 1.2 square meters of pixels for me.

I use mouse for editing and never for navigating because I have to move it and still not able to go directly trough all Ion's dimensions. I use teleport instead which doesn't have those limits then just tasting shortcuts in app's.

July 26, 2010

There no such think as lie

My point exactly is that there no deliberate untruth.
Fist account is logical equality of `rightful `true teller and `deluded `liar.
It can be checked by logical table and all YES/NO answers will be same.

Suppose real person. She is liar. Lie is recurring, also reflective process, from it comes self delusion. If we recall that this person liar it become indistinguishable from honest and sane one.

The only difference is inside.


Geeks jokes

trait Philosophical {
    def philosophize = println ("I consume memory, therefor I'm\nQED")  
} 


Atoms dialog:
- i lost my electron
- i you sure?
- yes, i'm positive!

Me - buying a Car

I don't hate cars but I love bicycles. Still time comes to buy one of those fridges on wheels with expectation of improving long distance mobility.

Data source for offers is local news-board. Datamining target is to filter ill intentioned sellers. Criteria 1 - get only new offers, 2 - check contact phone with Google for multiple cars in stock. Tools is 15-min script in Python which
$ crontab -e
# m h dom mon dow command
0 * * * * /home/$USER/golf.sh
.
and tail -F /tmp/new_golf.txt on results.

import sys
import datetime
import lxml.html

def readIds (name):
    xs = list ()
    file = open(name, "r")
    try:
        while 1:
            line = file.readline()
            if line == '':
                break
            xs.append(line.strip())
    finally:
        file.close()
    return xs

def writeIds (name, xs):
    file = open(name, "w")
    xsn = map(lambda (s): s + '\n', xs)
    try:
        file.writelines(xsn)
    finally:
        file.close()

def appendResult(name, xs):
    file = open(name, "a")
    xsn = map(lambda (s): s + '\n', xs)
    try:
        now = datetime.datetime.now()
        file.write(">> At " + str(now) + " added: " + str(len(xs)) + " new item\n")
        file.writelines(xsn)
    finally:
        file.close()
        
def parseCatalog(catalog, base_url, pages):
    xs = list ()
    for page in range(1, pages +2):
        linkTo = catalog % page

        links = lxml.html.parse(linkTo).xpath("//a[@class=\"resulttextlink noMargin\"]/@href")
        for link in links:
            if link.find(base_url) >= 0:
                Id = link[link.rfind('/', 0, link.rfind('/') -1) +1 : -5]
                xs.append(Id)

    return xs

CATALOG_URL = "http://www.publi24.ro/anunturi/auto-moto-velo/masini-second-hand/vw/golf-4/?pag=%d"
ANUNT_URL = "http://www.publi24.ro/anunturi/auto-moto-velo/masini-second-hand/vw/golf-4/anunt/"

def main ():
    upper = 2
    if len(sys.argv) >1:
        upper = int(sys.argv[1])

    cars_store_file = "/tmp/golf.txt"

    cars = readIds (cars_store_file)

    new_cars = parseCatalog(CATALOG_URL, ANUNT_URL, upper)
    
    lset = set (cars)
    rset = set (new_cars)    
    cars_diff = list(rset.difference(lset))
#     import pdb
#     pdb.set_trace()

    writeIds(cars_store_file, new_cars)

    new_urls = map(lambda s: ANUNT_URL + s + '.html', cars_diff)
    appendResult("/tmp/new_golf.txt", new_urls)
    
    

if __name__ == "__main__":
    main()




Simple enough and robust but wrong. For example next construct.

file = open(name, "r")
    try:
        while 1:
            line = file.readline()
            if line == '':
                break
            xs.append(line.strip())
    finally:
        file.close()

It is degenerated Python 3.0 resource management construct. It is RAII for GC runtimes sprinkling everywhere from VB to Ruby and C# two stage de-allocator.

with open(name, "r") as file:
           pass # here we do stuff
originally.

Some can argue that it is evolutionary result of new ideas implemented into language. But this semantic construct always been there. If natural language would need redesign every time new idea pushed out we would still be discussing advantages `wheel vs `backpacking instead Scala vs Python.

BTW, Scala has no problem with extension.

object _3 { 
  import java.io.File
  import java.io.PrintWriter
  //
  def withPrintWriter(file: File) (op: PrintWriter => Unit) { 
    val writer = new PrintWriter(file)
    try { 
      op (writer)
    } finally { 
      writer.close()
    }
  }
  //
  withPrintWriter (new File("/tmp/Date.txt")) { 
    writer =>
      writer.println (new java.util.Date)
  }
}

No need to wait. One can write new ideas fluently for other to understand and accept.

July 23, 2010

Scala is my language-of-the-year this season.

Already for a while, I'm teaching myself one programming-language-per-year.
It upgrade my coding abilities whilst keeping programming skills generic and language agnostic. Practically it means I'm rewriting lots of code snippets with familiar structure in different languages. Something like RosetaCode on syntactic level.

Last year I flushed my brain with Category Theory and Linear Logic. Reason for that upgrade was one silly question from headhunter, namely: "What do you call class with virtual function". (C++ interview).
His own answer was - `Polymorphic Class'. Ups... This `hangs me up just like F0 0F C7 C8  hangs Pentium MMX. Postfactum I meditated on subject a lot,  because it was traumatizing failing interview that miserable.
Clearly he meant `Subtyping polymorphism of C++ object's but I ruled that out on simplicity ground and begin looking for `higher-kinded (*->*) in type classes, then for `class's from Naive Sets and then back to nothing, Just Nothing...

Thanks to this unfortunate event I rethink my approach for `skills-upgrade in general:
`programming-language-per-year still good, valid and fun
`proficiency can be gained in 10 year (10,000 3000 hour when 4.5 per day 220 days per year)
`then you have to go to new LEVEL (still creator) or GAME OVER (manager)

What is Scala?
For me it is reification of computation via programing (By means of reification something that was previously implicit, unexpressed and possibly unexpressible is explicitly formulated and made available to conceptual (logical or computational) manipulation).

Why Scala?
Because I like to program things fluent style and the way I feel it right.

July 6, 2010

Get to the light..

.. make BOT happy.

One of my favorite educational games is Light-Bot.
Its target is to navigate psychotic robot to light ball, let him make lite. This act bring happiness to robot. This also complete the game.

Level 10 split humanoids in two groups - 60/40, where 40 will newer pas it.
Who does it - programmers. More precisely - `can be programmer under favorable circumstances.


Top 15 solutions presented in no order.


  • All 10 level in under 45 MIN
    
    


Sent: joi 8 noiembrie 2012 15:45 
Received: 11/08/2012 04:31 PM






  • lb-88.png
  • if __name__ == "__main__":
        f1()
    
  • lb-105.png
  • lb-111.png
  • :- use_module(library(clpfd)).
     
    puzzle(    [[ 151],
              [U1],[U2],
            [40],[U3],[U4],
          [U5],[U6],[U7],[U8],
        [ X],[11],[ Y],[ 4],[ Z]], X,Y,Z  ) :-
     151 #= U1 + U2, 40 #= U5 + U6,
     U1 #= 40 + U3, U2 #= U3 + U4,
     U3 #= U6 + U7, U4 #= U7 + U8,
     U5 #=  X + 11, U6 #= 11 +  Y,
     U7 #=  Y +  4, U8 #=  4 +  Z,
      Y #=  X +  Z,
     Vars = [U1,U2,U3,U4,U5,U6,U7,U8,X,Y,Z],
     Vars ins 0..sup, labeling([],Vars).
     
    % ?- puzzle(_,X,Y,Z).
    % X = 5,
    % Y = 13,
    % Z = 8 ;
    
  • lb-114.png
  • lb-116.png
  • 117, 117-1 are same as 116 but have hiden bug in them.. Because they 117 :_
  • lb-117-1.png
  • lb-117.png
  • [-]>,+[->,+]<[.<]
    
  • lb-119.png
  • lb-125.png
  • I think, I understand this one.
    qsort []     = []
    qsort (x:xs) = qsort [y | y <- xs, y < x] ++ [x] ++ qsort [y | y <- xs, y >= x]
    
  • lb-126.png
  • fib = 0 : 1 : zipWith (+) fib (tail fib)
    fib !! 4
    
  • lb-131.png
  • lb-136.png
  • Program will take all available memory no matter what. Seriously, trying to be everything is not a way to success.
  • lb-190.png
  • Two light bull solution

  • Total inline strategy



  • high kinetic energy 

  • real proof that non programmer can do it


  • Carpenter: there 17 symmetries in topology. He used 6.  


  • Easy Test



July 5, 2010

FooBuzz canonical answers

Most tasks have multiple solutions. Our life experience and aesthetic inclination forms partial map from `all solution space to personalized one.

By comparing `personal solution with `canonical, for a given problem, we can analyze what is our essence.

Many interview problem designed just for that purpose.

Problem One - `FooBuzz'.

You asked to enumerate numbers fro 1 to 100. It it is multiple of 3 then print `Foo. If multiple of 5 then print `Buzz. If multiple of both print `FooBuzz else print number.

Solution show the balance of mathematical awareness versus following programming standard.

Canonical solution for different type of languages (I skip most and ignore non-mainstream).

`C
int main ()
{
  
  for (int i = 0; i < 100; ++i) {
    bool flag = false;

    if (i % 3 == 0) {
      printf("Foo");
      flag = true;      
    }

    if (i % 5 == 0) {
      printf("Buzz");      
      flag = true;      
    }
    
    if (flag) {
      printf("\n");      
    } else {      
      printf("%d\n", i);      
    }    
  }
}

`Python
for i in range (1, 100):
    s = ""
    if i % 3 == 0: s+="Foo"
    if i % 5 == 0: s+="Buzz"
    if s == "": s += str(i)
    print s

`Scala
def FooBuzz {
    for (i <- 1 until 100) {
      val s = { if(i % 3 == 0) "Foo" else "" } + 
              { if(i % 5 == 0) "Buzz" else "" }
      println ( if(s.isEmpty)  i.toString else s )
    }
  } 

There is no extensive study of deviations for this solution only observations gathered from limited sources.

On math side main problem is failure to recognize instance of Monoids {nat, %} and {string, +} which naturally additive and don't need special treatment in code.

On coding side variety language specific problems. Only one was common -  putting conditional of multiple being equal 0 but not just `i % 3.


Our efficiency as designer proportional to degree of flexibility we can take without damaging our brain. This and similar test show us our limits.