Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Friday, December 4, 2015

rosetta-stone

One thing that I've come to realize while being a Software Engineer is that I enjoy learning different programming languages, build tools, frameworks, libraries, etc in programming. Now, almost every language/framework/library has their own "How To" guide, but it's usually very basic - how to setup your environment, how to write your first line of code, how to compile, etc. I thought it would be fun to make a "How To" for programming tasks - print to the user, comparison, sorting, etc. That's when I stumbled up Rosetta Code's Programming Tasks page, which has an enormous list of different tasks done in various languages. Once I found this, I decided to make rosetta-stone.

rosetta-stone is a repository which has examples of various programming tasks done in various languages. The tasks that I have completed so far are:

  • hello-world - Print "Hello World!" to the standard out.
  • command-line-arguments - Print the total number of arguments and each argument to the standard out.
  • integer-comparison - Compare two integers and see if the first one is less than, equal to, or greater than the second.
  • string-comparison - Compare two strings and see if they are equal with and without case and their lexicographical ordering.
For each task, I currently have examples in Java, Scala, and Clojure, however I plan on expanding the number of languages in the future. I also plan on adding new tasks and categories as I progress.

Stay tuned for updates on this repository for new tasks and programming languages.

Saturday, October 24, 2015

Crypto-Tool

When downloading files from websites, there are usually MD5 and SHA-1 checksums pasted on the site next to the download link. The reason for these checksums is so one can verify the integrity of the downloaded file. Once the file has been downloaded, you run a local hash of the file and verify that your checksum matches the one pasted on the site. Should they match, you know that the file hasn't been tampered with or you downloaded an incorrect file (though there is a minute chance of a hash collision).

Now this sounds like a really easy way to guarantee that you have downloaded the correct file from a website, but how many people actually run a local hash and check their checksums? I know I don't do it (even though I know I should), and I am willing to bet a lot of other people don't do this either. I looked online for solutions and there seems to be an abundance of utility tools to do this, even Windows has some built in commands.

However, I download things on multiple computers that run multiple OSes and none of these utilities seem to be able to run on all of my devices - and I like programs which run the same on everything. So, this is why I've decided to start my crypto-tool project - a cross-platform crypto tool. It is built in Java (which runs on most all devices) and will allow me to have the same process of checking checksums on every device I use.

The program currently comes with a command line interface which allows the user to generate checksums for input strings and files. It currently supports the following hash algorithms:
  • MD2
  • MD5
  • SHA-1
  • SHA-256
  • SHA-384
  • SHA-512
And to run the program, the user just needs to specify the hash algorithm to use and the file(s) and/or string(s) to generate the checksum for:

 S:\Workspaces\Github - Java\crypto-tool\latest-build>java -jar crypto-tool-cli-0.0.4-jar-with-dependencies.jar hash -ha MD5 -f input.txt -s "Command line string to hash." -s "And another string."  
 MD5 hash of [Command line string to hash.] is: 4354cb305345dc2582f1aefef124df47  
 MD5 hash of [And another string.] is: a3482fe6387ebb8cc20ea5aa713c3b8a  
 MD5 hash of file [input.txt] is: 632e60b155c9a24d3cf47f072532b440  

I feel like this is a good start to the project, however I have some plans to enhance this utility:

  • Add checksum verification
  • Add encryption/decryption of files/strings
  • Add a graphical user interface in addition to the command line interface


Friday, July 17, 2015

Spring Boot

I recently did a presentation on Spring Boot - what it is and how to use it. And for my presentation, I made a simple REST server sample project[1]. The project consists of a few REST endpoints, a couple of data entity classes, and an in-memory H2 database.

Feel free to check out the documentation[2] if you're interested in setting up a very simple REST server with Spring Boot.


  • [1] - https://github.com/DWiechert/spring-boot
  • [2] - https://github.com/DWiechert/spring-boot/blob/master/README.md

Friday, February 6, 2015

Pi-Temperature

Raspberry Pi's are a great little tool for learning. Software people can learn a little hardware and hardware people can learn a little software. I recently got a Raspberry Pi B+ kit and have been messing around with it lately to learn a little hardware.

My goal was to attach temperature sensors and have the Pi report back the temperature to me.

So, I went out and bought the Vktech DS18b20 sensors and attached them to a GPIO port. Once, the sensors have been connected, you need to login and run the following 2 commands to have Linux setup and probe them:

 sudo modprobe w1-gpio  
 sudo modprobe w1-therm  

Now, once those commands are ran, the temperatures will show up in following files:

 /sys/bus/w1/devices/w1_bus_master1/<serial id>/w1_slave  

where <serial id> is the serial id of the sensor itself. An example of one of these files is:

 4d 01 4b 46 7f ff 03 10 d8 : crc=d8 YES  
 4d 01 4b 46 7f ff 03 10 d8 t=20812  

Now, in that file, the Celsius temperature is actually the last little bit, 20812 - it just needs to be divided by 1000 and you have your Celsius temperature of 20.8.

Great, it's now working. Linux is probing the sensor and reporting it to a file which I can read and see. It works, but not that practical. At this point I wanted to see if I could automate this process so I didn't have to manually read the file each time I want to know the temperature.

Meet pi-temperature, a Java library I wrote to solve this exact problem. It probes all attached sensors for me at a given interval (defaults to 1 min) and can report the temperatures of each sensor back to the user. It utilizes spring boot to startup a local Tomcat instance for a web server and has several REST urls attached:

 /sensors/list  
 /alerts/list  
 /alerts/setOn/<name>  
 /alerts/setOff/<name>  
 /alerts/update/<name>  

The /sensors/list is the primary endpoint which reads all of the sensors and reports back the temperatures in both Celsius and Fahrenheit. The /alerts endpoints are currently a work in progress and another post will be coming soon with their features.

Specific instructions on how to build, run, and more thorough instructions can be found on the pi-temperature project's README.