Skip to content

Instantly share code, notes, and snippets.

View drejohnson's full-sized avatar

DeAndre Johnson drejohnson

View GitHub Profile
module Moment = {
type t;
[@bs.send.pipe : t] external format : string => string = "";
[@bs.send.pipe : t] external utcOffset : string => t = "";
};
[@bs.module] external _moment : string => Moment.t = "moment";
let moment = (value) => _moment(value);
let unitConfig = Fela.Plugins.unit_config(~unit_="rem", ());
let extendPlugin = Fela.Plugins.extend;
let embeddedPlugin = Fela.Plugins.embedded;
let prefixerPlugin = Fela.Plugins.prefixer;
let fallbackValue = Fela.Plugins.fallbackValue;
@drejohnson
drejohnson / styletron.re
Created November 28, 2017 06:10
basic styletron bindings for reasonml
type t;
type getStylesheetsHtmlMeth = {. "getStylesheetsHtml": [@bs.meth] (unit => unit)};
[@bs.val] external styletron_client_option : array(string) => t = "";
[@bs.module "styletron-client"] [@bs.new] external styletronClient : 'a => 'a = "default";
[@bs.module "styletron-server"] [@bs.new]
external styletronServer : unit => getStylesheetsHtmlMeth =
@drejohnson
drejohnson / fela.re
Last active November 28, 2017 09:56
basic fela.js bindings for reasonml
type t;
[@bs.obj]
external renderer_options :
(
~plugins: array(t)=?,
~enhancers: array(t)=?,
~mediaQueryOrder: array(string)=?,
~supportQueryOrder: array(string)=?,
~selectorPrefix: string=?,
import * as path from 'path';
import * as ExtractTextPlugin from 'extract-text-webpack-plugin';
import * as AssetsPlugin from 'assets-webpack-plugin';
import * as CompressionPlugin from 'compression-webpack-plugin';
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
import * as ManifestPlugin from 'webpack-manifest-plugin';
import * as webpack from 'webpack';
import { clientConfiguration, serverConfiguration } from 'universal-webpack';
import settings from './universal-webpack-settings';
@drejohnson
drejohnson / require-to-import.txt
Created February 25, 2016 21:29
Convert require statement to ES2015 import statement
Search:
var\s+(\w+)\s+\=\s+require\((("|')[a-zA-Z0-9\/\.-]+\3)\)\;?
Replace:
import $1 from $2;
@drejohnson
drejohnson / restful.js
Created October 2, 2015 02:15 — forked from BinaryMuse/restful.js
Express API with Async/Await
import express from "express";
/**
* Takes a route handling function and returns a function
* that wraps it after first checking that the strings in
* `reserved` are not part of `req.body`. Used for ensuring
* create and update requests do not overwrite server-generated
* values.
*/
function checkReservedParams(routeHandler, ...reserved) {
Provider Singleton Instantiable Configurable
Constant Yes No No
Value Yes No No
Service Yes No No
Factory Yes Yes No
Decorator Yes No? No
Provider Yes Yes Yes

Constant

.video { position: relative; padding-bottom: 56.25%; /* 16:9 */ height: 0; }
.video img { position: absolute; display: block; top: 0; left: 0; width: 100%; height: 100%; z-index: 20; cursor: pointer; }
.video:after { content: ""; position: absolute; display: block;
background: url(play-button.png) no-repeat 0 0;
top: 45%; left: 45%; width: 46px; height: 36px; z-index: 30; cursor: pointer; }
.video iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
/* image poster clicked, player class added using js */
.video.player img { display: none; }
.video.player:after { display: none; }

Resolve a promise from a custom promise

Or: Turning a function into a promise

What most Angular Promise Tutorials Fail to teach You: Creating the promise

So many times while learning how to use promises, or trying to use them in my Angular applications, I would discover pieces of functionality that needed to be a promise, but weren't a $resource (or one of it's derivates).

Most tutorials show a final result of something like this: