Thursday, October 6, 2016

Quick Tip: How to Style Google Custom Search Manually

Website owners very often decide on using Google's Custom Search Engine (GCSE) for searching through their content instead of using built-in and/or custom search functionality. The reason is simple - it's much less work, and most often it does the trick. If you don't need advanced filters or custom search parameters then GSCE is for you.

In this quick tip, I will show you how to manually render the search form (without using a special GCSE tag) and a results box which allows for more control and a cleaner way to style the search input field.

The Problem

Usually adding GCSE to your site is as simple as copy pasting a script and a custom HTML tag into your site. In the place where you put the special GCSE tag, an input search field will render. Typing and starting a search from this field will do a Google search based on previously configured parameters (e.g. search sitepoint.com only).

One question that often comes up is "How do I change the placeholder of the GCSE input field?". Unfortunately very often the suggested answer is wrong as it uses an unreliable setTimeout method in order to wait for the Ajax call from the GCSE to complete (making sure the input is already attached to the DOM) and then changes attributes via JavaScript.

We are also going to query the element and change the attributes with JS, but instead of doing a blind setTimeout() we will use the callback provided by the GCSE which will guarantee that the input has already loaded.

Creating a GCSE Account

The search engine is configured completely online. The first step is to go to the GCSE site and click add. Follow the wizard by filling in the domain on which you want to search (usually your site URL). You can ignore any advanced settings for now.

When you click done, you are presented with three options:

  1. Get Code, which will guide you through what and where you have to copy in order for the search to show on your site
  2. Public URL will show you a working preview of the search that you set up
  3. Control Panel for customising the search

Go to Control Panel, click Search Engine ID and make a note of this value for later.

HTML Setup

In order to try this out, we will create a basic index.html containing the HTML needed and an app.js file containing the functions needed to render and customise the search.

Go ahead and create a basic HTML file with this inside:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>GCSE test</h1>
    <div class="gcse-search-wrapper"></div>
    <div class="gcse-results-wrapper"></div>
    <script src="app.js"></script>
</body>
</html>

We added two <div>'s with special classes in order to be recognized as the elements where the search form and results should be rendered.

Continue reading %Quick Tip: How to Style Google Custom Search Manually%


by Almir Bijedic via SitePoint

State of JavaScript 2016 results, Vue 2.0 released, Angular 2 vs React comparison

This week's JavaScript newsRead this e-mail on the Web
JavaScript Weekly
Issue 304 — October 6, 2016
The (very thorough) results from Sacha Greif’s (creator of Telescope) ‘State of JavaScript’ survey. Over 9,000 of you took part and there’s lots to learn here.
Sacha Greif

After 8 alphas, 8 betas and 8 RCs, Vue 2.0 is ready for production. It’s a lot faster than before, and includes a great introductory guide.
Evan You

The complexity of the JS ecosystem can sometimes prove overwhelming — here, Jose takes a satirical look at how varied the JS landscape is in 2016. This provoked much discussion and many responses.
Jose Aguinaga

Frontend Masters
Most people are aware that Dev Tools exist.. to tweaking CSS or the interactive console. But there is so much more! Let’s look at every dev tools and learn to edit, debug and profile web applications!
Frontend Masters   Sponsor

Dr. Axel looks at ‘global’, a proposal for a standard way to access the global object in JavaScript across all types of runtime.
Dr. Axel Rauschmayer

An in-depth comparison between Angular 2 and React.
Eric Elliott

A write-up of what’s going on with TC39 (the group working on specifying the latest versions of JavaScript) around ECMAScript Module support in Node. A great look at the issues involved.
James M Snell

The tale of how a developer with an idea for a JavaScript data grid control turned it into an entire company. I hope this inspires some of you.
Niall Crosby

Jobs Supported by Hired.com

  • Frontend specialist in AmsterdamAlways wanted to work in a multicultural organisation with clients from all over the world? We travel, present and breathe JavaScript daily. Join us and help create the world's leading lean customer experience platform. Backbase
  • Senior Front End EngineerEveryone should have the power to create professional-quality videos. As a member of the Animoto team, you'll be developing a responsive, elegant web experience and pioneering the next generation of video creation software. Animoto
  • One Application, 4,000+ Opportunities - Try HiredOn Hired companies apply to interview you. Get 1:1 support for your job search plus upfront compensation details. Hired

In brief

A Book Apart Releases 'JavaScript for Web Designers' Book news
Mat Marquis

Latest WebKit Build Supports JavaScript Internationalization API news
WebKit

A Look At The 'Rest/Spread Properties' ES Proposal news
Dr. Axel Rauschmayer

Join Google for Polymer Summit 2016 via Livestream on 17-18 October event
Featuring 2 days of talks on Polymer, Web Components, Progressive Web Apps, & the future of the mobile web
Google Inc.  Sponsor

Chrome Dev Summit 2016 event
Registration for the Chrome Dev Summit is now open (San Francisco, Nov 10-11). Join Chrome VP Darin Fisher for two days of announcements and talks from the Chrome team.
Google

Lazy-Loading ES2015 Modules in the Browser tutorial
How to load ES2015 modules synchronously (during the page load) and asynchronously (performing lazy-loading) using System.js.
Tiago Garcia

A Quick, Practical Guide to JavaScript Promises tutorial
Dominik Kundel

Create a Trello Clone using Angular, Node.js, Mongo, and Express tutorial
This in-depth tutorial details how to write a Trello-like ticketing system from scratch.
Codementor

Embedding ChakraCore into CLR / C# Apps on Windows tutorial
Eric Rozell

Elegant Form Validation Using React tutorial
Jordan Schaenzle

Loading Polyfills Only When Needed tutorial
How to conditionally load polyfills while considering the balance of simplicity and performance.
Philip Walton

Saved from Callback Hell tutorial
Camilo Reyes believes that by applying some SOLID principles, callbacks can still be a useful technique.
SitePoint

Using the Fetch API for Modern Async Server Calls tutorial
How the new fetch API is a better replacement for XHR when fetching resources.
Jared Faris

Variable and Function Hoisting in ES2015 tutorial
Ire Aderinokun

The Guide to Promises in Computed Properties in Ember tutorial
Frank Treacy

Write Better Apps in Angular 2: Rangle’s Online Training Program course
Rangle offers this free Angular 2 online training program for JavaScript developers. Register now to join the session on October 18-19.
RANGLE.IO  Sponsor

Why I Believe GraphQL Will Come to Replace REST opinion
Martijn Walraven

Canary in the Gold Mine: Test npm Modules on a Specific Node Version tools
Node.js Foundation

Lasso: Advanced JS Module Bundler, Asset Pipeline and Optimizer tools
eBay

iView: UI Component Library with Vue.js code

mFancyTitle: jQuery Plugin That Animates Your Page's Title code
Federica Sibella

Curated by Peter Cooper and published by Cooper Press.

Stop getting JavaScript Weekly : Change email address : Read this issue on the Web

© Cooper Press Ltd. Office 30, Lincoln Way, Louth, LN11 0LS, UK


by via JavaScript Weekly

How You Can Maximize Your Productivity by Eating Like Your Ancestors

A bowl of grapes

[author_more]

It should come as no surprise that a vast amount of time and money is spent gathering endless scientific evidence to tell us how to eat and live, but what is surprising is that the findings are often very contradictory, and as a result, we're left confused and ill-informed about how we should stay healthy.

As some experts suggest, living healthily and functioning optimally (in both body and mind) is as easy as eating and living like our ancestors did, before the Neolithic Revolution 10,000 years ago, before we started to farm grains and leave our hunter-gatherer lifestyles behind.

Eating like our ancestors means to eat what nature gave us. Essentially this is animals, insects and vegetation, and when you think about it, this should be rather easy for us since we no longer have to hunt food ourselves!

Mounting research, clinical evidence and revelations as to why official advice has worked so poorly over the past few decades seem to make it clear that emulating the way we ate for the vast majority of our evolution is a good idea. But there’s still some condescension from part of the media, which is quick to point out that the old way isn’t always the best way. That’s technically true, but it ignores that these approaches work not because they’re old, but because they reverse some of the recent, disastrous innovations in human food consumption.

It seems as if we'd mostly rejected this way of living because we're so enticed by modern-day fad diets that would rather take our money than help us live longer, healthier lives. However, we're now starting to see diets like paleo, keto and primal gaining in popularity, and these diets outline the ways that we can eat and live like our ancestors for optimum health and productivity.

What do these diets consist of? Let’s take a look.

Sisson’s Primal Blueprint

Former runner and triathlete Mark Sisson discovered (from his own first-hand experiences) that following the same lifestyle "blueprint" our ancestors followed ⏤ thousands of years ago ⏤ still greatly benefits us today. His modern-day Primal Blueprint is almost identical to the lifestyle lived by our ancestors and you can read about this in further detail in his book, The Primal Blueprint or on his site.

It's made up of the following rules:

  • Eat lots of animals, insects and plants
  • Move around a lot, but at a slow pace
  • Run really fast once in a while
  • Lift heavy things
  • Get lots of sleep
  • Play (i.e. enjoy yourself)
  • Get some sunlight every day
  • Make use of your mind
  • Avoid trauma and poisonous things

I won't go into too much detail, but you may have noticed that some of these rules sound a little primitive or even downright obvious, but 10,000 years ago was a different time. While coming into contact with poisonous things was certainly something to avoid doing back then (and it still is, don't worry!), nowadays that might apply to alcohol and substance abuse. Playtime would have meant practicing spear-throwing, but today that could be a soccer game.

In short, Sisson advocates a balanced diet and lifestyle similar to our predecessors. Eat plenty of protein (fish and eggs are great substitutes for vegetarians), eat plenty of vegetables, make sure you’re not sedentary (sitting down for too long), include rigorous exercise now and again, have fun (don't stress yourself too much), avoid placing yourself in unnecessary danger (such as failing to wear a seatbelt), have lots of sleep to rest your body and mind, and avoid fast food, refined carbs and sugars and other harmful substances.

Why Refined Carbohydrates Are the Enemy

Have you ever noticed how tired and foggy your brain becomes once you've eaten a carb-y meal such as pizza? That happens because our ancestors never ate bread and other grains, and so our bodies never evolved to "understand" those types of refined carbohydrates. Simply put, your body has to work overtime to digest these unnatural foods. In terms of evolutionary biology, we haven't caught up to that yet!

As you may have guessed, your body becomes exhausted and highly unproductive when it has to work overtime to digest the foods or handle the blood glucose levels that we've not yet evolved to handle ⏤ this can even lead to food intolerance and have adverse effects on both your physical and mental health, including frequent headaches and other uncomfortable symptoms that can seriously hinder an entrepreneur's peak performance.

Let’s discuss the other two diets, paleo and keto.

Continue reading %How You Can Maximize Your Productivity by Eating Like Your Ancestors%


by Rebeka Bergin via SitePoint

Pie Timer with CSS asnd jQuery

A tutorial about creating Pie Timer with CSS, jQuery using linear-gradient.


by via jQuery-Plugins.net RSS Feed

Hire the Donald

opl-small

'Hire the Donald' is a hilarious One Pager acting as Donald Trump's job application for commander in chief. Real laughs at that loading icon in the qualifications section. Lovely touch with the angled CV intro (with links in the copy). Other features include references, interactive endorsement section, skills, accomplishments and ends with a big wall covering the Single Page site (promoting Hillar's campaign). Excellent work by Hum Creative.

by Rob Hope via One Page Love

Alcohol

opl-small

Text-only launching soon page with some intriguing copy for 'Alcohol'. I'm a fan of these arty One Pagers but I think it's a fail when there is no mailing list sign up or way to follow on social networks for announcements.

by Rob Hope via One Page Love

Quick Tip: Use Enums in Rails for Mapped Values

When I worked in a call center, we used to mark cases with different statuses. This allowed upper management to get a handle on where cases stood, what the bottlenecks were and flow of calls. Thankfully it has been a long time since I worked in a call center, but I have pondered how I would accomplish this task with Rails. Thankfully, Rails has a solution known as Enums.

When you are adding statuses to a model, you might be tempted to use strings to set the status. This makes perfect sense because different statuses tend to be named things like 'pending', 'under review', and 'completed'.

However, Rails encourages you to take advantage of Enums to replace these strings with integers. It seems counter-intuitive at first, but it is actually a perfect fit for the problem.

Continue reading %Quick Tip: Use Enums in Rails for Mapped Values%


by William Kennedy via SitePoint