New NodeJS 12 feature look more enterprise java now

New NodeJS 12 support thread and it is more stable

Threads are almost stable!

With the last LTS we’ve got access to threads. Of course, it was an experimental feature and required a special flag called –experimental-worker for it to work.

With the upcoming LTS (Node 12) it’s still experimental, but won’t require a flag anymore. We are getting closer to a stable version!

https://morioh.com/p/027e49ee6bce/new-node-js-12-features-will-see-it-disrupt-ai-iot-and-more-surprising-areas

V8 Gets an Upgrade: V8 update to V8 7.4

Hello TLS 1.3

Properly configure default heap limits

Switch default http parser to llhttp

Making Native Modules Easier — progress continues

Worker Threads

Diagnostic Reports

Heap Dumps

Startup Improvements

ES6 Module Support

New compiler and platform minimums

https://medium.com/@nodejs/introducing-node-js-12-76c41a1b3f3f

The creation of Telegram MyWeatherTodayBot

What is Telegram?

Telegram is a messaging app with a focus on speed and security, it’s super-fast, simple and free. You can use Telegram on all your devices at the same time — your messages sync seamlessly across any number of your phones, tablets or computers.

With Telegram, you can send messages, photos, videos and files of any type (doc, zip, mp3, etc), as well as create groups for up to 200,000 people or channels for broadcasting to unlimited audiences. You can write to your phone contacts and find people by their usernames. As a result, Telegram is like SMS and email combined — and can take care of all your personal or business messaging needs.

What is Telegram Bot?

Bots are third-party applications that run inside Telegram. Users can interact with bots by sending them messages, commands and inline requests.

What is MyWeatherTodayBot?

MyWeatherTodayBot is a Telegram Bot that’s able to send your location and get real time weather forecast.

How MyWeatherTodayBot made?

MyWeatherTodayBot is made by PHP and a web service to get weather forecast. First it receives user input as location (latitude and longitude), and the bot will send a REST POST to an external web service to get weather forecast.

To make your own MyWeatherTodayBot, you need Telegram Apps, and Invited @BotFather (a Telegram own bot that you can create your bot) to your accounts, that you can get started to create bot.

Step by Step to create MyWeatherTodayBot

  1. Chat with @BotFather
  2. Click and send /newbot
  3. Name your bot
  4. Copy the API token and it looks like this: 898795721:AAGkiU2Taw83m6CDpVSpH4PaVbEaFkIByHo
  5. Write a PHP file and hosts on a web server, assume the location of the file is at https://<your web server>/bot/telegrambot.php
  6. With following code
[code] $endpoint = 'https://api.telegram.org/bot898795721:AAGkiU2Taw83m6CDpVSpH4PaVbEaFkIByHo'; $action = !empty($_GET['action']) ? $_GET['action']:''; function reply($chat_id, $text, $opts = array()) { global $endpoint; $url = $endpoint . ‘/sendMessage?text=’.urlencode($text) . ‘&chat_id=’.$chat_id; if(!empty($opts[‘reply_markup’])) { $url .= ‘&reply_markup=’ . json_encode($opts[‘reply_markup’]); } if(!empty($opts[‘parse_mode’])) { $url .= ‘&parse_mode=’ . urlencode($opts[‘parse_mode’]); } file_get_contents($url); } if($action == ‘setWebhook’) { $url = ‘https://<your web server>/bot/telegrambot.php?action=incoming’; echo file_get_contents($endpoint.’/setWebhook?url=’.urlencode($url)); } else if($action == ‘info’) { echo file_get_contents($endpoint.’/getMe’); } else if($action == ‘incoming’) { $entityBody = file_get_contents(‘php://input’); $incoming = json_decode($entityBody, true); $username = $incoming[‘message’][‘from’][‘username’]; $chatid = $incoming[‘message’][‘from’][‘id’]; $input = $incoming[‘message’][‘text’]; $location = $incoming[‘message’][‘location’]; if(!empty($location)) { $latitude = $location[‘latitude’]; $longitude = $location[‘longitude’]; $userData[‘weather’][‘latitude’] = $latitude; $userData[‘weather’][‘longitude’] = $longitude; $url = “https://api.imgshow-apps.com/?api=1&k=q:name=weather,lat=$latitude,lng=$longitude,display=label,stat=telegrambot”; $label = file_get_contents($url); reply($chatid, $label); } else { reply($chatid, ‘Enter your location to get weather now’, array( ‘reply_markup’ => array( ‘one_time_keyboard’ => true, ‘keyboard’ => array( array( array(‘text’ => ‘My Location’,’request_location’ => true) ) ) ) )); } } [/code]

 

7. Now, in your Internet browser, access https:///bot/telegrambot.php?action=setWebhook, which will register a webhook to your bot.

8. And now, you can start testing with your telegram bot now.

Phantomjs fails to load HTTPS issue as switching to tlsv1

I had an apps to use phantomjs to generate a report by using Google Charts.

The apps will spawn a child process to execute phantomjs command, to load a web page that contains the charts, and then take a screenshots saving into JPG, which later convert into PDF for archive.

In the code, it needs to load the following JS URL from Google: https://www.google.com/jsapi, which is HTTPS based.

Suddenly it is stopped working since last month.

By checking the log and found that PhantomJS encountered JavaScript error: “ReferenceError, can’t find Google”. Hey, I tried to open the web page in my local Chrome browser, and it still working. I tried to CuRL from my server, still can download the page. So I suspected might be SSL issues on PhantomJS.

Tried googling and found a solution. As Google had already deprecated the old version of SSL (SSLv3) and use TLSv1.

In the command line, we need to add one more option: –ssl-protocol=tlsv1, to bypass the HTTPS error, and it turns out it is working now.


phantomjs --ssl-protocol=tlsv1 your-code.js

Java——永存、曲折、低谷、重生!

Java——永存、曲折、低谷、重生!
Java作为最流行的编程技术之一,带给软件产业深远影响,也改变了许多人的人生轨迹。值Java二十年之际,本期《程序员》邀请Java领域技术专家、知名图书作者从他们的角度谈谈Java的技术变迁以及在各个领域的技术实战。

安全曾让Java蒙羞,安全也让Java重获新生。在2014 Pwn20wn黑客大会上,Java成为唯一没有被攻破的平台。而在2015的会议中,Pwn20wn甚至没有把Java列在攻击名单上。

对于Oracle的接管,Gosling表达了自己的喜悦之情,“得知这个消息后,我感到非常惊喜。Oracle是个非常优秀的监护人并大大超出了我的期望。一开始我还担心它会不会成为第二个Solaris,现在看来我是多虑了。”

虽然很多人都曾预言Java将一蹶不振,但是现今在不少的重要项目中,Java仍扮演着极其重要的角色。
Purdy指出,没有Java,甚至不会有大数据的大发展,“Hadoop本身就是用Java编写的。当你需要在运行MapReduce的服务器集群上发布新功能时,你需要进行动态的部署,而这正是Java所擅长的。”
另一Java受惠者是Twitter。一开始Twitter是用Ruby on Rails编写的,但是随着用户数的增长RoR逐渐显得力不从心。Fail Whale(失败鲸)的宕机画面预示着瓶颈问题亟需解决。在2012年,Twitter从RoR转向了Java和Scala,而失败鲸从此灭绝了。

Link: http://m.csdn.net/article/2015-04-20/2824514-Java

ReSnap – A Smart Automated Photo Book Creation Platform

ReSnap – A Smart Automated Photo Book Creation Platform

ReSnap, a company that automatically creates a book of photographs from a range of sources, has announced an update for its beta platform, with a revamped platform that allows you to upload photos from local storage – it will then automatically pick the best images from the selection without you having to do anything.

http://thenextweb.com/insider/2015/04/23/resnap-expands-its-smart-automated-photo-book-creation-platform/

http://thenextweb.com/apps/2014/04/24/resnap-retools-print-demand-photo-book-platform-work-virtually-big-data-source/

Hello world on HomeKit

I just setup a HomeKit apps on my home, using Apple Siri to control my television.

First, need a smart home device, for example Sony Bravia TV which connected to a home WIFI. Second, requires a HomeKit Server talking HomeKit Protocol. This server will interact with other smart home device registered as accessories. Third, requires a HomeKit client installed on mobile, which talking to HomeKit Server, adding any accessories available from HomeKit server. In usual setup, HomeKit server can installed on Raspberry PI, but I don’t have, use my Mac to host it.

The following procedures will help to setup.

1) Get a Mac with Node JS installed. Get a Apple licensed developer program.

2) Download a HomeKit Demo Swift based project, run it on your mobile. Download at https://github.com/KhaosT/HomeKit-Demo.

3) Download a HomeKit Server, I am homebridge. It is a Node.JS based server. Download at https://github.com/nfarina/homebridge.

4) Download Bravia Controlled library which is also Node.JS based. Download at https://github.com/alanreid/bravia.

5) Follow instruction on how to control Bravia TV by using the library. And then, you may build a HTTP based interface around the Bravia library. And then, you may program HomeKit server apps, add a new accessories, and then send the command requests to Bravia Server via HTTP (Turn on/off TV). The last part is much more tricky, to setup HomeKit client talks to HomeKit server.

6) Important note, once you had HomeKit client installed, navigate to one of accessories, look for the service name, this is the name Siri will look and map into. Name it as “television”, or some fancy name, which you will tell Siri to look for and do the action.

7) After that, if everything goes well, you can turn on your Siri, and say “Siri, turn on television”. Then your television magically turned on. Enjoy.

Tutorial on setup OpenCV on iOS

This tutorial is to setup OpenCV on iOS. To include opencv2.framework to iOS8 Objective C Project.

By following this tutorial: http://docs.opencv.org/doc/tutorials/ios/hello/hello.html#opencvioshelloworld

1) to download prebuilt opencv2.framework, the fine working version is 2.4.9.

2) to create new XCode Project, target iOS8.0 if you are under XCode 6.0.1 as this version not yet support iOS8.1

3) link opencv2.framework to XCode Project. Go to project build phase, and link following frameworks:
opencv2.framework
AssetsLibrary.framework
AVFoundation.framework
CoreGraphics.framework
CoreImage.framework
CoreMedia.framework
CoreVideo.framework
Foundation.framework
UIKit.framework
Accelerate.framework

Screen Shot 2015-01-20 at 12.42.28 am

4) Create <NameOfProject>-Prefix.pch, with following snippets of code add between ifdef / endif block.

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif

5) in ViewController.h, add the following to header
#import <opencv2/highgui/cap_ios.h>
#include <opencv2/opencv.hpp>

Note, the most important line is #include <opencv2/opencv.hpp>, this is important to make the stuffs works. I spent few hours and found this solve my problems, which unable to recognize cvtColor function, OK, will introduce in next steps.

6) To do some testing, by adding a video camera, reading 30 frames per second, process the images by inverting the color…

7) Rename ViewController.m to ViewController.mm as we are going to put C PlusPlus Code. Extension mm allows coexist of Objective C and C PlusPlus.

8) In ViewController.h, add following line
@property (nonatomic, retain) CvVideoCamera* videoCamera;

9) In ViewController.mm, we initialize videoCamera and starts it.

self.videoCamera = [[CvVideoCamera alloc] initWithParentView:_ImageView];
self.videoCamera.delegate = self;
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionFront;
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPreset352x288;
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.videoCamera.defaultFPS = 30;
[self.videoCamera start];

10) In ViewController.h, add CvVideoCameraDelegate

Like this

@interface ViewController : UIViewController

11) In ViewController.mm, add following snippets of code before @end.

#pragma mark – Protocol CvVideoCameraDelegate

#ifdef __cplusplus
– (void)processImage:(Mat&)image;
{
// Do some OpenCV stuff with the image
Mat image_copy;
cvtColor(image, image_copy, CV_BGRA2BGR);
bitwise_not(image_copy, image_copy);
cvtColor(image_copy, image, CV_BGR2BGRA);
}
#endif

12) Run the project. Cheers.

Photo 20-1-15 12 51 57 am

Install CMake on Mac

CMake, the cross-platform, open-source build system. CMake is a family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files. CMake generates native makefiles and workspaces that can be used in the compiler environment of your choice.

To install CMake on Mac, you can download the precompiled binaries here. Under platforms Mac OSX 10.6 or later, I chose cmake-3.1.0-Darwin64.dmg at the time of writing.

Once downloaded, run open cmake-3.1.0-Darvin64.dmg on terminal.

A finder view shown. Drag cmake-3.1.0-Darvin64.dmg to Applications shortcut, it will copy the binary to Applications folder.

Open the applications by sudo.

Do sudo /Applications/CMake.app/Contents/MacOS/CMake

Click on menu Tools, Install for Command line use.

You shall see the result, then you are done.

Screen Shot 2015-01-17 at 7.25.34 pm