Jan
2
2020
JSON is a versatile format to define data. I read and write JSON all the time but as a subset of JavaScript, it has a few limitations, most notably the lack of support for comments. Enter HJSON, or Human JSON. HJSON makes quotes around object names optional, it makes quotes around strings optional as well, it adds support for multi-line strings, and allows you to add comments in a number of ways. The following is valid HJSON.
{
// use #, // or /**/ comments,
// omit quotes for keys
key: 1
// omit quotes for strings
contains: everything on this line
// omit commas at the end of a line
cool: {
foo: 1
bar: 2
}
// allow trailing commas
list: [
1,
2,
]
// and use multiline strings
realist:
'''
My half empty glass,
I will fill your empty half.
Now you are half full.
'''
}
There is an implementation of HJSON for most popular languages, like Java, Python, Go, Python, etc. I’ve used the hjson-java library to read HJSON file and converted it to JSON in a few lines.
no comments | tags: hjson, human json, json | posted in Java, JavaScript, Programming, TechKnow
Dec
27
2019
Here is a quick tutorial on how to create a local embedded HTTP server in Java to serve JSON data. The whole code in less than 30 lines on Java.
package com.juixe.json.server;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import java.io.IOException;
import java.net.InetSocketAddress;
public class JSONServer implements HttpHandler {
public static void main(String[] args) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
server.createContext("/data", new JSONServer());
server.setExecutor(null);
server.start();
}
@Override
public void handle(HttpExchange he) throws IOException {
String response = "{\"message\": \"Hello, HTTP Client\"}";
he.getResponseHeaders().set("Content-Type", "application/json;charset=UTF-8");
he.sendResponseHeaders(200, response.length());
he.getResponseBody().write(response.getBytes());
he.close();
}
}
The HttpServer and HttpHandler classes are part of the JRE, so no additional libraries are required. Java also includes a HttpsServer which supports SSL. In the HttpHandler, you can return any data but for this example we are returning a simple JSON response.
no comments | tags: http, Java, json, server, tutorial | posted in Java, Programming, TechKnow
Dec
15
2019
Every programmer should be well versed with Bash, from finding files to schedule tasks. The following are some of the most common Bash commands that I use on a weekly basis.
- grep -i aBc <FILE>
- grep –color abc <FILE>
- Color highlight matching pattern
- grep -v ABC <FILE>
- Ignore any lines that include ABC
- grep abc $(find . -mtime 0 -type f)
- Grep recently modified files
- grep “abc xyz” <FILE> | grep “02/03/19 09”
- Find all lines that contain “abc xyz” and then find the remaining lines that contain the following timestamp
- ps -ef | grep java
- history | grep git
- Find all commands in the history that contain the word git
- history -cw
- wc -l <FILE>
- ls -1 | wc -l
- Count the number of files in the current directory
- ls -lh
- Show the size unit of the file, such as K for kilobyte, M for megabyte, etc
- ln -s <SOURCE_FILE> <LINK_FILE>
- Create a symbolic file link reference to <SOURCE_FILE>
- df -P <FILE>
- Find free disk space and if it’s mounted
- du -hs
- Find disk usage for each file in current directory
- cat /dev/null > <FILE>
- zip -r <FILE>
- Zip all contents in current directory into the specified zip file
- zip -er <FILE> <DIRECTORY>
- Zip and encrypt all contents in given directory into the specified zip file
- zip -d <FILE> “file.txt”
- Remove file file.txt from the specified zip file
- unzip -l <FILE>
- List contents of given zip file
- diff -rq <DIRECTORY_ONE> <DIRECTORY_TWO>
- Recursively diff two directory structures
- crontab -l
- List cron rules for current user
- crontab -e
- at -f <COMMAND> -t 201906160701
- Schedule a command or batch file to run at the specified time
- atq
- List current scheduled tasks
- atrm
- uuidgen
- date | md5
- Use md5 on a date to generate a UUID based on a hash
- $RANDOM
- Create a random number between 0 and 32k
- tcpdump -ni eth0 -vvv -s0 -w capture.pcap
- Listen to eth0 interface in verbose mode and write out to file
- tcpdump -ni eth0 port 1812 or port 1813 -vvv -s0 -w capture.pcap
- Listen to eth0 interface for only ports 1812 and 1813
no comments | tags: bash, commands, linux, unix | posted in Mac, Programming, TechKnow, Tools
Oct
12
2019
Software companies like Facebook, Apple, Google, and the like are collecting and amassing large amounts of personal information about each of us. A large portion of this information is posts, tweets, texts, pictures we’ve taken and published. Additionally, there is a large about of derived and meta data such as our search history and geo-location data as we go throughout our day.
Much of the public discussions around personal information is around privacy. But as of late, I’ve been concerned about being able to leave our digital footprint onto our descendants or in the public domain. For example, I’ve taken over 500,000 photographs in the last 10 years, admittedly I’m sure most of them are not great, but this data set of images can be useful in a historical context.
Companies like Facebook and Apple should enable features to allow their users to designate how their data can be used, and ultimately shared, after death. It should be possible to build the means to determine what type of data to either share with our descendants or public domain at a specified time after we’ve passed.
Of course, a feature that allows for data, and even accounts, to be inherited is not trivial. This task is made even more difficult because there is some data we would not like to reveal even after we’ve been dead and gone. And of course, no one wants to manually sort thousands of posts, hundreds of thousands of photos, millions of text messages for potentially embarrassing or possibly misunderstood items. Such system needs to work effortlessly behind the scenes.
no comments | tags: data donor, death, digital inheritance, inheritance | posted in Programming, Social
Jul
6
2012
There is nothing more that I like than to received a comment to some post I wrote years ago on how it helped someone out. Like this, I’ve come to know that small chunks of code I’ve freely made available are used in production at a variety of sites. It is my hope that the tutorials, examples, and code I write here is of help to others. Even though I like writing tutorials and code to help out my fellow developers, I’ve never answered or posted a question on StackOverflow. My technical blog is really a labor of love and I post around my busy schedule, I’ve never tried to do more than just write about the technology that I use. But even though I don’t use StackOverflow I recently found out from looking at my analytics that I receive a nice amount of visitors from the question and answer site.

StackOverflow Stats
It always surprises me which posts are the most visited. It’s always the one that you least expect. Either way, I’m always grateful that others have found them useful enough to share on sites like StackOverflow.
no comments | tags: analytics, blog, posts, stackoverflow, statistics, top posts | posted in Programming, Social, Tools
Jun
26
2012
Most business applications display some amount of data in charts and graphs. If a picture is worth a thousand words, then a clean visual representation of business data is worth a lot more. Business charts can condense a lot of data points into a easy to understand graph.
Recently, I was tasked with updating the graph solution of a financial application with a HTML5 friendly charting tool or library. I looked at about half a dozen JavaScript chart libraries and eventually narrowed the selection down to two based on features and functionality: Google Charts and jQuery chart plugin jqPlot. Both Google Charts and jqPlot support a large number of chart types, from the basic bar and pie to more advance features such as multiple y-axis and and zoom. Both libraries support HTML5 graphics, the legacy chart solution I was to replace generated a pixelated image. Google Charts and jqPlot both draw the graph into div tag instead by using HTML5 graphics and don’t anti-aliasing issues.
For this particular project, we picked jqPlot over Google Charts for the following reasons. Google Charts is not open sourced and it uses a loading mechanism that requires you to be online to load the JavaScript source files from Google’s servers. This is great if you are always online, but the project owners wanted a HTML5 charting solution that works offline. jqPlot is a freely available open source JavaScript library which can be hosted alongside with the other application resources. jqPlot, like Google Charts, has a large number of chart types it supports including line, area, bubble, bar stacked, pyramid, pies, donuts, gauges, and much more.

jqPlot JavaScript Chart Library
1 comment | tags: bar graph, charting, google charts, graph, javascript, jqplot, jquery, js | posted in HTML/XML, JavaScript, Programming, TechKnow