Skip to content

Instantly share code, notes, and snippets.

View chrisbuttery's full-sized avatar
🏠
Working from home

Chris Buttery chrisbuttery

🏠
Working from home
View GitHub Profile
function hostReachable() {
// Handle IE and more capable browsers
var xhr = new ( window.ActiveXObject || XMLHttpRequest )( "Microsoft.XMLHTTP" );
var status;
// Open new request as a HEAD to the root hostname with a random param to bust the cache
xhr.open( "HEAD", "//" + window.location.hostname + "/?rand=" + Math.floor((1 + Math.random()) * 0x10000), false );
// Issue request and handle response
@chrisbuttery
chrisbuttery / index.js
Created January 11, 2015 11:08
generatorz
function *write(){
console.log('writing');
var num = yield 1;
console.log('num x num =', num * num);
}
function *blah () {
console.log('starting blah');
yield* write();
console.log('ending blah');
// Thunk
let get = function (url) {
// return a function, passing in our callback
return function (callback) {
let xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onreadystatechange = function() {
let response = xhr.responseText;
if(xhr.readyState != 4) return;
@chrisbuttery
chrisbuttery / app.js
Created February 3, 2015 09:43
So what does koa give you?
"use strict";
const port = process.env.PORT || 1337;
const koa = require('koa');
const app = koa();
app.use(function* (){
/* this */
// ES6 for loops
// =============
// Things in ES6 can be "iterable". Arrays are iterable by default.
var fruits = ['Apple', 'Banana', 'Grape'];
for (var fruit of fruits)
console.log('Fruit: ' + fruit);
import {component,dom} from 'deku'
// Define a component with a name for debugging
const Button = component('My Button')
// Define properties
Button
.prop('foo', { type: 'string', optional: true, expects: ['hello', 'goodbye'] })
.prop('bar', { type: 'boolean', default: false })
function render(context){
let {el,children,events} = context
let {foo,bar} = context.props
let {open,enabled} = context.state
return (
<button disabled={enabled} onClick={click} class={foo} isSomething={bar}>Submit</button>
)
}
@chrisbuttery
chrisbuttery / resources.md
Last active August 29, 2015 14:17
JavaScript Resources
@chrisbuttery
chrisbuttery / test.js
Last active August 29, 2015 14:17 — forked from miguelmota/test.js
var test = require('tape');
var request = require('supertest');
var server = require('../../server');
test('barcode route', function(t) {
request(server)
.get('/api/1/code')
.expect(200)
.expect('Content-Type', /json/)
.expect({"code":{"code":"1M4A67AE3H94RS6GG74M"}})
@mixin ie6 { * html & { @content } }
#logo {
background-image: url("/images/logo.png");
@include ie6 { background-image: url("/images/logo.gif"); }
}