DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.

Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.

Threat Detection: Learn core practices for managing security risks and vulnerabilities in your organization — don't regret those threats!

Managing API integrations: Assess your use case and needs — plus learn patterns for the design, build, and maintenance of your integrations.

Avatar

Nic Raboy

Founder at The Polyglot Developer

Tracy, US

Joined Apr 2015

https://www.thepolyglotdeveloper.com

About

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand. @nraboy

Stats

Reputation: 1631
Pageviews: 956.8K
Articles: 16
Comments: 1
  • Articles
  • Comments

Articles

article thumbnail
Real-Time Maps With a Raspberry Pi, Golang, and HERE XYZ
Check out this post to learn more about real-time maps.
June 21, 2019
· 13,925 Views · 1 Like
article thumbnail
How to Work With GeoJSON Data in Golang for HERE XYZ
Learn how to work with GeoJSON Data in Golang.
Updated June 12, 2019
· 11,778 Views · 2 Likes
article thumbnail
Read GPS Data With a Raspberry Pi Zero W and Node.js
Learn more about reading GPS Data with a Raspberry Pi and Node.js.
June 6, 2019
· 16,117 Views · 2 Likes
article thumbnail
Interacting With a NEO 6M GPS Module Using Golang and a Raspberry Pi Zero W
Learn more about interacting with NEO 6M GPS Module using Golang and a Raspberry Pi Zero W.
May 29, 2019
· 8,660 Views · 1 Like
article thumbnail
Data Management With SQLite and Vuex in a NativeScript-Vue App
In this tutorial, we saw some examples that made use of a key-value storage that used the Application Settings module for NativeScript.
July 2, 2018
· 12,604 Views · 1 Like
article thumbnail
Use AWS Lambda and API Gateway With Node.js and Couchbase NoSQL
This article will be useful if you want to create applications that are billed for the time that they are used rather than the time that they are active.
January 17, 2018
· 5,997 Views · 3 Likes
article thumbnail
Creating a Front-End for Your User Profile Store With Angular and TypeScript
We’re going to see how to create a client front-end written in Angular with TypeScript, that communicates with each of the API endpoints.
August 31, 2017
· 51,242 Views · 12 Likes
article thumbnail
Deploy a PHP With Couchbase Application as Docker Containers
See how to create an automatically provisioned Couchbase node and simplistic PHP application that writes and reads data from the Couchbase NoSQL node.
June 23, 2017
· 5,178 Views · 2 Likes
article thumbnail
Deploy a Golang Web Application and Couchbase as Docker Containers
Learn how to deploy a Golang web application as a Docker container alongside Couchbase using microservices and Docker images.
May 17, 2017
· 4,652 Views · 1 Like
article thumbnail
Perform Various N1QL Queries Without Indexes in Couchbase Server
You may be surprised to learn that not every N1QL query requires an index to exist. Learn how to run a few N1QL queries on a Couchbase Bucket that has no indexes.
May 3, 2017
· 5,824 Views
article thumbnail
Creating a CD Pipeline With Jenkins and Java
Reap all the benefits that continuous deployments has to offer! Let's quickly set up a pipeline for your projects using Jenkins and Couchbase Server.
April 26, 2017
· 17,973 Views
article thumbnail
Flattening and Querying NoSQL Array Data With N1QL
Need to query within embedded documents? This example takes us through using Couchbase's N1QL query for objects in a nested array in a single document.
March 2, 2017
· 12,267 Views · 2 Likes
article thumbnail
Use RegEx to Test Password Strength in JavaScript
In this post, we learn how to combine JavaScript and RegEx to create scripts that can help us test our password strength.
May 16, 2015
· 93,051 Views · 1 Like
article thumbnail
All About Java Modifier Keywords
I’ve been a Java programmer for a while now, however, recently someone asked me a question regarding one of Java modifier keywords and I had no clue what it was. This made it obvious to me that I needed to brush up on some Java that goes beyond actual coding and algorithms. After a few Google searches, I got bits and pieces on the topic, but never really the full story, so I’m using this post as a way to document the subject. This is a great interview question to test your computer science book-smarts. Modifiers in Java are keywords that you add to variables, classes, and methods in order to change their meaning. They can be broken into two groups: Access control modifiers Non-access modifiers Let’s first take a look at the access control modifiers and see some code examples on how to use them. Modifier Description public Visible to the world private Visible to the class protected Visible to the package and all subclasses So how do you use these three access control modifiers? Let’s take the following two classes. Please ignore how inefficient they may or may not be as that is besides the point for this tutorial. Create a file called project/mypackage/Person.java and add the following code: package mypackage; class Person { private String firstname; private String lastname; protected void setFirstname(String firstname) { this.firstname = firstname; } protected void setLastname(String lastname) { this.lastname = lastname; } protected String getFirstname() { return this.firstname; } protected String getLastname() { return this.lastname; } } The above Person class is going to have private variables and protected methods. This means that the variables will only be accessible from the class and the methods will only be accessible from the mypackage package. Next create a file called project/mypackage/Company.java and add the following code: package mypackage; import java.util.*; public class Company { private ArrayList people; public Company() { this.people = new ArrayList(); } public void addPerson(String firstname, String lastname) { Person p = new Person(); p.setFirstname(firstname); p.setLastname(lastname); this.people.add(p); } public void printPeople() { for(int i = 0; i < this.people.size(); i++) { System.out.println(this.people.get(i).getFirstname() + " " + this.people.get(i).getLastname()); } } } The above class is public, so it can be accessed from any future classes inside and outside of the package. It has a private variable that is only accessible from within the class, and it has a bunch of public methods. Because the Person class and Company class both share the same package, the Company class can access the Person class as well as all its methods. To complete the demonstration of the access control modifiers, let’s create a driver class in a new project/MainDriver.java file: import mypackage.*; public class MainDriver { public static void main(String[] args) { Company c = new Company(); c.addPerson("Nic", "Raboy"); c.printPeople(); Person p = new Person(); p.setFirstname("Maria"); p.setLastname("Campos"); } } Remember, because the Company class is public, we won’t have issues adding and printing people. However, because the Person class is protected, we’re going to get a compile time error since the MainDriver is not part of the mypackage package. Now let’s take a look at the available non-access modifiers and some example code on how to use them. Modifier Description static Used for creating class methods and variables final Used for finalizing implementations of classes, variables, and methods abstract Used for creating abstract methods and classes synchronized Used in threads and locks the method or variable so it can only be used by one thread at a time volatile Used in threads and keeps the variable in main memory rather than caching it locally in each thread So how do you use these five non-access modifiers? A good example of the static modifier is the following in Java: int max = Integer.MAX_VALUE int numeric = Integer.parseInt("1234"); Notice in the above example we make use of variables and methods in the Integer class without first instantiating it. This is because those particular methods and variables are static. The abstract modifier is a little different. You can create a class with methods, but they are essentially nothing more than definitions. You cannot add logic to them. For example: abstract class Shape { abstract int getArea(int width, int height); } Then inside a child class you would add code similar to this: class Rectangle extends Shape { int getArea(int width, int height) { return width * height; } } This brings us to the synchronized and volatile modifiers. Let’s take a look at a threading example where we try to access the same method from two different threads: import java.lang.*; public class ThreadExample { public static void main(String[] args) { Thread thread1 = new Thread(new Runnable() { public void run() { print("THREAD 1"); } }); Thread thread2 = new Thread(new Runnable() { public void run() { print("THREAD 2"); } }); thread1.start(); thread2.start(); } public static void print(String s) { for(int i = 0; i < 5; i++) { System.out.println(s + ": " + i); } } } Running the above code will result in output that is printed in a random order. It could be sequential, or not, it depends on the CPU. However, if we make use of the synchronized modifier, the first thread must complete before the second one can start printing. The print(String s) method will now look like this: public static synchronized void print(String s) { for(int i = 0; i < 5; i++) { System.out.println(s + ": " + i); } } Next let’s take a look at an example using the volatile modifier: import java.lang.*; public class ThreadExample { public static volatile boolean isActive; public static void main(String[] args) { isActive = true; Thread thread1 = new Thread(new Runnable() { public void run() { while(true) { if(isActive) { System.out.println("THREAD 1"); isActive = false; } } } }); Thread thread2 = new Thread(new Runnable() { public void run() { while(true) { if(!isActive) { System.out.println("THREAD 2"); try { Thread.sleep(100); } catch (Exception e) { } isActive = true; } } } }); thread1.start(); thread2.start(); } } Running the above code will print the thread number and alternate between them because our volatile variable is a status flag. This is because the flag is stored in main memory. If we remove the volatile keyword, the thread will only alternate one time because only a local reference is used and the two threads are essentially hidden from each other. Conclusion Java modifiers can be a bit tricky to understand and it is actually common for programmers to be unfamiliar with a lot of them. This is a great interview question to test your book knowledge too. If I’ve missed any or you think my explanations could be better, definitely share in the comments section.
May 15, 2015
· 12,522 Views
article thumbnail
Using Oauth 2.0 in your Web Browser with AngularJS
I have a few popular Oauth related posts on my blog. I have one pertaining to Oauth 1.0a, and I have one on the topic of Oauth 2.0 for use in mobile application development. However, I get a lot of requests to show how to accomplish an Oauth 2.0 connection in a web browser using only JavaScript and AngularJS. We’re going to better explore the process flow behind Oauth 2.0 to establish a secure connection with a provider of our choice. In this particular example we’ll be using Imgur because I personally think it is a great service. Before we begin, it is important to note that this tutorial will only work with providers that offer the implicit grant type. Oauth Implicit Grant Type via OauthLib: The implicit grant type is used to obtain access tokens (it does not support the issuance of refresh tokens) and is optimized for public clients known to operate a particular redirection URI. These clients are typically implemented in a browser using a scripting language such as JavaScript. Unlike the authorization code grant type, in which the client makes separate requests for authorization and for an access token, the client receives the access token as the result of the authorization request. You’ll know the provider supports the implicit grant type when they make use of response_type=token rather than response_type=code. So there are going to be a few requirements to accomplish this in AngularJS: We are going to be using the AngularJS UI-Router library We are going to have a stand-alone index.html page with multiple templates We are going to have a stand-alone oauth_callback.html page with no AngularJS involvement With that said, let’s go ahead and create our project to look like the following: project root templates login.html secure.html js app.js index.html oauth_callback.html The templates/login.html page is where we will initialize the Oauth flow. After reaching the oauth_callback.html page we will redirect to the templates/secure.html page which requires a successful sign in. Crack open your index.html file and add the following code: Now it is time to add some very basic HTML to our templates/login.html and templates/secure.html pages: Login Login with Imgur Secure Web Page Access Token: {{accessToken} Not much left to do now. Open your js/app.js file and add the following AngularJS code: var example = angular.module("example", ['ui.router']); example.config(function($stateProvider, $urlRouterProvider) { $stateProvider .state('login', { url: '/login', templateUrl: 'templates/login.html', controller: 'LoginController' }) .state('secure', { url: '/secure', templateUrl: 'templates/secure.html', controller: 'SecureController' }); $urlRouterProvider.otherwise('/login'); }); example.controller("LoginController", function($scope) { $scope.login = function() { window.location.href = "https://api.imgur.com/oauth2/authorize?client_id=" + "CLIENT_ID_HERE" + "&response_type=token" } }); example.controller("SecureController", function($scope) { $scope.accessToken = JSON.parse(window.localStorage.getItem("imgur")).oauth.access_token; }); We are first going to focus on the login method of the LoginController. Go ahead and add the following, pretty much taken exactly from the Imgur documentation: $scope.login = function() { window.location.href = "https://api.imgur.com/oauth2/authorize?client_id=" + "CLIENT_ID_HERE" + "&response_type=token" } This long URL has the following components: Parameter Description client_id The application id found in your Imgur developer dashboard response_type Authorization grant or implicit grant type. In our case token for implicit grant The values will typically change per provider, but the parameters will usually remain the same. Now let’s dive into the callback portion. After the Imgur login flow, it is going to send you to http://localhost/oauth_callback.html because that is what we’ve decided to enter into the Imgur dashboard. Crack open your oauth_callback.html file and add the following source code: Redirecting... If you’re familiar with the ng-cordova-oauth library that I made, you’ll know much of this code was copied from it. Basically what we’re doing is grabbing the current URL and parsing out all the token parameters that Imgur has provided us. We are then going to construct an object with these parameters and serialize them into local storage. Finally we are going to redirect into the secure area of our application. In order to test this we need to be running our site from a domain or localhost. We cannot test this via a file:// URL. If you’re on a Mac or Linux machine, the simplest thing to do is run sudo python -m SimpleHTTPServer 80 since both these platforms ship with Python. This will run your web application as localhost on port 80. A video version of this article can be seen below.
April 7, 2015
· 26,809 Views · 1 Like
article thumbnail
Parse an XML Response with Java and Dom4J
Previously we’ve explored how to parse XML data using NodeJS as well as PHP. Continuing on the trend of parsing data using various programming languages, this time we’re going to take a look at parsing XML data using the dom4j library with Java. Now dom4j, is not the only way to parse XML data in Java. There are many other ways including using the SAX parser. Everyone will have their own opinions on which of the many to use. To keep up with my previous two XML tutorials, we’re going to use the following XML data saved in a file called data.xml at the root of the project: Code Blog Nic Raboy Nic Raboy Maria Campos With our XML content figured out, let’s make sure we structure our project like the following: project root src xmlparser MainDriver.java libs dom4j-1.6.1.jar build.xml data.xml Based on our project structure, you can probably tell that we’re going to be using Apache Ant for building. Say what you want about using Ant, but I’m still one of many who still uses it. Feel free to make changes to Apache Maven or other to better meet your needs. We’re now ready to crack open our src/xmlparser/MainDriver.java to start adding our parse logic. package xmlparser; import java.io.*; import java.util.*; import org.dom4j.*; import org.dom4j.io.*; public class MainDriver { public static void main(String[] args) { } public static void printRecursive(Element element) { } public static Document readFile(String filename) throws Exception { } } To further explain our intentions, the readFile(String filename) function will load the data.xmlfile and return it as a Document object for further parsing. The printRecursive(Element element)function will iterate through each node of the XML and print it out if it contains text. All levels of the XML will be iterated through. So let’s start with readFile(String filename): public static Document readFile(String filename) throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(new File(filename)); return document; } Nothing really to the above code. In fact, I pulled most of it from the dom4j quick-start code. The printRecursive(Element element) function is where things get more complex: public static void printRecursive(Element element) { for(int i = 0, size = element.nodeCount(); i < size; i++) { Node node = element.node(i); if(node instanceof Element) { Element currentNode = (Element) node; if(currentNode.isTextOnly()) { System.out.println(currentNode.getText()); } printRecursive(currentNode); } } } Some of the above code was taken from the dom4j quick-start, but the rest is some custom work. We are basically looking at each node and trying to visit any available children. If none exist, bail out. We also only want to print if there is text. Finally, we’re looking at the main(String[] args) function to bring it all together: public static void main(String[] args) { try { Element root = readFile("data.xml").getRootElement(); printRecursive(root); } catch (Exception e) { e.printStackTrace(); } } Just like that we’ve printed our each node of our XML document. In case you’re interested in the build.xml code, it can be seen below: To test the project you’d just run ant buildandrun from your command prompt or Terminal. Assuming of course you have Apache Ant configured correctly. The dom4j library is very thorough so I recommend have a look at the Javadocs that go with it.
April 7, 2015
· 13,865 Views

Comments

Creating a Front-End for Your User Profile Store With Angular and TypeScript

Sep 05, 2017 · Thomas Martin

Thanks!

User has been successfully modified

Failed to modify user

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: