Skip to content

Instantly share code, notes, and snippets.

View icodejs's full-sized avatar

Tahir Joseph icodejs

View GitHub Profile
@icodejs
icodejs / writeOutNumbers.js
Created April 7, 2016 21:59
Write out numbers
/*
Create a function that transforms any positive number to a string representing the number in words. The function should work for all numbers between 0 and 999999.
For example,
number2words(0) should return "zero"
number2words(1) should return "one"
number2words(9) should return "nine"
@icodejs
icodejs / json-view-style.css
Last active February 2, 2016 11:03
JSONView Stylesheet
/* Solarized colours http://www.zovirl.com/2011/07/22/solarized_cheat_sheet */
body {
white-space: pre;
font-family: monospace;
background-color: #002b36;
color: #839496;
}
a {

React Bit-by-Bit: An Introduction for Beginners

This will provide a gradual implementation of the 'todo' application on React's website (or a close approximation).

Boilerplate

If you are just starting, I'd suggest using JSBin to play around; you can learn React without having to install anything locally.

If you want to develop locally, this assumes you have an index.html that includes both React and index.js (which we'll mention in a moment) and a index.jsx or similar that is getting compiled to the index.js file previously mentioned. We'll technically be using browserify, but webpack or similar should work fine.

/**
* Create batches of values and apply a function asynchronously over each batch.
* Start new batch when the previous batch's promise has completed.
* @param {array} arr - List of values to be batched.
* @param {int} batchSize - Batch size.
* @param {Function} fn - Function to be applied on each array value.
* @return {Promise} - An array of arrays containing promises.
*/
var mapLimit = function(arr, batchSize, fn) {
var batches = arr.reduce(function (accumulator, currVal, index) {
/*
* Takes provided URL passed as argument and make screenshots of this page with several viewport sizes.
* These viewport sizes are arbitrary, taken from iPhone & iPad specs, modify the array as needed
*
* Usage:
* $ casperjs screenshots.js http://example.com
*/
var casper = require("casper").create();
@icodejs
icodejs / tableToJson.js
Last active December 18, 2015 21:59
Convert table of timezone data into JSON object
$(function () {
var html = '<table class="border1" border="0" cellpadding="4" cellspacing="0" align="center"><tbody><tr><th class="head">Abbreviation</th><th class="head">Full name</th><th class="head">Location</th><th class="head">Time zone</th></tr><tr class="c1"><td><a href="military/a.html">A</a></td><td>Alpha Time Zone</td><td>Military</td><td>UTC + 1 hour</td></tr><tr class="c0"><td><a href="au/cdt.html">ACDT</a></td><td>Australian Central Daylight Time</td><td>Australia</td><td>UTC + 10:30 hours</td></tr><tr class="c1"><td><a href="au/cst.html">ACST</a></td><td>Australian Central Standard Time</td><td>Australia</td><td>UTC + 9:30 hours</td></tr><tr class="c0"><td><a href="atlantic/adt.html">ADT</a></td><td>Atlantic Daylight Time</td><td>Atlantic</td><td>UTC - 3 hours</td></tr><tr class="c1"><td><a href="na/adt.html">ADT</a></td><td>Atlantic Daylight Time</td><td>North America</td><td>UTC - 3 hours</td></tr><tr class="c0"><td><a href="au/edt.html">AEDT</a></td><td>Australian Eastern
@icodejs
icodejs / getUtcTime.js
Created January 18, 2013 16:52
Get UTC time
function _getUtcTime () {
var
d = date,
i = 0,
arr,
t;
d = d || new Date(); // default to now
arr = [
ReportGrid.sankey("#chart", {
axes: ["viewers"],
datapoints: data2()
});
function data2() {
return [{
"head": "show1",
"tail": "show2",
@icodejs
icodejs / requireJqueryPluginTemplate.js
Created November 24, 2012 21:41
JS: Template uses AMD or browser globals to create a jQuery plugin.
// Uses AMD or browser globals to create a jQuery plugin.
// It does not try to register in a CommonJS environment since
// jQuery is not likely to run in those environments.
// See jqueryPluginCommonJs.js for that version.
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);