Breadcrumbs

Blog

Iterating over a List to Filter specific Element's in Java 8 with Lambdas is List size independent. This means that it doesn't matter how big youre list is, with lambda it is fast on every size, nearly the same speed.

Please check out my Github Project: https://github.com/rkunas/java-list-map-set

package eu.kunas.javalistmapset.performances;

import eu.kunas.javalistmapset.model.CustomerDto;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;

/**
 * Created by rkunas on 23.02.2016.
 */
public class LambdaListSearchPerformance {

    public static void perfLambdas(Integer times) {

        List<CustomerDto> list = new ArrayList<CustomerDto>();

        for (int i = 0; i < times; i++) {
            CustomerDto customerDto = new CustomerDto("Customer " + i);
            list.add(customerDto);
        }
        long start = System.currentTimeMillis();
        Stream<CustomerDto> filtered = list.stream().parallel().filter(
                customer -> {
                    return customer.getName().endsWith("2");
                });
        long stop = System.currentTimeMillis();

        System.out.println(filtered.count() + " Items");
        System.out.println(stop - start + " Millis Search with Lambda");

        long start2 = System.currentTimeMillis();
        List<CustomerDto> filtered1 = new ArrayList<>();
        for (CustomerDto customerDto : list) {
            if(customerDto.getName().endsWith("2")){
                filtered1.add(customerDto);
            }
        }

        long stop2 = System.currentTimeMillis();

        System.out.println(filtered1.size() + " Items");
        System.out.println(stop2 - start2 + " Millis Search with Default way");

    }

}

 

If we now run this Code we are getting the following result.

1000000 Items
64 Millis Search with Lambda
1000000 Items
103 Millis Search with Default way

In our Example here with 1000000 elements the Lambda Code is double time faster then the standard way.

Homecloud is next Homeloud for you. It is based on Java, same popuplar language on which Android is based on.

Owncloud and other "Private Clouds" are based on PHP or Pyhton.

You have to configure to much get them running.

 

Homecloud is Open Source

http://github.com/rkunas/homecloud

We are just at the beginning !!!

 

 

 

 

 

RC Tire 1:8

This is an small Example how to design an RC- Tire by youre own. It is designed with the CAD Tool for Software Developers.

$fn=100;
module tire(){
   
    // Das Grobe Rad schaffen
    difference(){
        intersection(){
            
            cylinder(h=60,r=50,center=true);
            
            // Abrundung um das Grobe rad
            translate([0,0,30]){
                sphere(r=77,center=false);
            };
            
            
            translate([0,0,-30]){
                sphere(r=77,center=false);
            };
        }
        
        // Loch in Rad
        cylinder(r=1.5,h=60,center=true);
        
        
        // Vertiefung im Rad
        translate([0,0,30])
        donut();
        
        // Erste lochreihe von innen nach außen
        for ( i = [0 : 8] ){
           
           rotate((360/8)*i,[0,0,10]){
                translate([0, 20, 0]){
                    cylinder(r=5,h=60,center=true);
                }
           }
          
       }
       rotate(20)
       // Zweite lochreihe von innen nach außen
       for ( i = [0 : 8] ){
           rotate((360/8)*i,[0,0,10]){
                translate([0, 33, 0]){
                    cylinder(r=10,h=60,center=true);
                }
           }
          
       }
       translate([0,0,10]){
            cylinder(r=20, h =40);
       }
       
       // Profil 
        for ( i = [0 : 30] ){
           
           rotate((360/30)*i,[0,0,10]){
                translate([0, 59, 0]){
                   cylinder(r=10,h=60,center=true,$fn=5);
                }
           }
          
       }
       translate([0,0,-30]){
            cylinder(h=5, r=8,$fn=6);
       }
           
    }
}
turn($t);
module turn(t){
    rotate([0,0,t*800]){
        tire();
    }
}
  
module donut() {
    rotate_extrude(){
    
        translate([22,0,0]){
    
            difference() {
                circle(r=21);
            }
            
        }
    }
}

 

 

Turkey Trip Skydiving

Skydiving in Turkey with a boat at the end of the rope.

The silence at 300 or 400 meters was awesome with the blue sky and blue beachwater.

 

 

 

RepRap Prusa 3D Printer

This is my first 3D Printer. It is nearly finished, only e few electronic parts are missing. Steppers and End stoppers are installed. Currently i am trying to configure the RepRap Gen7 v1.4.1 . It is very dfficult/undocumented how to install the ROM onto the Atmel Chip. Many guys are strungling with the same problems.

And no i am not trying to print weapons with my 3D Printer. Uuups PRISM is surely reading this (smile)

Hello World

Website is now online !

public class java {
    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

I was able to code an Multithreaded litle Projekt with two servos and the Arduino Due. The servos from Modelcraft RS2 are cheap and good for what i need them. You can see the signals frequency in this article.

Signal at 1.0 ms turn left

Signal at 1.0 ms

Signal at 2.0 ms turn right

Signal at 2.0 ms

Signal 13.4 LOW and 2.0 ms HIGH 

1.0 ms HIGH and 13.4 ms LOW = turn left

2.0 ms HIGH and 13.4 ms LOW = turn riight

1.5 ms HIGH and 13.4 ms LOW = middle position

/*
 * Example to demonstrate thread definition, semaphores, and thread sleep.
 
 */
#include FreeRTOS_ARM.h;
int *r = 0;
// The LED is attached to pin 13 on Arduino.
const uint8_t LED_PIN13 = 13;
const uint8_t LED_PIN12 = 12;
// Declare a semaphore handle.
// xSemaphoreHandle sem;
//------------------------------------------------------------------------------
/*
 * Thread 1, turn the LED off when signalled by thread 2.
 
 */
// Declare the thread function for thread 1.
//------------------------------------------------------------------------------
/*
 * Thread 2, turn the LED on and signal thread 1 to turn the LED off.
 
 */
// Declare the thread function for thread 2.
static void Thread2( void *pvParameters) {
  int *t2 ;
  t2 = ( int * ) pvParameters;
  int timer = 1;
  pinMode(LED_PIN13, OUTPUT);
  while (1) {
    if(timer == 150){
      timer =1;
    }
    digitalWrite(LED_PIN13, HIGH);
    if(timer &lt; 75){
      vTaskDelay((2.0 * configTICK_RATE_HZ) / 1000L);
    }
    if(timer &gt; 75){
      vTaskDelay((1.0 * configTICK_RATE_HZ) / 1000L);
    }
    digitalWrite(LED_PIN13, LOW);
    vTaskDelay((13.4 * configTICK_RATE_HZ) / 1000L);
    timer = timer + 1;
  }
}
static void Thread1( void *pvParameters) {
  int *t1 ;
  t1 = ( int * ) pvParameters;
  
  int timer = 1;
  pinMode(LED_PIN12, OUTPUT);
  while (1) {
    if(timer == 500){
      timer =1;
    }
    digitalWrite(LED_PIN12, HIGH);
    if(timer &lt; 250){
      vTaskDelay((2.0 * configTICK_RATE_HZ) / 1000L);
    }
    if(timer &gt; 250){
      vTaskDelay((1.0 * configTICK_RATE_HZ) / 1000L);
    }
    digitalWrite(LED_PIN12, LOW);
    vTaskDelay((13.4 * configTICK_RATE_HZ) / 1000L);
    timer = timer + 1;
  }
}
//------------------------------------------------------------------------------
void setup() {
  portBASE_TYPE s2,s1;
  Serial.begin(9600);
  // initialize fifoData semaphore to no data available
  // sem = xSemaphoreCreateCounting(1, 0);
  // create sensor task at priority two
  s2 = xTaskCreate(Thread2, NULL, configMINIMAL_STACK_SIZE, (void*)r, 1, NULL);
  s1 = xTaskCreate(Thread1, NULL, configMINIMAL_STACK_SIZE, (void*)r, 2, NULL);
  // create SD write task at priority one
  // check for creation errors
  if ( s2 != pdPASS ) {
    // Serial.println(F("Creation problem"));
    while(1);
  }
  // start scheduler
  vTaskStartScheduler();
  //Serial.println(F("Insufficient RAM"));
  while(1);
}
//------------------------------------------------------------------------------
// WARNING idle loop has a very small stack (configMINIMAL_STACK_SIZE)
// loop must never block
void loop() {
  // Not used.
}

Threading in embeded devices for example an Arduino is quite difficult to code. The code is getting more and more unreadable. FreeRTOS is an operating System for embedded devices. Threads are clearly separated from each other. The code is entered in this article.

/*
 * Example to demonstrate thread definition with two LED's.
 */
#include &lt;FreeRTOS_ARM.h&gt;
// Redefine AVR Flash string macro as nop for ARM
#undef F
#define F(str) str
// The LED is attached to pin 12 and 13 on Arduino.
const uint8_t LED_PIN_12 = 12;
const uint8_t LED_PIN_13 = 13;
//------------------------------------------------------------------------------
/*
 * Thread 1
 */
// Declare the thread function for thread 1.
static void Thread1(void* arg) {
  while (1) {
    
    digitalWrite(LED_PIN_12, HIGH);
    double  t = (500L * configTICK_RATE_HZ) / 1000L;
    vTaskDelay(t);
    digitalWrite(LED_PIN_12, LOW);
    double t2 = (500L * configTICK_RATE_HZ) / 1000L;
    vTaskDelay(t2);
  }
}
/*
 * Thread 1
 */
// Declare the thread function for thread 1.
static void Thread2(void* arg) {
  while (1) {
    digitalWrite(LED_PIN_13, HIGH);
    double  t = (200L * configTICK_RATE_HZ) / 1000L;
    vTaskDelay(t);
    digitalWrite(LED_PIN_13, LOW);
    double t2 = (200L * configTICK_RATE_HZ) / 1000L;
    vTaskDelay(t2);
  }
}
//------------------------------------------------------------------------------
void setup() {
  portBASE_TYPE s1,s2;
  // Useable for logging
  Serial.begin(9600);
  // create thread 1
  s1 = xTaskCreate(Thread1, NULL, configMINIMAL_STACK_SIZE, NULL, 1, NULL);
  // create thread 2
  s2 = xTaskCreate(Thread2, NULL, configMINIMAL_STACK_SIZE, NULL, 2, NULL);
  // check for creation errors
  if (s1 != pdPASS  || 21 != pdPASS ) {
    Serial.println(F("Creation problem"));
    while(1);
  }
  // start scheduler, start of threads
  vTaskStartScheduler();
  Serial.println(F("Insufficient RAM"));
  while(1);
}
//------------------------------------------------------------------------------
// loop must never block
void loop() {
  // Not used.
}