יום שבת, 27 ביולי 2013

c++ cross compilation for my raspberry pi

C++ cross compilation should be a very simple and intuitive task especially using the  new eclipse Kepler that’s already contains all the integration ingredients .
If a problem comes out  95% is because of bad toolchain. ( that cause linking problems and segmentation faults when  you finally overcome the linking problems )
I fount the following source for raspberry pi toolchain working:
$ wget https://s3.amazonaws.com/RTI/Community/ports/toolchains/raspbian-toolchain-gcc-4.7.2-linux64.tar.gz

Please Note :
Use the proper toolchain version according to your compilation machine (32 or 64 bit ).
If segmentation faults error appear to to compile the program with “static” flag .

Resources:
http://www.xappsoftware.com/wordpress/2013/02/07/using-ubuntu-to-cross-compile-for-raspberry-pi/

יום שישי, 12 ביולי 2013

Pax in work

The pax tools are collection of tools for OSGI
Pax Construct:set of scripts,  that automates the creation,building, and execution of OSGi projects.

Download Pax:https://ops4j1.jira.com/wiki/display/paxconstruct/Download

C:\devtools\Osgi\pax>pax-create-project -g learn.myProject -a dwmj -v 1.0.0-SNAP
SHOT

..\pax-provision

 

https://ops4j1.jira.com/wiki/display/ops4j/Pax
http://wiki.ops4j.org/display/ops4j/Pax

Java Serialization

The pojo object

  1: package playwithserialization;
  2: 
  3: import java.io.Serializable;
  4: import java.lang.reflect.Field;
  5: import java.util.Date;
  6: import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
  7: 
  8: /**
  9:  *
 10:  * 
 11:  */
 12: public class LogMsg implements Serializable {
 13: 
 14:     public Date getDateTime() {
 15:         return DateTime;
 16:     }
 17: 
 18:     public void setDateTime(Date DateTime) {
 19:         this.DateTime = DateTime;
 20:     }
 21: 
 22:     public String getMsg() {
 23:         return Msg;
 24:     }
 25: 
 26:     public void setMsg(String Msg) {
 27:         this.Msg = Msg;
 28:     }
 29: 
 30:     public String getMessageGroup() {
 31:         return MessageGroup;
 32:     }
 33: 
 34:     public void setMessageGroup(String MessageGroup) {
 35:         this.MessageGroup = MessageGroup;
 36:     }
 37: 
 38:     public TraceEventType getSeverity() {
 39:         return Severity;
 40:     }
 41: 
 42:     public void setSeverity(TraceEventType Severity) {
 43:         this.Severity = Severity;
 44:     }
 45: 
 46:     public String getThreadID() {
 47:         return threadID;
 48:     }
 49: 
 50:     public void setThreadID(String threadID) {
 51:         this.threadID = threadID;
 52:     }
 53: 
 54:     public String getThreadName() {
 55:         return ThreadName;
 56:     }
 57: 
 58:     public void setThreadName(String ThreadName) {
 59:         this.ThreadName = ThreadName;
 60:     }
 61: 
 62:     public String getAdditionalInfo() {
 63:         return AdditionalInfo;
 64:     }
 65: 
 66:     public void setAdditionalInfo(String AdditionalInfo) {
 67:         this.AdditionalInfo = AdditionalInfo;
 68:     }
 69: 
 70:     public String getStackTrace() {
 71:         return StackTrace;
 72:     }
 73: 
 74:     public void setStackTrace(String StackTrace) {
 75:         this.StackTrace = StackTrace;
 76:     }
 77:     
 78:     // Summary:
 79:     //     Identifies the type of event that has caused the trace.
 80:     public enum TraceEventType
 81:     {
 82:         // Summary:
 83:         //     Fatal error or application crash.
 84:         Critical (1),
 85:         //
 86:         // Summary:
 87:         //     Recoverable error.
 88:         Error ( 2),
 89:                 
 90:         //
 91:         // Summary:
 92:         //     Noncritical problem.
 93:         Warning (4),
 94:         //
 95:         // Summary:
 96:         //     Informational message.
 97:         Information (8),
 98:         //
 99:         // Summary:
100:         //     Debugging trace.
101:         Verbose (16),
102:         //
103:         // Summary:
104:         //     Starting of a logical operation.
105:        
106:         Start (256),
107:       
108:         Stop ( 512),
109:       
110:         Suspend (1024),
111:       
112:         Resume ( 2048),
113:       
114:         Transfer (4096);
115:    
116:         private final int mOrder;
117:           
118:          TraceEventType(int pOrder )
119:         {
120:             mOrder = pOrder;    
121:         } 
122:     }
123:     
124:     
125:        private Date DateTime ;
126: 
127:         private String Msg ;
128: 
129:         private String MessageGroup ;
130: 
131:         private TraceEventType Severity ;
132: 
133:         private String threadID ;
134: 
135:         private String ThreadName ;
136: 
137:         private String AdditionalInfo ;
138: 
139:         private String StackTrace ;
140: 
141:         public LogMsg()
142:         {
143:             
144:         } 
145:         
146:             public String toString() {
147:      return (new ReflectionToStringBuilder(this) {
148:          protected boolean accept(Field f) {
149:              return true;
150:          }
151:      }).toString();
152:             }
153: }

The test project


  1: package playwithserialization;
  2: 
  3: import java.io.FileInputStream;
  4: import java.io.FileOutputStream;
  5: import java.io.ObjectInputStream;
  6: import java.io.ObjectOutputStream;
  7: 
  8: import java.util.Date;
  9: 
 10: /**
 11:  *
 12:  * @author Zvika Peer 
 13:  */
 14: public class PlayWithSerialization {
 15: 
 16:     /**
 17:      * @param args the command line arguments
 18:      */
 19:     public static void main(String[] args) {
 20:     
 21:          String filename = "LogMsg.ser";
 22:     LogMsg theLogMsg = new LogMsg();
 23: 
 24:     theLogMsg.setAdditionalInfo("Additional info");
 25:     
 26:     theLogMsg.setDateTime( new Date());
 27:     
 28:     theLogMsg.setMessageGroup("my Message group");
 29:     
 30:     theLogMsg.setMsg("This is the message ");
 31:     
 32:     theLogMsg.setSeverity(LogMsg.TraceEventType.Critical );
 33:     
 34:     // Save the object to file
 35:     FileOutputStream fos = null;
 36:     ObjectOutputStream out = null;
 37:     try {
 38:       fos = new FileOutputStream(filename);
 39:       out = new ObjectOutputStream(fos);
 40:       out.writeObject(theLogMsg);
 41: 
 42:       out.close();
 43:     } catch (Exception ex) {
 44:       ex.printStackTrace();
 45:     }
 46:     // Read the object from file
 47:     // Save the object to file
 48:     FileInputStream fis = null;
 49:     ObjectInputStream in = null;
 50:     try {
 51:       fis = new FileInputStream(filename);
 52:       in = new ObjectInputStream(fis);
 53:       theLogMsg = (LogMsg) in.readObject();
 54:       out.close();
 55:     } catch (Exception ex) {
 56:       ex.printStackTrace();
 57:     }
 58:     System.out.println(theLogMsg);
 59:   }
 60: }

The Result:
debug:
playwithserialization.LogMsg@1bb73b0[DateTime=Sun Jun 30 10:57:35 IDT 2013,Msg=This is the message ,MessageGroup=my Message group,Severity=Critical,threadID=<null>,ThreadName=<null>,AdditionalInfo=Additional info,StackTrace=<null>]
BUILD SUCCESSFUL (total time: 0 seconds)

References
http://javarevisited.blogspot.co.il/2011/04/top-10-java-serialization-interview.html
http://www.vogella.com/articles/JavaSerialization/article.html

functools.lru_cache

A sample program that demonstrates the functools.lru_cache:

  1: import timeit 
  2: import itertools
  3: import functools
  4: import sys
  5: 
  6: @functools.lru_cache(maxsize=32)
  7: def myTestCacheFucntion (pKey  ):
  8:     print ("The method has been called")
  9:     return "Hello:" + pKey
 10: 
 11: print ( myTestCacheFucntion ("Zvika"))
 12: 
 13: print (myTestCacheFucntion ("Shahf"))
 14: 
 15: print (myTestCacheFucntion ("Zvika"))
 16: 
 17: print (myTestCacheFucntion ("Shahf"))
 18: 
 19: sys.exit()

And the result
The method has been called
Hello:Zvika
The method has been called
Hello:Shahf
Hello:Zvika
Hello:Shahf
Traceback (most recent call last):
  File "C:\blogs\test1\testpy.py", line 19, in <module>
    sys.exit()
SystemExit

unless in Ruby

The unless is ruby is equivalents to if not
Sample code

  1:   fileName = 'C:\\learn\\Ruby\\TestFiles\\myTest.txt'
  2:   f = File.open(fileName, "r") 
  3:   f.each_line do |line|
  4:   next unless line =~ /\d{2,6}/ # Skip lines with no numbers with len < 2 
  5:     puts line
  6:   end

Input data
13333333333333333333333333333
2
3
4
Zvika
5
6
7
Shaaf


And the result
C:\learn\Ruby>test5.rb
2
3
4
Zvika
5
6
7
Shaaf

Listing the operators in html table

The following code shows the list of the operators in html table.

  1: <!DOCTYPE html>
  2:  <style>
  3:  .imgstl
  4:    {
  5:   
  6:    }
  7:  .imgstl2
  8:    {
  9:    margin:2px;
 10:    border:1px solid #0000ff;
 11:    height:50px;
 12:    width:50px;
 13:    float:left;
 14:    text-align:center;
 15:    }
 16:  div.img img
 17:    {
 18:    display:inline;
 19:    margin:3px;
 20:    border:1px solid #ffffff;
 21:    }
 22:  div.img a:hover img
 23:    {
 24:    border:1px solid #0000ff;
 25:    }
 26:  div.desc
 27:    {
 28:    text-align:center;
 29:    font-weight:normal;
 30:    width:120px;
 31:    margin:2px;
 32:    }
 33:  </style>
 34: <html lang="en">
 35: <head>
 36:     <title>Routes Web API</title>
 37:     <link href="../../Content/Site.css" rel="stylesheet" />
 38:  
 39: </head>
 40:    
 41: <body id="body" >
 42:     <div class="main-content">
 43:         <div>
 44:             <h1>All Operators</h1>
 45:             <ul id="OperatorsList"/>
 46:         </div>
 47:         <div>
 48:             <input type="button" id="CallWebApi" value="Call web api" />
 49:             <p id="product" /> 
 50:         </div>
 51:     </div>
 52: 
 53:     <div id="dynamicTable">
 54:     </div>
 55: 
 56:       <script src="../../Scripts/jquery-1.8.2.js"></script>
 57:        <script> 
 58:            $(document).ready(function () {
 59:                
 60:                $("#CallWebApi").on("click", function (event) {
 61: 
 62:                    // create table
 63:                    var $table = $('<table>');
 64:                    // caption
 65:                    $table.append('<caption>Operators List</caption>')
 66:                    // thead
 67:                    .append('<thead>').children('thead')
 68:                    .append('<tr />').children('tr').append('<th>Photo</th><th>Name</th>');
 69: 
 70:                    //tbody
 71:                    var $tbody = $table.append('<tbody />').children('tbody');
 72: 
 73:                    var theOperatorTable = $("#OperatorTable");
 74:                             
 75:                    // Send an AJAX request
 76:                   
 77:                    $.getJSON("api/OperatorData/",
 78:                    function (data) {
 79:                        // On success, 'data' contains a list of products.
 80:                        $.each(data, function (key, val) {
 81:                            
 82:                            var theOperatorName = val.Name ;
 83: 
 84:                            var theOperatorImage = val.OperatorImage;
 85:                          
 86:                            var theNewRow = $tbody.append('<tr />').children('tr:last');
 87: 
 88:                            var theNewTD = theNewRow.append("<td></td>").children('td:last');
 89: 
 90:                            $('<img  />', { src: "http://localhost:20385/api/Images/" + theOperatorImage }).
 91:                              appendTo(theNewTD);
 92: 
 93:                       //     $('#table_header td:nth-child(3)').html('the content');
 94: 
 95:                            theNewRow.append("<td>" + theOperatorName + "</td>")
 96:                       
 97:                        });
 98: 
 99:                        // add table to dom
100:                        $table.appendTo('#dynamicTable');
101: 
102:                    });                 
103:                });
104:          });
105:         
106:        </script>
107: </body>
108: </html>

Capture48


Resources
http://www.jquery4u.com/plugins/30-amazing-jquery-tables/

Passing parameters in soapUI

Create the test Suite
Capture45

Add the parameters
Capture46 
Call the web service

Capture47

The soap request :

  1: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cxf="http://cxfserver.mycompany.com/">
  2:    <soapenv:Header/>
  3:    <soapenv:Body>
  4:       <cxf:GetMsg>
  5:          <!--Optional:-->
  6:          <arg0>
  7:             <!--Optional:-->
  8:             <Name>${#Name}</Name>
  9:             <Age>${#Age}</Age>
 10:          </arg0>
 11:       </cxf:GetMsg>
 12:    </soapenv:Body>
 13: </soapenv:Envelope>