com.google.gson library needs to be added to use this code.
Here is the example string:
String companyDetails = {"companyName":"abcd","address":"abcdefg"}
JSON strings can be parsed using below syntax in Java:
JsonParser parser = new JsonParser();
Json...
The word count program is like the "Hello World" program in MapReduce.
Hadoop MapReduce is a software framework for easily writing applications which process vast amounts of data (multi-terabyte data-sets) in-parallel on large clusters (thousands of nodes) of commodity hardware in a relia...
PM2 lets you run your nodejs scripts forever. In the event that your application crashes, PM2 will also restart it for you.
Install PM2 globally to manager your nodejs instances
npm install pm2 -g
Navigate to the directory in which your nodejs script resides and run the following command each t...
To start the process:
$ forever start index.js
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info: Forever processing file: index.js
List running Forever instances:
$ forever list
i...
When adding a LIMIT to a UNION, this is the pattern to use:
( SELECT ... ORDER BY x LIMIT 10 )
UNION
( SELECT ... ORDER BY x LIMIT 10 )
ORDER BY x LIMIT 10
Since you cannot predict which SELECT(s) will the "10" will come from, you need to get 10 from each, then further whittle do...
Strict mode also prevents you from deleting undeletable properties.
"use strict";
delete Object.prototype; // throws a TypeError
The above statement would simply be ignored if you don't use strict mode, however now you know why it does not execute as expected.
It also prevents you fr...
Remember to npm install all the files into devDependencies first. E.g.
npm install --save-dev gulp gulp-concat gulp-rename gulp-uglify gulp-uglifycss
Gulpfile.js
var gulp = require('gulp');
var gulp_concat = require('gulp-concat');
var gulp_rename = require('gulp-rename');
var gulp_uglify = ...
To create a parallel collection from a sequential collection, call the par method. To create a sequential collection from a parallel collection, call the seq method. This example shows how you turn a regular Vector into a ParVector, and then back again:
scala> val vect = (1 to 5).toVector
vect:...
The most common mode of using TensorFlow involves first building a dataflow graph of TensorFlow operators (like tf.constant() and tf.matmul(), then running steps by calling the tf.Session.run() method in a loop (e.g. a training loop).
A common source of memory leaks is where the training loop conta...
PyPar is a library that uses the message passing interface (MPI) to provide
parallelism in Python. A simple example in PyPar (as seen at https://github.com/daleroberts/pypar) looks like this:
import pypar as pp
ncpus = pp.size()
rank = pp.rank()
node = pp.get_processor_name()
print 'I am r...
package com.example.my.package;
The package declaration should not be line wrapped, regardless of whether it exceeds the recommended maximum length of a line.
Source code and comments should generally not exceed 80 characters per line and rarely if ever exceed 100 characters per line, including indentation.
The character limit must be judged on a case by case basis. What really matters is the semantical “density” and readability of the line. Making l...
If a line approaches the maximum character limit, always consider breaking it down into multiple statements / expressions instead of wrapping the line.
Break before operators.
Break before the . in chained method calls.
popupMsg("Inbox notification: You have "
+ newMsgs + &...
You can also use line-height to center vertically a single line of text inside a container :
CSS
div {
height: 200px;
line-height: 200px;
}
That's quite ugly, but can be useful inside an <input /> element.
The line-height property works only when the text to be centered spans ...
Note the use of {{.}} to output the item within the template.
package main
import (
"fmt"
"os"
"text/template"
)
func main() {
const (
letter = `Dear {{.}}, How are you?`
)
tmpl, err := template.New("letter").Pa...
In this example, a function map named funcMap is supplied to the template via the Funcs() method and then invoked inside the template. Here, the function increment() is used to get around the lack of a less than or equal function in the templating language. Note in the output how the final item in t...
With methods in golang you can do method "chaining" passing pointer to method and returning pointer to the same struct like this:
package main
import (
"fmt"
)
type Employee struct {
Name string
Age int
Rank int
}
func (empl *Employee) Promote() *...
It is possible to specify log destination with something that statisfies io.Writer interface. With that we can log to file:
package main
import (
"log"
"os"
)
func main() {
logfile, err := os.OpenFile("test.log", os.O_RDWR|os.O_CREATE|os.O_APPEND,...