Skip to content

Instantly share code, notes, and snippets.

@jmendiara
jmendiara / cache.ts
Last active December 14, 2020 14:15
LRU Cache for Promises in typescript
import LRU from 'lru-cache';
/**
* Small utility around an LRU cache that gives us some features:
* - Promisification: Async ready to easily change to a memcached/redis implementation
* - Improved get method, to make more expressive usage of the pattern "if not found
* in the cache, go get it, store in the cache, and return the value"
* - Funnel values: Promises are stored and returned, so if the value for a key
* is being obtained while another get is requested, the promise of the value is returned
* so only one request for value is done
@jmendiara
jmendiara / index.ts
Last active December 18, 2020 01:03
Concurrent TaskQueue with lifecycle notification in typescript (alike a Promise.map with concurrency and continue on failure)
import { TaskQueue, TaskSuccessEvent, TaskErrorEvent, QueueStartEvent, QueueCompleteEvent } from "/taskqueue";
// Define several task with optional titles
const firstTask = () => new Promise<void>((resolve, reject) => setTimeout(resolve, 1000));
firstTask.title = '1 second timeout';
const secondTask = () => new Promise<void>((resolve, reject) => setTimeout(() => reject(new Error('boom!')), 1000));
secondTask.title = '1 second failed timeout';

Keybase proof

I hereby claim:

  • I am jmendiara on github.
  • I am jmendiara (https://keybase.io/jmendiara) on keybase.
  • I have a public key whose fingerprint is B818 2FBD 2CED 9DF0 1D2C 9A19 C4CF 4990 702C E9F7

To claim this, I am signing this object:

var sensorLib = require('node-dht-sensor');
var sensor = {
initialize: function () {
return sensorLib.initialize(22, 22);
},
read: function () {
var readout = sensorLib.read();
console.log('Temperature: ' + readout.temperature.toFixed(2) + 'C, ' +
'humidity: ' + readout.humidity.toFixed(2) + '%');
@jmendiara
jmendiara / features.md
Last active August 29, 2015 14:20
Angular $http features wishlist

This is an opinionated list of desired Angular capabilities and feature lacks, to open debate and looking for best ways to solve them

Caches

  • We cannot be confident about the URL used as cache key: Removing, getting or updating $http cache entries in userland is hard and hacky. httpu.headers helps on solving this issue.
  • $cacheFactory.Cache is private: This causes reimplementing all the logic for a $cacheFactory API, instead of letting users to specify with kind of cache a $cacheFactory is returning.
  • We cannot control how a $cacheFactory.Cache key is generated: You have to decorate all your $cacheFactory implementations ($cacheFactory.Cache is private). Exposing a key generator method somewhere may help
  • We cannot know if a request comes from the server or the cache Core implementation
@jmendiara
jmendiara / Gruntfile.js
Created April 14, 2014 07:45
Execute Grunt tasks iteratively based on external config. It will allow you to modify the input parameters for the same tasks without modifying the Gruntfile.
grunt.initConfig(
//The build task is in charge of creating a compilation enforcing
//one parameter in the HTML code: the url
build: {
//The default options for the build task
options: {
//The source file
src: 'app/index.html'
}
/*
@jmendiara
jmendiara / extrapixel.html
Created February 1, 2012 17:43
Annoying extra-pixel in Firefox
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<style type="text/css">
p {
line-height:32px;
font-size:28px;
font-family:Arial, Helvetica, sans-serif;
}