Skip to content

Instantly share code, notes, and snippets.

onChange: function(){},
onFoo: function(){},
onBar: function(){}
// changed to
onChange: $.noop,
onFoo: $.noop,
onBar: $.noop
(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;
@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);
});
@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
},
{
import sinon from 'sinon';
import _ from 'lodash';
import expect from 'expect';
let eachStub = sinon.stub(_, 'each').returns(null);
expect(eachStub).calledOnce();
@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;
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 / this.js
Last active January 2, 2017 21:45
"this" mistakes
this.foo = 'foo';
document.querySelector('.my-div').onclick = function() {
console.log(this.foo)
}
//Logs undefined
document.querySelector('.my-div').onclick = function() {
console.log(this.foo)
}.bind(thid);
@chrislaughlin
chrislaughlin / thises6.js
Created January 2, 2017 21:45
ES6 This context
this.foo = 'foo';
document.querySelector('.my-div').onclick = () => {
console.log(this.foo)
}
@chrislaughlin
chrislaughlin / window.event.js
Created January 2, 2017 21:56
Window.event
onClick: () => {
console.log(Window.event);
}
//Bad
onClick: (event) => {
console.log(event);
}
//Good