Skip to content

Instantly share code, notes, and snippets.

componentDidMount() {
axios.get('https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty')
.then(response => {
let posts = [];
const lastPostIndex = response.data.length - 1;
for (var i = 0; i < response.data.length; i++) {
axios.get('https://hacker-news.firebaseio.com/v0/item/' + response.data[i] + '.json?print=pretty')
.then(post => {
posts.push(post.data);
if (i === lastPostIndex) {
@chrislaughlin
chrislaughlin / index.js
Created October 10, 2016 22:34
Print the name and description of 50 transactions from the npm repo stream
const ChangesStream = require('changes-stream');
const db = 'https://replicate.npmjs.com';
var changes = new ChangesStream({
db: db,
include_docs: true
});
let count = 0;
import sinon from 'sinon';
import _ from 'lodash';
import expect from 'expect';
let eachStub = sinon.stub(_, 'each').returns(null);
expect(eachStub).calledOnce();
@chrislaughlin
chrislaughlin / Array to Tally
Created September 8, 2015 10:01
Turn an array into a tally
var array = [
{
name: 'red',
vlaue: 7
},
{
name: 'red',
vlaue: 7
},
{
@chrislaughlin
chrislaughlin / gym
Created February 17, 2015 20:49
How many people are in the gym
$.get( "http://www.puregym.com/gyms/belfast-adalaide-street/whats-happening", function( data ) {
var inTheGym = $("<div></div>" ).html(data).find('.people-number').html();
alert(inTheGym);
});
(function(root, module) {
if (typeof exports == 'object') {
module.exports = module();
} else if (typeof define == 'function' && define.amd) {
define(module);
} else {
root.Fizzbuzz = module();
}
}(this, function () {
var FIZZ_NUMBER = 3;
onChange: function(){},
onFoo: function(){},
onBar: function(){}
// changed to
onChange: $.noop,
onFoo: $.noop,
onBar: $.noop
promiseFunction(inputData).then(function() {
});
//Can be changed to
promiseFunction(inputData).then($.noop());
@chrislaughlin
chrislaughlin / gist:e04c2a34ee2a263745d5
Last active August 29, 2015 14:05
call back with noop
jQuery.fn.someAjaxStyleFunc = function(url, complete) {
return jQuery.ajax(url || this.url)
.complete(complete || jQuery.noop);
};
@chrislaughlin
chrislaughlin / gist:a96b139c77119d256d6b
Last active August 29, 2015 14:05
function with callback
special: {
ready: {
// Make sure the ready event is setup
setup: jQuery.bindReady,
teardown: jQuery.noop
}