Monday, September 5, 2016

Silvana

Silvana - Creative Agency WordPress Theme

'Silvana' is a One Page WordPress theme crafted for a professional online portfolio. There are 3 header layouts including big image, slideshow or video background. Features include skills graph, allocation for big team member images, Lightbox portfolio with category filter, pricing table, testimonial slider and a nice big footer with Google Maps integration. Really like the slick contact form when you click the 'Send Request' buttons. Also good to know the purchase includes Visual Composer Page Builder (valued at $34) and Slider Revolution (valued at $19). Don't need content management with WordPress? Check out the $15 HTML template of Silvana.

by Rob Hope via One Page Love

Pry: A Simple Start

pry_logo (1)

A REPL - Read, Eval, Print, Loop, is an interactive shell for a programming language to evaluate expressions in the language. REPLs are a great way to learn a language, it's syntax, and APIs.

Most programming languages have a REPL of its own or a community-built tool written for the same purpose. For Ruby, it's IRB - Interactive Ruby Shell, that lets you play with Ruby in seconds and start experimenting with its features.

IRB comes bundled with Ruby and can be launched from the command line using the command irb. It provides command history, line editing, and executing Ruby programs from inside it. However, we aren't going to talk about IRB today. Instead, I want to focus on an alternative, called pry, and what it brings to the table. We'll see some nifty features that Pry is packed with today.

Continue reading %Pry: A Simple Start%


by Vinoth via SitePoint

How Do You Start a New Web Design Project?

I come bearing good news! For those of you who didn't hear yet (where've you been?) SitePoint recently launched a new podcast: The Versioning Show. It's headed by regular SitePoint contributors M. David Green and Tim Evko, who every week sit down to discuss the industry of the web, from development to design, with some of the people making it happen today.

Personally, I'm loving the show. I was an avid listener of the previous SitePoint podcast (anyone remember that?) and I think that podcasts in general are an excellent way of keeping up with an increasingly fast-paced and ever-changing industry. Tim and David have already spoken to a number of distinguished guests, one of whom was Chris Coyier. They asked Chris (who has also written for the JavaScript channel) what types of technologies he would use if he had to build a new website tomorrow. I found his answer interesting (in so far as it gave me food for thought) and that's what I'd like to look at today.

Continue reading %How Do You Start a New Web Design Project?%


by James Hibbard via SitePoint

Lynn Schmidt

opl-small

Minimal Single Page website with a scattered image layout for Munich-based stylist, Lynn Schmidt. Absolutely do not load this (super) long scrolling One Pager on mobile as total image size is 39mb. A controversial approach to a portfolio but still beats a PDF in an email:) Tweet us your thoughts...

by Rob Hope via One Page Love

Decade in Design

Decade in Design

Special One Pager by Elegant Seagulls celebrating ten successful years in business. The long scrolling Single Page website has good focus on the team behind all their great work including bios and thank you notes from each. Features include big typography, company timeline (with lovely responsive adaption), client milestones and a nice little Dribbble infographic section. Awesome to see it's built on WordPress too!

by Rob Hope via One Page Love

Android From Scratch: Using REST APIs

Most of us have developed voracious appetites for new information, what with the Internet being such an important part of our lives. Our attention spans too are shorter than ever, so building Android applications whose content is static can be a bad idea. Instead, you should consider building applications that can display fresh content every time the user opens them. 

That might sound hard, but with more and more websites exposing their resources through REST APIs, it's actually quite easy. (See our Beginner’s Guide to HTTP and REST for a primer.)

In this tutorial, I'm going to show you how to use the classes and methods available in the Android SDK to connect to remote web servers and interact with them using their REST APIs.

1. Enabling Internet Access

Making use of a REST API obviously involves using the Internet. However, Android applications can access the Internet only if they have the android.permission.INTERNET permission. Therefore, before you start writing any networking code, you must make sure that the following uses-permission tag is present in your project's manifest file:

Because android.permission.INTERNET is not considered a dangerous permission, you don't have to request for it during runtime on devices running API Level 23 or higher.

2. Creating Background Threads

The Android platform does not allow you to run network operations on the main thread of the application. Therefore, all your networking code must belong to a background thread. The easiest way to create such a thread is to use the execute() method of the AsyncTask class. As its only argument, execute() expects a Runnable object.

If you want to learn more about running operations in background threads, I suggest you read this tutorial about background operations from the Android From Scratch series.

3. Creating an HTTP Connection

By using the openConnection() method of the URL class, you can quickly set up a connection to any REST endpoint. The return value of openConnection() must be cast to an instance of either HttpURLConnection or HttpsURLConnection, depending on whether the endpoint is accessed over HTTP or HTTPS. Both HttpURLConnection and HttpsURLConnection allow you to perform operations such as adding request headers and reading responses.

The following code snippet shows you how to set up a connection with the GitHub API's root endpoint:

Note that HttpsURLConnection is a subclass of the HttpURLConnection class.

4. Adding Request Headers

Most websites that offer REST APIs want to be able to identify your app uniquely. The easiest way to help them do so is to include a unique User-Agent header in all your requests.

To add a User-Agent header to your request, you must use the setRequestProperty() method of the HttpURLConnection object. For example, here's how you set the User-Agent header to my-rest-app-v0.1:

You can add multiple headers to your request by calling the setRequestProperty() method multiple times. For example, the following code snippet adds an Accept header and a custom Contact-Me header:

5. Reading Responses

Once you have passed all the request headers, you can check if you have a valid response using the getResponseCode() method of the HttpURLConnection object.

If the HttpURLConnection class gets a redirect response code, such as 301, it handles it automatically and follows the redirect. Therefore, usually, you will not have to write any extra code to check for redirects.

In case of no errors, you can now call the getInputStream() method to get a reference to the input stream of the connection.

Most REST APIs these days return data formatted as valid JSON documents. Therefore, instead of reading from the InputStream object directly, I suggest you create an InputStreamReader for it.

6. Parsing JSON Responses

The Android SDK has a class called JsonReader, which makes it very easy for you to parse JSON documents. You can create a new instance of the JsonReader class by passing the InputStreamReader object to its constructor.

How you extract a specific piece of information from the JSON document depends on its structure. For example, the JSON document returned by the root endpoint of GitHub's REST API looks like this:

As you can see, the response is just one large JSON object that contains several keys. To extract the value of the key called organization_url from it, you will have to write the following code:

The above code processes the JSON response as a stream of tokens. Therefore, it consumes very little memory. However, because it has to process every single token one after another, it can be slow while handling large responses.

After you've extracted all the required information, you must always call the close() method the JsonReader object so that it releases all the resources it holds.

You must also close the connection by calling the disconnect() method of the HttpURLConnection object.

7. Using Different HTTP Methods

HTTP-based REST interfaces use HTTP methods to determine the type of operation that has to be performed on a resource. In the previous steps, we made use of the HTTP GET method to perform a read operation. Because the HttpURLConnection class uses the GET method by default, we didn't have to specify it explicitly.

To change the HTTP method of your HttpURLConnection object, you must use its setRequestMethod() method. For example, the following code snippet opens a connection to an endpoint that belongs to httpbin.org and sets its HTTP method to POST:

As you might already know, POST requests are used to send data to the server. By writing to the output stream of the connection, you can easily add any data to the body of the POST request. However, before you do so, you must make sure that you call the setDoOutput() method of the HttpURLConnection object and pass true to it.

The following code snippet shows you how to send a simple key-value pair to the server:

8. Caching Responses

It is always a good idea to cache HTTP responses. By doing so, you can not only reduce your app's bandwidth consumption, but also make it more responsive. From API level 13 onwards, the Android SDK offers a class called HttpResponseCache, which allows you to easily implement caching without making any changes to your networking logic.

To install a cache for your application, you must call the install() method of the HttpResponseCache class. The method expects an absolute path specifying where the cache must be installed, and a number specifying the size of the cache. You can use the getCacheDir() method if you don't want to specify the absolute path manually.

The following code snippet installs a cache whose size is 100,000 bytes:

Once the cache is installed, the HttpURLConnection class starts using it automatically. To check if your cache is working, you can use its getHitCount() method, which returns the number of HTTP responses that were served from the cache.

Conclusion

There are thousands of REST APIs available for you to freely use in your Android apps. By using them, you can make your app more informative, interesting, and feature-rich. In this tutorial, you learned how to use the HttpURLConnection class to consume such REST APIs. You also learned how to create an HTTP response cache that keeps your app's bandwidth usage low.

If you think using HttpURLConnection is hard, you should give third-party libraries such as Volley a try. Libraries like this use the HttpURLConnection class internally, but provide lots of convenient methods that allow you to make your code more concise and readable.

To learn more about networking on the Android platform, you can refer to Android's Network Operations guide.


by Ashraff Hathibelagal via Envato Tuts+ Code

AtoZ CSS Screencast: Box-Model

This screencast is a part of our AtoZ CSS Series. You can find other entries to the series here.

Transcript

Every element on a web page is a box.

We can describe the characteristics of these boxes using the CSS Box Model.

Understanding this model and how different types of boxes lay out, is key when converting designs into a working website.

Continue reading %AtoZ CSS Screencast: Box-Model%


by Guy Routledge via SitePoint