Monday, September 7, 2015

How to Make a Useful Toggl Time Tracker with Particle and Node

I have recently been tracking my time on projects more closely throughout the day. It is useful to see which projects take up more time than others and helps me measure which days I'm most productive (and what is distracting me!). My service of choice for this is Toggl. It is simple, clean and syncs across devices. Best of all - it has an API which you can hook up your own applications and devices to. I decided to set up a button connected to my Particle Photon that would start and stop my Toggl timer for me. I used a simple Node server to manage the communication between my Particle device and Toggl.

Clicking a physical button feels just that little bit more empowering than tapping a software button and prevents me needing to get out my smartphone or click around on my Mac to find the timer!

What You'll Need

  • A Particle Core or Photon - I'll be using a Particle Photon but both should be compatible with the demo
  • A physical button of some kind
  • A breadboard, resistors and jumper wires - If you are new to tinkering with microcontrollers, SparkFun has a great new Inventors Kit for the Photon
  • A Toggl account - If you don't have one, head to the Toggl website to sign up!
  • Knowledge of how to get code onto your Particle device - if you're new to this, I published a SitePoint article a few weeks back on connecting to the Photon. The Particle Core is similar.
  • A basic understanding of running a Node server and using npm - Peter Dierx at SitePoint has written a pretty comphrensive guide on starting with npm.

Note: Particle also sell a big physical button. You could quite likely adapt this concept to the big button for a lot of fun, I just don't own one of those... yet.

Finding Your API Keys

To get your Toggl API key, visit the Toggl "My Profile" Page. If you scroll down to the bottom of this page, you'll find a unique API token you can use like so:

Finding your Toggl API key

Copy that token to a safe place. You'll need it!

You can also reset it using the tiny "Reset" link on the right hand side (useful in moments like just then when I revealed my API key to you all).

If it has been a while since your last Particle build session and you need a refresher on finding your Particle API key, go to the Particle Build online editor and click the gear icon at the very bottom to get to the settings page. From there, you'll see a screen which shows you your access token.

Finding your Particle API key

Copy that one too.

Our Particle Sketch

Our sketch with the layout of the breadboard, Particle device (shown as a Core in this pic but both this and a Photon will work), LED and button looks like so:

Sketch of our Particle Toggl button

Download The Code

All of the code for this example can be found on GitHub.

Our Particle Code

Our Particle code will keep track of whether or not the button is pressed and whether or not we want to have our LED lit up or not. All the rest of the functionality will be taken care of by our Node server.

The Particle code looks like so:

[code language="c"]
int ledPin = D0;
int buttonPin = D5;
bool ready = true;
int last;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
last = millis();
digitalWrite(ledPin, LOW);

Spark.function("ledTrigger", ledTrigger);
}

void loop() {
if (millis() - last > 200) {
if (digitalRead(buttonPin)) {
if (ready) {
ready = false;
Spark.publish("buttonPressed");
last = millis();
}
} else {
ready = true; // button ready to be pressed again
}
}
}

int ledTrigger(String value) {
if (value == "ON") {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}

return 0;
}
[/code]

I'll explain what each bit of that code means. To start with, we define our two components and the pins they are attached to. Our button is attached to D5 and our LED is attached to pin D0.

[code language="c"]
int ledPin = D0;
int buttonPin = D5;
[/code]

The next two variables are there to keep track of timing within our loop. ready tracks whether our button is ready to be pressed again. We want to ensure there is a period between when we first click it and when it can be clicked again. last is the variable which helps track this period of time, it keeps track of the last time the loop has been run. That might make more sense when you see it in action soon.

[code language="c"]
bool ready = true;
int last;
[/code]

In our setup() function, we start by setting the pin mode for our LED to output and set it to input for our button.

[code language="c"]
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);

// more code explained next!
}
[/code]

Continue reading %How to Make a Useful Toggl Time Tracker with Particle and Node%


by Patrick Catanzariti via SitePoint

Object Orientated Development with WordPress

Object Orientated code is everywhere and WordPress is no exception.

The Core of WordPress is built on series of objects/classes used to control everything from manipulation of the database to the look and feel of your site.

Throughout this tutorial, we will look into Object Orientated design and how you can use these in practical applications when developing for WordPress including:

  • Understanding exactly what object orientated design is.
  • Discussing why we should use object orientated design.
  • Examining a real world example to showcase how it can work.

Note 1: Also note that this tutorial outlines primarily WordPress centric concepts, so if you are entirely new to object orientated design you should probably get a quick overview of OO via the PHP reference guide.

Note 2: If you're keen on downloading everything right away feel free to download the source from my GitHub repository and follow along with the tutorial.

Let's jump right into it!

What Is Object Orientated Design Anyway?

Object Orientation Design (OO Design) is a different methodology for solving issues, separate from the traditional procedural approach.

With Object Orientated Design you create a structure (class) that will group together all of your related functions (methods) and information (properties) to solve an issue.

This is different from procedural development in which you create functions and variables to solve issues, however, these elements can be separated across multiple files, re-declared and often loosely related.

Continue reading %Object Orientated Development with WordPress%


by Simon Codrington via SitePoint

An Introduction to GameplayKit: Part 3

Heliom

opl-small

Gorgeously minimal and spacious One Pager for Canadian digital agency 'Heliom'. Great reference to a quality team photo followed by their roles neatly presented below. Big fan of their less is more approach.

by Rob Hope via One Page Love

HoldOn.js – jQuery Plugin to Create CSS UI Blocker

HoldOn.js is a jQuery plugin to create CSS UI blocker. It's useful to prevent that your user do something wrong while something in the background is executed.


by via jQuery-Plugins.net RSS Feed

How to Hire Your First Employees While Running Your Startup

  Hiring your first employees is an exciting milestone for any startup founder. It’s a sign your startup is (literally) growing and getting traction. However, it’s also notoriously stressful, time-consuming and difficult. After all, if it’s just you and your co-founders, the first couple people you bring on board will contribute to a significant portion […]

Continue reading %How to Hire Your First Employees While Running Your Startup%


by Aja Frost via SitePoint

Fast Multi-language Docs with SitePoint’s RTDSphinx-PHP

This post will guide you through getting up and running with RTDSphinx-PHP, a ReadTheDocs-friendly Sphinx based PHP documentation skeleton with sane defaults, pre-installed directives, and modified styles for optimal API and prose documentation rendering in multiple languages. For an unfinished example of the documentation, see here and switch the language in the bottom left flyout panel.

If this sounds familiar, it’s because we already went through a manual setup of a similar skeleton in a previous post, but that one had no localization support, too many steps, and wasn’t as reusable as this newly developed one. This guide will not be a “let’s build it from scratch” project, but rather an overview of the features this skeleton project offers out of the box, and an introduction into its usage.

This post will be the first in a long line of many SitePoint branded projects meant for wide-spread public consumption, fully open source and highly welcoming of other people’s contributions.

Sphinx at night vector illustration

Quickstart

For prerequisites, make sure you have Python and pip, the Python package manager, installed.

First, clone the skeleton into a folder - either a subfolder of your project, like projectRoot/docs or into its own folder - anything goes.

git clone https://github.com/sitepoint/rtdsphinx-php docs

Optionally, create a Python virtual environment.

Then, while inside the cloned folder, install prerequisites from the requirements.txt file by running:

pip install -r requirements.txt

This will install all necessary packages.

That’s it. To generate files for a new language, run:

bin/update.sh xx

… where xx is the language code (e.g. “jp” for Japanese).
Then, edit files in locale/xx/LC_MESSAGES that end in .po.

To compile the HTML from these translations, run:

bin/build.sh xx yy zz

… where xx, yy and zz are language codes for all the languages you want to build. Inspect your generated HTML by opening _build/html/xx/index.html in a browser.

For deploying to ReadTheDocs, see below.

Continue reading %Fast Multi-language Docs with SitePoint’s RTDSphinx-PHP%


by Bruno Skvorc via SitePoint