Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am hsubra89 on github.
  • I am hsubra89 (https://keybase.io/hsubra89) on keybase.
  • I have a public key ASAiMU3u6GAuRHRSby5JkE5zjLipWEwUmSDIEDujZKAXago

To claim this, I am signing this object:

@hsubra89
hsubra89 / index.html
Last active October 26, 2015 00:19
Gist to demonstrate the back navigation bug in @cycle/history
<html>
<body>
<script src="./test-app.js"></script>
</body>
</html>
@hsubra89
hsubra89 / cb -> promise
Created August 18, 2014 05:01
Converting Callback style code to promises
var q = require('q');
// Sample Async Function
function asyncFunction(data, cb) {
setTimeout(function() {
// call cb with error
cb(new Error('Error'));
// Or call with success
cb(null, {status: 'true'});
}, 100);
@hsubra89
hsubra89 / promises
Created August 13, 2014 05:00
Promises Example 2
var allTheXmlsYay = [];
function getXML(url) {
var d = $q.defer();
d3.xml(url, 'image/svg+xml' function(xml) {
// If error variable is present
// if(err) d.reject(err);
d.resolve(xml);
@hsubra89
hsubra89 / javascript async
Created August 11, 2014 04:10
async adding javascript
var addScript = function(url,success){
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0], done=false;
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done=true;
success();
@hsubra89
hsubra89 / index.js
Created August 4, 2014 22:02
Sharing instance of event emitter
var emitter = require("events").EventEmitter;
var eInstance = new emitter();
function Component() {
// Component's Constructor Section (can do custom stuff)
}
// Component prototype inhertits emitter prototype instance.
Component.prototype = Object.create(eInstance);
@hsubra89
hsubra89 / gist:9aaa5af19ef2e245c4d7
Last active August 29, 2015 14:04
callback vs promise basic example
function a(text) {
console.log(text);
}
/********************************* Callback style ****************************/
setTimeout(function() {
var text = "Hello World";
// Calling the next function using its reference // cb style
a(text);
// call next function in the chain
app.controller('someController', ['$scope', '$q', 'd3Service', function($scope, $q, d3Service) {
var promises = [d3Service.d3(),
Restangular.one('images/Example PDF.svg').get(),
Restangular.one("Job", $scope.jobID).one("Costing")];
$q.all(promises)
.then(function(data) {