Skip to content

Instantly share code, notes, and snippets.

View rkaw92's full-sized avatar

Robert Kawecki rkaw92

  • rkaw software
  • Warsaw
View GitHub Profile
@rkaw92
rkaw92 / when-failure.js
Created June 3, 2014 14:50
How to break when.js rejection handler detection
var when1 = require('when1');
var when2 = require('when2');
var rejectedPromise = when1.reject(new Error('Intentional failure'));
when2(rejectedPromise).done(undefined, function(error){
console.log('Rejection properly handled:', error);
});
@rkaw92
rkaw92 / san.py
Created August 12, 2014 15:16
OpenStack Cinder driver for Solaris
# Copyright 2011 Justin Santa Barbara
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@rkaw92
rkaw92 / client.js
Last active February 13, 2016 10:01
var WebSocket = require('ws');
var ws = new WebSocket('ws://localhost:7717');
var fs = require('fs');
var loremIpsum = fs.readFileSync(__dirname + '/lipsum.txt', 'utf-8');
ws.on('open', function open() {
function spam() {
try {
console.log('-> send');
@rkaw92
rkaw92 / symbols.js
Created June 23, 2016 07:27
A gist that shows that no method of object type detection is infallible in ECMAScript...
Object.prototype.toString.call(new Date()); // '[object Date]'
// Now to have some fun:
const suspiciousDate = new Date();
suspiciousDate[Symbol.toStringTag] = 'window';
Object.prototype.toString.call(suspiciousDate); // wut!
const immutable = require('immutable');
const lodash = require('lodash');
const a = new immutable.List([ 1, 2, 3 ]);
const b = new immutable.List([ 1, 2, 3 ])
console.log('a.equals(b) => %s', a.equals(b));
console.log('a === b => %s', a === b);
console.log('_.isEqual(a, b) => %s', lodash.isEqual(a, b));
const z = new immutable.List([ 1, 2, 3, 4 ]);
console.log('_.isEqual(a, z) => %s', lodash.isEqual(a, z));
@rkaw92
rkaw92 / buckets.js
Created May 11, 2017 22:21
Prototypal inheritance
function BucketCollector() {
}
BucketCollector.prototype.addToBucket = function addToBucket(item) {
this.items.push(item);
};
BucketCollector.prototype.items = [];
@rkaw92
rkaw92 / strict.js
Created May 12, 2017 09:04
strict mode demo in Node.js - it still isn't the default
(function nonStrict() {
console.log('nonStrict: %s', typeof this);
})();
(function strict() {
'use strict';
console.log('strict: %s', typeof this);
})();
@rkaw92
rkaw92 / annotated-output.txt
Created November 14, 2017 20:48
Stuck Promises from node-postgres/Client#query
* firing query
* query result: 1
* firing query
* query result: 1
* firing query
* query result: 1
* firing query
* query result: 1
* firing query
* query result: 1
'use strict';
const Big = require('big.js');
const EventEmitter = require('events');
/**
* An EventEmitter that emits subsequent approximations of number Pi.
* @extends external:EventEmitter
*/
class PiEmitter extends EventEmitter {
@rkaw92
rkaw92 / index.html
Created March 28, 2018 10:01
Cross-window data passing in JS
<!DOCTYPE html PUBLIC>
<html>
<head>
<title>Root window</title>
</head>
<body>
<p id="greeter">Nothing here yet...</p>
<button id="opener">Open a new window</button>
<script>
window.greet = function greet() {