Skip to content

Instantly share code, notes, and snippets.

View DarrylD's full-sized avatar
💭
daydreaming

Darryl D. DarrylD

💭
daydreaming
View GitHub Profile
function getErroringPromise() {
console.log('getErroringPromise called');
return Promise.reject(new Error('sad'));
}
Observable.defer(getErroringPromise)
.retry(3)
.subscribe(x => console.log);
// logs "getErroringPromise called" 4 times (once + 3 retries), then errors
@royto
royto / ES6 Angular Directive with injection
Last active October 25, 2017 18:01
Example of Angular Directive as ES6 class with injection
class myDirective {
constructor(userService) {
this.template = `<div>{{fullName}}</div>`;
this.restrict = 'E';
this.scope = {
user: '='
};
this.link = function(scope, element) {
scope.fullName = userService.getFullName(scope.user);
};
@gbabiars
gbabiars / Scores.js
Created December 20, 2015 21:15
Basic example of RxJS and React
import React from 'react';
import axios from 'axios';
import Rx from 'rxjs';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
scores: []
};
@nz
nz / bonsai.md
Last active July 3, 2018 22:51
Bonsai.io - The ElasticSearch add-on for Heroku

Bonsai offers a Heroku add-on for ElasticSearch.

ElasticSearch is the latest generation search engine built on the powerful Lucene library. Its API is freshly designed around modern RESTful JSON conventions, making it easy to learn and understand. ElasticSearch will automatically index your JSON data with sensible defaults, which means that you can get started without writing a single line of configuration. ElasticSearch is the perfect place to start for anyone new to full-text search engine concepts, or for anyone who is looking for more clarity and less ceremony in their search engine.

The ElasticSearch internals are designed from the ground up with data distribution in mind. This means you get greater scalability, performance and reliability in a cloud hosted environment. An ElasticSearch index can automatically shard your data, to scale to the largest indexes and support high volumes of write traffic. All of our

@deltaepsilon
deltaepsilon / rxjs-firebase-demo.js
Created September 8, 2016 17:44
Demo RxJs integration with Firebase
var Rx = require('rxjs');
var firebase = require('firebase');
firebase.initializeApp({
"databaseURL": "https://quiver-two.firebaseio.com",
"serviceAccount": "./service-account.json"
});
var ref = firebase.database().ref('rxjs-demo');
Rx.Observable.fromPromise(ref.remove())
.map(function () {
@MicheleBertoli
MicheleBertoli / App.jsx
Last active August 30, 2018 13:12
React Automata
import React from 'react'
import { Action, withStatechart } from 'react-automata'
const statechart = {
initial: 'idle',
states: {
idle: {
on: {
FETCH: 'fetching',
},
@mjackson
mjackson / resolvePromise.js
Last active September 9, 2018 08:23
An easy way to do async APIs in JavaScript that support both promises *and* callbacks!
// Here is a function that I use all the time when creating public
// async APIs in JavaScript:
const resolvePromise = (promise, callback) => {
if (callback)
promise.then(value => callback(null, value), callback)
return promise
}
// Sometimes I like to use callbacks, but other times a promise is
@mykelswitzer
mykelswitzer / component.jsx
Created September 11, 2015 00:41
React.js with pickadate.js
// How to get the pickadate to mount correcty in React.js component
// requires jQuery and pickadate.js (https://github.com/amsul/pickadate.js/)
var Component = React.createClass({
getInitialState: function() {
return ({value: null});
},
componentDidMount: function() {
@tomkis
tomkis / redux-saga-confirmation-dialog.js
Last active March 14, 2019 15:02
Implementing confirmation dialog via redux-saga
import { select, put, take } from 'redux-saga/effects';
function* emptySaga() {}
export function* withConfirmation(text, onConfirm, onCancel = emptySaga) {
yield put({ type: 'ShowConfirmationDialog', payload: text });
const { type } = yield take([
'ConfirmationDialogConfirmed',
'ConfirmationDialogCanceled'
@jonsullivan
jonsullivan / cors-middleware-express-with-proxy.js
Created July 17, 2012 01:22
node.js CORS http-proxy / express middleware
// node.js proxy server example for adding CORS headers to any existing http services.
// yes, i know this is super basic, that's why it's here. use this to help understand how http-proxy works with express if you need future routing capabilities
var httpProxy = require('http-proxy'),
express = require('express');
var proxy = new httpProxy.RoutingProxy();
var proxyOptions = {
host: '192.168.3.11',