Wednesday, January 10, 2018

Import Data into Redshift Using the COPY Command

This article was originally published by TeamSQL. Thank you for supporting the partners who make SitePoint possible.

Importing a large amount of data into Redshift is easy using the COPY command. To demonstrate this, we’ll import the publicly available dataset “Twitter Data for Sentiment Analysis” (see Sentiment140 for additional information).

Note: You can connect to AWS Redshift with TeamSQL, a multi-platform DB client that works with Redshift, PostgreSQL, MySQL & Microsoft SQL Server and runs on Mac, Linux and Windows. You can download TeamSQL for free.

Download the ZIP file containing the training data here.

The Redshift Cluster

For the purposes of this example, the Redshift Cluster’s configuration specifications are as follows:

  • Cluster Type: Single Node
  • Node Type: dc1.large
  • Zone: us-east-1a

Create a Database in Redshift

Run the following command to create a new database in your cluster:

CREATE DATABASE sentiment;

Create a Schema in the Sentiment Database

Run the following command to create a scheme within your newly-created database:

CREATE SCHEMA tweets;

The Schema (Structure) of the Training Data

The CSV file contains the Twitter data with all emoticons removed. There are six columns:

  • The polarity of the tweet (key: 0 = negative, 2 = neutral, 4 = positive)
  • The id of the tweet (ex. 2087)
  • The date of the tweet (ex. Sat May 16 23:58:44 UTC 2009)
  • The query (ex. lyx). If there is no query, then this value is NO_QUERY.
  • The user that tweeted (ex. robotickilldozr)
  • The text of the tweet (ex. Lyx is cool)

Create a Table for Training Data

Begin by creating a table in your database to hold the training data. You can use the following command:

CREATE TABLE tweets.training (
    polarity int,
    id BIGINT,
    date_of_tweet varchar,
    query varchar,
    user_id varchar,
    tweet varchar(max)
)

Uploading CSV File to S3

To use Redshift’s COPY command, you must upload your data source (if it’s a file) to S3.

To upload the CSV file to S3:

  1. Unzip the file you downloaded. You’ll see 2 CSV files: one is test data (used to show structure of original dataset), and the other (file name: training.1600000.processed.noemoticon) contains the original data. We will upload and use the latter file.
  2. Compress the file. If you’re using macOS or Linux, you can compress the file using GZIP by running the following command in Terminal: gzip training.1600000.processed.noemoticon.csv
  3. Upload your file using the AWS S3 Dashboard.

Alternatively, you can use Terminal/Command Line to upload your file. To do this, you must install AWS CLI and, after installation, configure it (run aws configure in your terminal to start the configuration wizard) with your access and secret key.

Connect TeamSQL to the Redshift Cluster and Create the Schema

Open TeamSQL (if you don’t have the TeamSQL Client, download it from teamsql.io) and add a new connection.

  • Click Create a Connection to launch the Add Connection window.

Create a Connection

  • Select Redshift and provide the requested details to set up your new connection.
  • Do not forget to enter the Default Database Name!
  • Test the connection, and save if the test is successful.
  • By default, TeamSQL displays the connections you’ve added in the left-hand navigation panel. To enable the connection, click on the socket icon.
  • Right click on default database to open a new tab.

New tab

  • Run this command to create a new schema in your database.
CREATE SCHEMA tweets;

  • Refresh the database list in the left-hand navigation panel with right clicking on connection item.
  • Create a new table for training data.
CREATE TABLE tweets.training (
    polarity int,
    id int,
    date_of_tweet varchar,
    query varchar,
    user_id varchar,
    tweet varchar
)

Create new table query

  • Refresh the connection and your table should appear in the left-hand list.

Table created

Using the COPY Command to Import Data

To copy your data from your source file to your data table, run the following command:

Continue reading %Import Data into Redshift Using the COPY Command%


by Can Abacıgil via SitePoint

Yay Brigade’s Favorite Albums

Really impressive One Pager by Yay Brigade curating their top albums of 2017. On first load the site stacks 10 tracks in vinyl shapes, each interactive and autoplays the songs. Lovely touch with the progress bar on the left side and also the list or stacked view switcher 💃 Cheers for the build notes!

Full Review | Direct Link


by Rob Hope @robhope via One Page Love

Run Automated Website Tests on Thousands of Devices Using CrossBrowserTesting

10 Best WordPress Star Rating Plugins

#322: What's New in HTML 5.2, A Performance Checklist for 2018 and CSS Grid Explained

Frontend Focus
Issue 322 — January 10, 2018
HTML 5.2 became an official W3C Recommendation (REC) a month ago, but what did it introduce and change?
Ire Aderinokun

A quick and easy high level introduction to the main concepts of CSS Grid given by Morten Rand-Hendriksen at Wordcamp Europe 2017.
Statuscode

A front-end performance checklist with everything you need to know to create fast Web experiences this year.
Vitaly Friedman

Get up and running in a hurry with the Vue.js JavaScript framework. Learn how to build and maintain complex applications quickly and efficiently in this practical guide to Vue.js by Sarah Drasner.
Frontend Masters   Sponsor

Eight new guides covering the real use cases of Flexbox, looking at where Grid should be used instead, and clarification on how the spec works with Writing Modes, Box Alignment and ordering of items.
Mozilla Hacks

Rather than replace your HTML or rendering mechanisms, Stimulus augments your existing HTML with functionality. From the creators of Ruby on Rails.
Basecamp

You’ve probably heard of Meltdown and Spectre, two timing attacks that can affect modern CPUs which can also be taken advantage of from browsers..
Mozilla Security Blog

If you’ve not played with CSS Grid yet this is an accessible example-led study of what it makes easy.
Per Harald Borgen

Dig into the CSS Grid Layout specification to uncover some features you might have missed – and some coming soon.
Rachel Andrew

Jobs

In Brief

What Spectre and Meltdown Mean For WebKit news
An explainer on how Spectre and Meltdown affect existing WebKit security mechanisms and what short-term and long-term fixes WebKit is deploying to provide protection against this new class of attack.
Filip Pizlo

Improving URLs for AMP Pages news
AMP pages will now show a page’s original URL, instead of using the google.com/amp URL scheme.
Accelerated Mobile Pages Project

Making CSS Animations Feel More Natural tutorial
Brandon Gregory

Better Web Typography with Font Variants tutorial
Learn about a wide variety of font-variant- CSS properties.
Jonathan Harrell

Robust Client-Side JavaScript: A Developer’s Guide tutorial
Mat​hia⁠s S​chäf⁠er

Animating With Minimal CSS and SVGs tutorial
David Brennan

Be A Full Stack Expert. Learn MongoDB Free in M001, MongoDB Basics 
MongoDB University courses are free and give you everything you need to know about MongoDB.
mongodb  Sponsor

Permissions On The Web Suck opinion
“there are uses for push notifications, what we really need to fix are the permissions”
Phil Nash

Web Design Trends 2018: What Could Make an Impact This Year? opinion
Oliver Lindberg

11 Things I Learned Reading the CSS Grid Specification opinion
Ohans Emmanuel

Chrome Only? Careful Now opinion
Chris Coyier warns developers not to build web experiences that only work in Chrome.
CSS Tricks

Introducing Heroicons: A Set of 104 SVG UI Icons tools
Steve Schoger

Real-Time Error Monitoring, Alerting, and Analytics for JavaScript 🚀 
ROLLBAR  Sponsor

Uppy: A Powerful, Modular JavaScript File Uploader code
Transloadit

headless-devtools: Perform Chrome DevTools Actions From Code code
Johnny Cowchimp

element-ready: Detect When an Element is Ready in the DOM code
Sindre Sorhus

Popmotion: A Functional JavaScript Motion Library code
Mix tweens, physics, and user input actions to create elegant Web-based interactions - all in 11KB.
Popmotion

Save Time with the Best, Fastest Angular Spreadsheets & UI Components 
GrapeCity JavaScript Solutions  Sponsor


by via Frontend Focus

#189: Community Concerns Regarding Google's AMP Project

Mobile Dev Weekly January 10, 2018   #189
Peter Cooper recommends
Improving URLs for AMP Pages — AMP pages will now show a page’s original URL, instead of using the google.com/amp URL scheme.
Accelerated Mobile Pages Project
Brian Rinaldi recommends
A Letter About Google AMP — A letter signed by prominent members of the web development community regarding their concerns about Google’s AMP (Accelerated Mobile Pages) project.
Holly Schinsky recommends
CSS Grid Layout Secrets Revealed — Dig into the CSS Grid Layout specification to uncover some features you might have missed – and some coming soon.
Rachel Andrew
Sponsored
Linux Cloud Hosting Starting at 1GB of RAM for $5/mo — Get a Linode server up and running in seconds. Simply choose your plan, distro and location and you’re ready to deploy your server. Get $20 credit on a new account.
Linode Cloud Hosting

Mobile Web
Holly Schinsky recommends
How Modern Web Browsers Accelerate Performance: The Networking Layer — Techniques modern browsers use to automatically boost performance and specific tips to help boost the performance of your apps even more.
Lachezar Nickolov
Holly Schinsky recommends
Which JavaScript Frameworks Are the Fastest?
John Hannah
Holly Schinsky recommends
12 Mobile UX Design Trends For 2018 — A list of mobile UX design trends to expect this year.
Nick Babich
Brian Rinaldi recommends
Safari Preview 46 Adds Service Workers — Some progress towards supporting PWAs in Safari.
Jon Davis
Brian Rinaldi recommends
11 Things Learned Reading the CSS Grid Specification
Ohans Emmanuel
Holly Schinsky recommends
10 Ways to Avoid Cross-Browser Compatibility Issues — How to make sure all your users see your site the way you intended it to be seen.
Simon Jones
Chris Brandrick recommends
A Vue.js Inspector Specifically for Mobile Devices
Cali Rojas
Za'e Johnson recommends
The Future of jQuery UI and jQuery Mobile
jQuery UI Blog
Hybrid Apps
Holly Schinsky recommends
Build A Ripple XRP Wallet For Android And iOS With Ionic Framework — Learn how to create a cross-platform mobile Ripple XRP wallet for Android and iOS using Ionic Framework and Angular.
Nic Raboy
Native Development
Holly Schinsky recommends
How We Architected the New Relic Mobile Web UI in React — How New Relic updated their mobile web UI architecture to be built from reusable pieces in React to allow for easier contribution from team members.
Frank Linehan
Brian Rinaldi recommends
Embedding NativeScript in an Existing iOS App — Learn about an experimental new way to embed NativeScript in an existing iOS app.
Rob Lauer
Chris Brandrick recommends
Creating an 'Offline' Notice in React Native — Have you ever seen the red “No Internet Connection” sign in mobile apps like Facebook Messenger. Here’s how to recreate it.
Chiamaka Nwolisa


by via Mobile Dev Weekly

An Introduction to Functional JavaScript

You’ve heard that JavaScript is a functional language, or at least that it’s capable of supporting functional programming. But what is functional programming? And for that matter, if you’re going to start comparing programming paradigms in general, how is a functional approach different from the JavaScript that you’ve always written?

Well, the good news is that JavaScript isn’t picky when it comes to paradigms. You can mix your imperative, object-oriented, prototypal, and functional code as you see fit, and still get the job done. But the bad news is what that means for your code. JavaScript can support a wide range of programming styles simultaneously within the same codebase, so it’s up to you to make the right choices for maintainability, readability, and performance.

Functional JavaScript doesn’t have to take over an entire project in order to add value. Learning a little about the functional approach can help guide some of the decisions you make as you build your projects, regardless of the way you prefer to structure your code. Learning some functional patterns and techniques can put you well on your way to writing cleaner and more elegant JavaScript regardless of your preferred approach.

Imperative JavaScript

JavaScript first gained popularity as an in-browser language, used primarily for adding simple hover and click effects to elements on a web page. For years, that’s most of what people knew about it, and that contributed to the bad reputation JavaScript earned early on.

As developers struggled to match the flexibility of JavaScript against the intricacy of the browser document object model (DOM), actual JavaScript code often looked something like this in the real world:

[code language="js"]
var result;
function getText() {
var someText = prompt("Give me something to capitalize");
capWords(someText);
alert(result.join(" "));
};
function capWords(input) {
var counter;
var inputArray = input.split(" ");
var transformed = "";
result = [];
for (counter = 0; counter < inputArray.length; counter++) { transformed = [ inputArray[counter].charAt(0).toUpperCase(), inputArray[counter].substring(1) ].join(""); result.push(transformed); } }; document.getElementById("main_button").onclick = getText; [/code]

So many things are going on in this little snippet of code. Variables are being defined on the global scope. Values are being passed around and modified by functions. DOM methods are being mixed with native JavaScript. The function names are not very descriptive, and that’s due in part to the fact that the whole thing relies on a context that may or may not exist. But if you happened to run this in a browser inside an HTML document that defined a <button id="main_button">, you might get prompted for some text to work with, and then see the an alert with first letter of each of the words in that text capitalized.

Imperative code like this is written to be read and executed from top to bottom (give or take a little variable hoisting). But there are some improvements we could make to clean it up and make it more readable by taking advantage of JavaScript’s object-oriented nature.

Continue reading %An Introduction to Functional JavaScript%


by M. David Green via SitePoint