Skip to content

Instantly share code, notes, and snippets.

View Aaronius's full-sized avatar

Aaron Hardy Aaronius

View GitHub Profile
// From http://stackoverflow.com/questions/13320015/how-to-write-a-debounce-service-in-angularjs
.factory('debounce', function($timeout, $q) {
return function(func, wait, immediate) {
var timeout;
var deferred = $q.defer();
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if(!immediate) {
@Aaronius
Aaronius / sequence.js
Last active September 15, 2017 11:54
Promise-based Sequential Queue
// Queues multiple asynchronous processes to run sequentially via promises
// Process can be added to the queue while other processes are running
var Sequence = function() {};
Sequence.prototype.enqueue = function(fn) {
this.tail = this.tail ? this.tail.finally(fn) : fn();
};
// Usage
angular.module('qAllSettled', []).config(function($provide) {
$provide.decorator('$q', function($delegate) {
var $q = $delegate;
$q.allSettled = function(promises) {
return $q.all(promises.map(function(promise) {
return promise.then(function(value) {
return { state: 'fulfilled', value: value };
}, function(reason) {
return { state: 'rejected', reason: reason };
});
@Aaronius
Aaronius / introrx.md
Last active August 29, 2015 14:12 — forked from staltz/introrx.md

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and netver tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@Aaronius
Aaronius / stopport.sh
Created March 17, 2017 15:37
Kills a port. Put it in /usr/local/bin. Run it like so: `stopport 3000`
#!/bin/bash
lsof -i tcp:$1 | awk 'NR!=1 {print $2}' | xargs kill
@Aaronius
Aaronius / hyper.js
Last active April 26, 2018 04:06
hyper.js
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',
@Aaronius
Aaronius / gist:09f1b3168a99357ebda2c7fee6447bde
Created January 23, 2019 02:57
Example upload npm script
{
"name": "reactor-helloworld-extension",
"version": "1.0.0",
"scripts": {
"upload": "npx @adobe/reactor-uploader --environment=production --org-id=04B20B885A7B43080A494209@AdobeOrg --tech-account-id=94A538A75B180FC90A49410B@techacct.adobe.com --api-key=395fe521b0044160935a90db77e0e18b"
}
}
@Aaronius
Aaronius / memoize1.js
Last active September 13, 2019 21:15
Memoize
const getCommaDelimitedKeys = memoize(object => {
return Object.keys(object).join(",");
});
const fruits = {
apple: 95,
avocado: 234,
banana: 133
};
@Aaronius
Aaronius / debuggere2esetup.js
Created January 26, 2021 23:23
Setting up launch properties and edge configurations for Debugger e2e tests
async function setUpEdgeConfigurationAndEnvironment({ blackbird }) {
console.log('Creating edge configuration.');
const config = await blackbird.createConfig({
description: 'Dummy from test',
enabled: true,
title: `Debugger E2E Test Config ${uuid()}`,
type: ''
});
const environment = await blackbird.createEnvironment(config.id, {
type: 'development',
@Aaronius
Aaronius / blackbird.js
Created January 28, 2021 17:10
Blackbird Mini SDK (WIP)
/*
Copyright 2021 Adobe. All rights reserved.
This file is licensed to you 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 distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.