Senin, 19 Januari 2015

Space Station Sunday: The Ships That Fell To Earth

Good evening, space fans!  Here's what went on with our off-planet pioneers this week.

Preparations are underway for Tuesday's detachment of the SpaceX Dragon space freighter that arrived at the ISS in January.  The Dragon will be loaded up with scientific experiments to be analyzed back on earth.  Also aboard will be non-essential hardware and a space suit with a malfunctioning fan motor (another space suit aboard the ISS had the same problem, but was repaired.)  The Dragon will be grappled by the 57.7-ft. Canadarm2 robotic arm, then sent back to earth by way of a splashdown near Baja, California.

Another vehicle currently docked at the ISS will be sent home this week, albeit to a fiery demise.  The European ATV-5 cargo vehicle will be loaded with trash and sent home to burst into flames in the atmosphere as it deorbits on Valentine's Day.  How's that for burnin' love?

Artist's rendering of the ATV-5 controlled reentry.  Happy Valentine's Day from space!
(Image courtesy esa.int.)

Other scientific endeavors of note this week on the ISS included Commander Butch Wilmore analyzing seedlings in the APEX-03 experiment to determine the effects of microgravity on plant cells and root systems.  ESA astronaut Samantha Cristoforetti analyzed roundworms in an Epigenetics study, which will assess if new cells develop significantly differently in micro-g.

CNN ran a story on the planning, packaging, and consumption of the food that gets transported to the ISS.  Since the human body cannot truly be at rest while constantly floating in micro-gravity, the astronauts must imbibe 3,000 calories a day, more than the average human on earth should consume.  Food scientist Maya Cooper of the Johnson Space Center explains that their team, who are responsible for 40% of all the food sent by NASA to the ISS, tries to "strike a delicate balance between providing home comforts and healthy food."  This includes everything from M&Ms to birthday cake on the comfort side, but a carefully-reformulated program of sodium reduction on the health side.  Of course, every now and again after a cargo launch, a special treat like fresh fruit might be the first thing out of the hatch.

Astronauts Terry Virts and Samantha Cristoforetti were eager to help unpack the latest SpaceX Dragon, which delivered (among other things) this precious golden cargo.
(Image courtesy NASA.gov.)

Back on earth, this week astronaut Scott Kelly concluded his aquatic training, which is designed to mimic microgravity.  Kelly will be headed to the ISS in March as part of a pioneering endeavor to spend a full year in space.  Looks like he's good to go!

On land...on sea...and in the lack-of-air...astronauts always take care of business!
(Image courtesy NASA.gov.)

Want to see the station for yourself (albeit from beneath the surly bonds of gravity?)  Check out Spot The Station and receive text or email alerts whenever the ISS will be flying by your area!  Then, if you happen to leave your lens open and capture an image of the ISS, tag it to #SpotTheStation or @SpotStationAUT (for Android users.)  Enjoy images by space fans from all over earth!


The space station, captured in long-exposure, swoops past Reunion Island, off the coast of Madagascar.
(Image courtesy @panoramareunion.)

That's all for this week, space fans!  See you next Sunday for news on two upcoming spacewalks...watch this space!


                               Commander Wilmore captured a nice, bright flyby this week.
                                 If you live on the East Coast of the US, you're in this video.
                                    

Source:http://blog.agupieware.com/2015/02/space-station-sunday-ships-that-fell-to.html

Dial-Up Diagnosis: Smartphone Device Identifies HIV Quickly, Cheaply, And Effectively

Sure, your smartphone has always been pretty sharp, but now, a new app makes it intelligent enough to diagnose diseases.  Thanks to a small device that plugs into a phone, HIV can now be detected in 15 minutes, using only a single drop of blood.

HIV hasn't been cured, but now it's much easier to spot.
(Image courtesy spectrum.ieee.org.)

According to bustle.com, the device has been deployed in Rwanda at healthcare facilities for the purpose of detecting HIV and syphilis.  The device was over 90% accurate in its diagnostic capability.  Handheld and lightweight, it can travel to far-flung patients who may not be able to make lengthy treks to clinics for tests.  Best of all, the devices only cost $34 apiece.

The implications of being able to bring this formerly-expensive and arduous technology to the masses are huge, particularly for the most vulnerable sufferers of HIB.  Samuel Sia, head of the device's research team from Columbia University, explained "If you diagnose and treat them on the spot, you can save the life of a newborn… If it’s not treated, you can have stillbirth."  With 17.1 million people in eastern and southern Africa currently suffering from HIV, the device could be a critical element in saving future lives.

That's DR. Smartphone, to you.
(Image courtesy nbcnews.com.)

  

Source:http://blog.agupieware.com/2015/02/dial-up-diagnosis-smartphone-device.html

Don't Just Complete, Compete! New "Push-ups With Friends" App Motivates More Muscles

We're now over a month into the new year - have you managed to maintain your resolutions?  If so, congratulations.  If not, was it because you aimed a little too high, or was it simply a lack of motivation?  If your time got crunched but your belly didn't, now, a new app can help you deal with at least one small aspect of getting fit.

The free new iPhone app PUWF (Push-ups With Friends) is straightforward and effective in the way that documented competition can be.  You do pushups, touching your nose to your smartphone as you complete a rep.  You and your friends will all get notifications when someone else in your group also drops and knocks out some pushups.  A leaderboard indicates monthly progress.  Your ripped arms and back will indicate the rest.

Use your smartphone for "games" that actually improve yourself.
(Image corutesy quickanddirtytips.com.)

With gadgets like the FitBit and entire smartphone systems devoted to managing every element of your health that's technologically trackable (at least without the aid of hospital equipment), the PUWF app eliminates the need for overabundant obsession.  Like a brutal but effective drill sergeant, it just wants you to do more pushups.  It might not yell at you as viciously, but the drive to out-push your friends might motivate you just as well.

What are you waiting for?  Time to unleash those pythons!  Drop and give PUWF fifty!

"You're too pretty to count them on your own!"
(Image courtesy slate.com.)





Source:http://blog.agupieware.com/2015/02/dont-just-complete-compete-new-push-ups.html

Pot Automat? Pot-O-Mat? New Cannabis Vending Machine Debuts In Seattle

Yesterday, in a move that helps to further freedom and medicinal options alike, Seattle became the first location in the state of Washington to allow the usage of a vending machine for medical marijuana.  According to trust.org, the ZaZZZ machine that is the first of its kind began operating on Tuesday for the customers of Seattle Caregivers medical dispensary.

The machine as well as its contents were fired up yesterday.
(Image courtesy cannamagazine.com.)

The ZaZZZ, created by American Green Inc, is an updated version of a similar machine that debuted in April 2014 in Colorado.  Those machines, however, only sold cannabis edibles.  The new and improved ZaZZZ sells the cannabis flower (a.k.a. buds), vaporizer pens, hemp-oil energy drinks, and more.  The first purchase made was for a $15 gram of the "Girl Scout Cookies" cannabis strain.

You will probably also want some real Girl Scout cookies to go with that.
(Image courtesy news.yahoo.com.)

The machine operates by using an ID card scanner, which verifies user identity after a shop employee confirms the client's medicinal-user status.  Stephen Shearin, president of American Green Inc., is enthusiastic about the adoption of the machines, saying, "It's a way to take something that has proven itself as a viable business model throughout the last century, and bring it into the 21st century."

Five ZaZZZes are planned for locations throughout Washington state, with others planned for Alaska, California, Colorado, Rhode Island, and Michigan. Wherever you venture to find one, you won't even need to worry about getting robbed for your stash cash along the way - the ZaZZZ accepts bitcoin!  The future just got a little more chill.

Bits for hits!
(Image courtesy maxkeiser.com.)


Source:http://blog.agupieware.com/2015/02/pot-automat-pot-o-mat-new-cannabis.html

Minggu, 18 Januari 2015

How to Filter Collections in Java 8 with Streams and Predicates



Java 8 provides excellent features to support filtering of elements in Java Collections. Prior to Java 8, only better way to filter elements is by using foreach loop or iterating over Collection using Iterator and selecting required object, leaving out rest. Though that approach work, it was very difficult to run them in parallel and take advantage of multiple CPU available in modern day servers. Java 8 provides Streams, which not only makes it easy to run any operation parallel but also support lazy loading and lazy evaluation, which means as soon as filtering condition is satisfied, it stooped doing work, doesn't matter how many object collection contains. You can filter Java Collections like List, Set or Map in Java 8 by using filter() method of Stream class. You first need to obtain stream from Collection by calling stream() method and than you can use filter() method, which takes a Predicate as only argument. Predicate is a functional interface with couple of boolean valued method e.g. test(), which returns boolean true or false. Java 8 uses this method to filter Collection. Just remember that filter doesn't remove elements which matches the condition given in predicate, instead it selects them in output stream. I agree, little bit counter intuitive, select would have been better name for this method, but once you used it couple of times, you will be Ok. For example, if you have list of String and you want another list which contains only long string say whose length is greater than 20 character, you can use filter method to do that and you don't need a loop. Java 8 Stream is very efficient replacement of looping both design and performance wise, because it separates What to do from how to do, just like SQL. Leaving the implementation part to platform.











Java 8 Filter Method


As I said filter() method is defined in Stream class, it takes a Predicate object and returns a stream consisting of the elements from original stream which matches the given Predicate. It is an intermediate operation, which means you can call any other method of Stream e.g. count() as stream will not be closed due to filtering. Predicate is applied to each element of Collection to check whether a particular element should be included in filtered stream or not. Predicate should be stateless and non interfering so that if needed filter operation can run in parallel using parallel stream. In Java8, Predicate is a functional interface with couple of boolean valued method used to test input against the condition. In our case test(T t) method is used, which evaluate this predicate in given argument. Since filter() method accept a functional interface, you can also pass lambda expression to it, which is what we will do. You can pass any condition to filter elements e.g. either by using relational operator e.g. less than, greater than or equal to or by using methods like equals() and equalsIgnoreCase() as shown in our sample program. 












Java 8 Example of Filtering List using Stream




This is our sample program to demonstrate power of Java 8 Stream and Filter method. By using these Java 8 enhancements you can perform SQL like operation in Java e.g.



SELECT * FROM Deals WHERE type = 'ELECTRONIC'



can be written using Java 8 stream and filter method as



 deals.stream()
.filter(deal -> deal.type() == Deal.Type.ELECTRONIC)
.forEach(System.out::println)



In this example, we are passing a lambda expression to filter method, which returns a boolean. It's actually anonymous function test(), we have omitted type information for deal variable because it will be inferred by JVM easily, making our code concise. In short, you can pass a lambda expression to filter method until result is boolean. The forEach() method is a terminal operation and used here to print all deals present in filtered collection.



Now let's see second example of filtering List in Java. Now we need all deals which are expiring in March. In SQL we can write query like this :



SELECT * FROM Deals WHERE validity='MARCH'



and in Java 8, we can write following code :



deals.stream()
.filter(deal -> deal.validity().getMonth() == Month.MARCH)
.forEach(System.out::println);



Our third example is about filtering elements based upon greater than condition. How about getting all deals which with 30% or more discounts? We can write following query in SQL :



SELECT * FROM Deals WHERE discountPercentage >= 30;



In Java 8 you can use filter method  like below to do the same :



deals.stream()
.filter(deal -> deal.discount().compareTo(new BigDecimal("00.30")) > 0)
.forEach(System.out::println);





Let's see one more example of filtering collection in Java. How about finding all deals from Apple, don't you know iPad and iPhone? We can write SQL query like following to get those deals :



SELECT * FROM Deals WHERE provider='Apple';



In Java 8, You can do  :



deals.stream()
.filter(deal -> deal.provider().equalsIgnoreCase("Apple"))
.forEach(System.out::println);





Here is the complete code which you can run in your favorite IDE or command prompt if you are a down to earth programmer.









How to use Filter method in Java 8




package test;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.Month;
import java.util.ArrayList;
import java.util.List;

/**
* Simple Java value class to represent a deal
*/

public class Deal {

public enum Type {
BOOK,
ELECTRONIC,
TRAVEL,
COSMATIC,
ACTIVITY,
}
private final String provider;
private final Type type;
private final BigDecimal price;
private final BigDecimal discount;
private final String title;
private final LocalDate validity;

public Deal(String provider, Type type, BigDecimal price,
BigDecimal discount, String title, LocalDate validity) {
this.provider = provider;
this.type = type;
this.price = price;
this.discount = discount;
this.title = title;
this.validity = validity;
}

public String provider() {
return provider;
}

public Type type() {
return type;
}

public BigDecimal price() {
return price;
}

public BigDecimal discount() {
return discount;
}

public String title() {
return title;
}

public LocalDate validity() {
return validity;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(title).append(" from ").append(provider).
append(", price : ").append(price).
append(", offer valid till ").append(validity).
append(" category : ").append(type);
return sb.toString();
}

}


/**
* Java 8 Example to filter Collection on Predicates using Stream API. this
* program also uses new Date and Time API, lambdas, method reference etc.
*
* @author Javin Paul
*/

public class Java8FilterDemo {

public static void main(String args[]) {

List deals = loadDeals();
System.out.println("All Deals");
System.out.println("--------------------------------");

// this will print all deals from list
deals.forEach(System.out::println);

System.out.println("--------------------------------");

// Filtering elements from a Collection in Java 8
// filtering on category
System.out.println("All deals for Electornic items");
deals.stream().filter(deal -> deal.type() == Deal.Type.ELECTRONIC).forEach(System.out::println);
System.out.println("--------------------------------");

// filter all deals which are expiring on March
System.out.println("Deals expiring on March");
deals.stream().filter(deal -> deal.validity().getMonth() == Month.MARCH).forEach(System.out::println);
System.out.println("--------------------------------");

// filter all deals which has more than 30% discount
System.out.println("All deals with 30% or more discount");
deals.stream().filter(deal -> deal.discount().compareTo(new BigDecimal("00.30")) > 0).forEach(System.out::println);
System.out.println("--------------------------------");

// filter all deals from companies
System.out.println("All deals from Apple");
deals.stream().filter(deal -> deal.provider().equalsIgnoreCase("Apple")).forEach(System.out::println);
System.out.println("--------------------------------");
}

private static List loadDeals() {
List deals = new ArrayList<>();
deals.add(new Deal("Manning", Deal.Type.BOOK,
new BigDecimal("30.00"), new BigDecimal(".50"),
"Save 50% on Java 8 Books", LocalDate.of(2014, Month.MARCH, 20)));

deals.add(new Deal("Amazon", Deal.Type.BOOK,
new BigDecimal("20.00"), new BigDecimal(".20"),
"Save 20% on Clean Code", LocalDate.of(2014, Month.FEBRUARY, 10)));

deals.add(new Deal("Kathy Pacific", Deal.Type.TRAVEL,
new BigDecimal("300.00"), new BigDecimal(".40"),
"Save 40% on flight to USA", LocalDate.of(2014, Month.FEBRUARY, 19)));

deals.add(new Deal("Luftanse", Deal.Type.TRAVEL,
new BigDecimal("30.00"), new BigDecimal(".50"),
"Save 50% on flight to Berlin", LocalDate.of(2014, Month.MARCH, 27)));

deals.add(new Deal("Trekking", Deal.Type.ACTIVITY,
new BigDecimal("400.00"), new BigDecimal(".50"),
"Save 50% on Trekking", LocalDate.of(2014, Month.MARCH, 25)));

deals.add(new Deal("Apple", Deal.Type.ELECTRONIC,
new BigDecimal("800.00"), new BigDecimal(".10"),
"10% discount on iPhone 5S", LocalDate.of(2014, Month.APRIL, 19)));

deals.add(new Deal("Samsung", Deal.Type.ELECTRONIC,
new BigDecimal("700.00"), new BigDecimal(".20"),
"20% discount on Galaxy S4", LocalDate.of(2014, Month.MARCH, 18)));

deals.add(new Deal("LG", Deal.Type.ELECTRONIC,
new BigDecimal("390.00"), new BigDecimal(".50"),
"Save 40% on LG Smartphones", LocalDate.of(2014, Month.FEBRUARY, 17)));

deals.add(new Deal("Sony", Deal.Type.ELECTRONIC,
new BigDecimal("500.00"), new BigDecimal(".50"),
"Save 50% on Sony Viao Laptops", LocalDate.of(2014, Month.APRIL, 10)));
return deals;
}

}


Output:

All Deals
--------------------------------
Save 50% on Java 8 Books from Manning, price : 30.00, offer valid till 2014-03-20 category : BOOK
Save 20% on Clean Code from Amazon, price : 20.00, offer valid till 2014-02-10 category : BOOK
Save 40% on flight to USA from Kathy Pacific, price : 300.00, offer valid till 2014-02-19 category : TRAVEL
Save 50% on flight to Berlin from Luftanse, price : 30.00, offer valid till 2014-03-27 category : TRAVEL
Save 50% on Trekking from Trekking, price : 400.00, offer valid till 2014-03-25 category : ACTIVITY
10% discount on iPhone 5S from Apple, price : 800.00, offer valid till 2014-04-19 category : ELECTRONIC
20% discount on Galaxy S4 from Samsung, price : 700.00, offer valid till 2014-03-18 category : ELECTRONIC
Save 40% on LG Smartphones from LG, price : 390.00, offer valid till 2014-02-17 category : ELECTRONIC
Save 50% on Sony Viao Laptops from Sony, price : 500.00, offer valid till 2014-04-10 category : ELECTRONIC
--------------------------------
All deals for Electornic items
10% discount on iPhone 5S from Apple, price : 800.00, offer valid till 2014-04-19 category : ELECTRONIC
20% discount on Galaxy S4 from Samsung, price : 700.00, offer valid till 2014-03-18 category : ELECTRONIC
Save 40% on LG Smartphones from LG, price : 390.00, offer valid till 2014-02-17 category : ELECTRONIC
Save 50% on Sony Viao Laptops from Sony, price : 500.00, offer valid till 2014-04-10 category : ELECTRONIC
--------------------------------
Deals expiring on March
Save 50% on Java 8 Books from Manning, price : 30.00, offer valid till 2014-03-20 category : BOOK
Save 50% on flight to Berlin from Luftanse, price : 30.00, offer valid till 2014-03-27 category : TRAVEL
Save 50% on Trekking from Trekking, price : 400.00, offer valid till 2014-03-25 category : ACTIVITY
20% discount on Galaxy S4 from Samsung, price : 700.00, offer valid till 2014-03-18 category : ELECTRONIC
--------------------------------
All deals with 30% or more discount
Save 50% on Java 8 Books from Manning, price : 30.00, offer valid till 2014-03-20 category : BOOK
Save 40% on flight to USA from Kathy Pacific, price : 300.00, offer valid till 2014-02-19 category : TRAVEL
Save 50% on flight to Berlin from Luftanse, price : 30.00, offer valid till 2014-03-27 category : TRAVEL
Save 50% on Trekking from Trekking, price : 400.00, offer valid till 2014-03-25 category : ACTIVITY
Save 40% on LG Smartphones from LG, price : 390.00, offer valid till 2014-02-17 category : ELECTRONIC
Save 50% on Sony Viao Laptops from Sony, price : 500.00, offer valid till 2014-04-10 category : ELECTRONIC
--------------------------------
All deals from Apple
10% discount on iPhone 5S from Apple, price : 800.00, offer valid till 2014-04-19 category : ELECTRONIC






That's all about how to filter collection in Java 8.  This is just an example of  super power of new stream API. You can write more expressive code, which is easy to understand, easy to optimize and super easy to run in parallel without you worrying about multi-threading nightmare. Together with lambda expression, method references and new Stream API, Java has become super expressive language without added boiler plate.



 If you like this Java 8 tutorial and hungry for more Java 8 articles, don't forget to checkout these :


  • How to use Lambda Expression in Place of Anonymous class (read here)

  • How to use Map function in Java 8 (see more)

  • How to use Default method in Java 8. (see here)

  • Java 8 Comparator Example (see example)

  • Free Java 8 tutorials and Books (read book)

  • Top 10 tutorials to Learn Java 8 (read here)


























Source:http://javarevisited.blogspot.com/2015/02/how-to-filter-collections-in-java-8.html

On The Road Again? Never Lose Power Thanks To New &quot;SmartBackpack&quot;

Let's face it, electronic gadgets govern huge swaths of our modern lives.  Try going a day without your cellphone.  Think about the horror of hitting the gym without your trusty mp3 player.  And of course, the ubiquity of tablets and e-readers has now made them indispensable as well.  So, how do you keep them all powered for hours?

According to wired.com, a new wearable battery charger/backpack is the nomadic, stylish answer for how to induce the juice.  Equipped with an onboard charger that's capable of powering up your phone, camera, or even laptop, the AMPL SmartBackpack has got you covered.  Capable of charging multiple devices at once, an OLED screen informs you of progress, as well as weather conditions that may be a hindrance to you or your tech toys.  This intel can also be sent to your smartphone via an app (of course.)

Neglect none of your devices thanks to the SmartBackpack.
(Image courtesy indiegogo.com.)

A hierarchy of charging can be established so that more important devices juice up first.  At maximum output, the SmartBackpack offers 147 Wh of charge.  The modular batteries inside can be removed and used individually, or the entire backpack itself can be plugged into a wall socket to re-up its own power.

Currently engaged in an indiegogo.com campaign for development, the SmartBackpack will be for sale at $225 in pre-production, and $250 later in 2015.  It might be pricey for a backpack, but it's invaluable for today's tech gypsies who crave constant connectivity.  And maybe you can recoup some of the expense by renting out your power to electronically-estranged folks who planned their battery life badly.

Workaholics, your dreams have come true.
(Image courtesy ampl-labs.com.)


Source:http://blog.agupieware.com/2015/02/on-road-again-never-lose-power-thanks.html

Green Power In The Green Mountain State: Vermont&#39;s Largest City Is Fueled By Renewable Energy

Vermont has always been known as "The Green Mountain State", but now, it's the "green city" state, too.  Vermont's capital, Burlington, now uses 100% sustainable methods to provide power to their citizens.

As reported by PBS, the city of Burlington actually makes or obtains more power than it uses, and all derived from "green" sources. At a population of 42,000, Burlington is the most populous state in Vermont, all powered by renewable energy from Burlington Electric.  Ken Dolan, a Burlington Electric worker, explained that this way, power is not only gathered and used in a safer manner than fossil fuels, but it is also cheaper in the long run as a means for the city to energize itself.

The Winooski One hydroelectric plant uses water to turn turbines, creating energy.
(Image courtesy thinkprogress.org.)

The change to renewables is estimated to save the city $20 million dollars over the next two decades, and it's already helped make significant strides.  Burlington's utility bill rates haven't risen since 2009.

The power itself is derived from several sources.  About a third of it comes from burning biomass (in this case, salvaged scrap wood that is burned to heat steam and thus generate electricity.)  Another 20% comes from wind turbines and solar power.  Thanks to the rivers of snowy mountain runoff that power hydroelectric facilities, the majority of the energy is harvested from hydro (which spins giant underground turbines to generate electricity.)

The J.C. McNeil power plant in Burlington, where biomass is converted to power.
(Image courtesy vtdigger.org.)

With Vermont relying deeply on nature to maintain their tourism (skiing and maple syrup are big moneymakers in the Green Mountain State), it's important to Vermonters to keep the environment happy.  Using renewable energy sources keeps things pleasant for the natural world as well as the citizens' wallets.  If their example can be extrapolated to larger areas in the country, we could be well on our way to improving conditions for all by kicking the fossil fuel habit for good.

A few windmills in the mountain vista are worth not having to be reliant on fossil fuels.
(Image courtesy revermont.com.)


Source:http://blog.agupieware.com/2015/02/green-power-in-green-mountain-state.html