December 1, 2013

Why Agile May Ruin Us All — Medium

Why Agile May Ruin Us All — Medium: "I ran into Scrum, and"

'via Blog this'

Bizarre stuff I dislike
- Stand UP meeting facing headquarter building
- Putting pieces of paper into the wall

 Stuff I like
- Music in the office space
- Pair programming with personal friend
- Getting Thing Done



November 26, 2013

Async / await explained in 5 seconds

Hi,


import scala.async.Async.{async, await}


  val fiveSeccond = async {
    val start = new java.util.Date()
    
    await { future { Thread.sleep(5000) } }
    
    val t = new java.util.Date()
    s"> ${start.getSeconds} - ${t.getSeconds}"
  }                                               //> fiveSeccond  :  = scala.concurrent.impl.Promise$DefaultPromise@1cb237
                                                  //| 8
  Await.result(fiveSeccond, 10 second)            //> res1:  = > 16 - 21
 
:)

May 30, 2013

BlackBox office power manager command-line script


Hi,

I asked student to make command line interface to the http://www.black-box.at/en-at/fi/1574/12791/Power-Switch-Cabinet-NG/O2.

Device has ajax over http with digest auth interface.

I works just fine, but ...

Random testing on IP addresses is really horrible idea. Half of our platform was down this morning.



#! /usr/bin/python

import sys, os, re
import getopt
import shlex, subprocess


command = "curl -u \"admin:admin\" --noproxy 192.168.100.1 --digest http://192.168.100.1/user/control.cgi --data-binary CMD="

def output_print(command):
 args = shlex.split(command)        
        output, error = subprocess.Popen(args,stdout = subprocess.PIPE, stderr= subprocess.PIPE).communicate()

 match = re.findall( r'var data=(.*)\;', output, re.MULTILINE)
        status = None
        if match:
  try:
   true = 1
   false = 0 # eval context
                 status = eval(str(match[0]))
  except TypeError:
                        print ("Status eval error")
                        return 1
 [Name, p2, port_state] = status[1]
 print Name
        print "|--------------------------------------------"
        print "|  Port         | State             "
        print "|--------------------------------------------"

 for i in range(4):
  [Name, P0, State,P1,P2,P3] = port_state[i]
  print ">",Name, "          |", State
 return


def main(argv):
        global command
 if len(argv) == 0:
  output_print(command)


 elif len(argv) == 2:
                ports = ['1','2','3','4']
                switch = {'ON':0,'OFF':1}

  if not argv[0] in ports:
                        print argv[0] + " is not port number"
                        return -1

  if not argv[1].upper() in switch.keys():
                        print argv[1] + " switch nok"
                        return -1

                command = command + "0_%d_%s" % (int(argv[0]) -1, str(switch.get(argv[1].upper())))
               
  output_print(command)
 else:
  print "not correct number of arguments, should be two - Port number and new state on/off"


if __name__ == '__main__':
    main(sys.argv[1:])



December 20, 2012

Property based testing for unit testers with PropEr – Part 1 «

Property based testing for unit testers with PropEr – Part 1 «: "Eric states his basic expectations as follows:

I can put arbitrary terms into the dictionary as keys
I can put arbitrary terms into the dictionary as values
When I put a value in the dictionary by a key, I can retrieve that same value
When I put a different value in the dictionary by key it does not change other key value pairs.
When I update a value the new value in available by the new key
When a value does not exist a not found exception is created"

'via Blog this'



%%% @author vlad 
%%% @copyright (C) 2012, vlad
%%% @doc
%%%
%%% @end
%%% Created : 17 Dec 2012 by vlad 

-module(erlware_tests).

-compile(export_all).

-ifdef(TEST).

-include_lib("proper/include/proper.hrl").
-include_lib("eunit/include/eunit.hrl").


%% --------------------------------------------------------------------------------
%% Erlware Dictionary
%% --------------------------------------------------------------------------------

%% I can put arbitrary terms into the dictionary as keys
key() -> nat().
    %union([integer(), atom()]).

%% I can put arbitrary terms into the dictionary as values
value() -> nat(). %union([integer(), atom(), binary(), boolean(), string()]).


sym_dict() ->
    ?SIZED(Size,sym_dict(Size)).

sym_dict(0) ->
    {'$call', ec_dictionary, new, [ec_gb_trees]};
sym_dict(Size) ->
    ?LAZY(frequency([
       {1, {'$call', ec_dictionary, remove, [key(), sym_dict(Size - 1)]}},
       {2, {'$call', ec_dictionary, add, [value(), value(), sym_dict(Size - 1)]}}
      ])).

%% Is it realy work?
%% proper_gen:sample(erlware_tests:value()).
%% proper_gen:sample(erlware_tests:key()).
%% proper_gen:sample(erlware_tests:sym_dict()).
%% {ok,D} = proper_gen:pick(erlware_tests:sym_dict(),10).

%% When I put a value in the dictionary by a key, I can retrieve that same value
prop_get_after_add() ->
    ?FORALL({Dict,K,V}, {sym_dict(), key(), value()},
            V =:= ec_dictionary:get(K, ec_dictionary:add(K, V, Dict))
           ).

%% When I put a different value in the dictionary by key it does not change other key value pairs.
prop_add_twice_get_first() ->
    ?FORALL({Dict,K1,V1,K2,V2}, {sym_dict(), key(), value(), key(), value()},
            ?IMPLIES(K1 /= K2,
                     V1 =:= ec_dictionary:get(K1,
                                              ec_dictionary:add(K2, V2,
                                                                ec_dictionary:add(K1, V1, Dict))) 
                    )).

%% When I update a value the new value in available by the new key
prop_update_the_value() ->
    ?FORALL({Dict,K,V1,V2}, {sym_dict(), key(), value(), value()},
                V2 =:= ec_dictionary:get(K,
                                         ec_dictionary:add(K, V2,
                                                           ec_dictionary:add(K, V1, Dict)))
           ).

%% When a value does not exist a not found exception is created
does_not_exist_exception_test() ->
    ?assertThrow(not_found, ec_dictionary:get(42, ec_dictionary:new(ec_gb_trees))). 


-endif. % (TEST).