Skip to content

Instantly share code, notes, and snippets.

View drejohnson's full-sized avatar

DeAndre Johnson drejohnson

View GitHub Profile
#!/usr/bin/env bash
uninstall() {
list=`gem list --no-versions`
for gem in $list; do
gem uninstall $gem -aIx
done
gem list
gem install bundler
}
@drejohnson
drejohnson / SassMeister-input.scss
Created June 6, 2014 06:36
Generated by SassMeister.com.
// ----
// Sass (v3.3.7)
// Compass (v1.0.0.alpha.18)
// ----
@mixin e($name) {
@at-root &__#{$name} {
@content;
}
}
// It is important to declare your variables.
(function() {
var foo = 'Hello, world!';
print(foo); //=> Hello, world!
})();
// Because if you don't, the become global variables.
(function() {
@drejohnson
drejohnson / mobile-classes.css
Last active August 29, 2015 14:04
Small javascript snippet for adding mobile CSS classes
/* ios only styling */
.ios body {
background-color: #fff;
}
/* android only styling */
.android body {
background-color: #e7e7e7;
}

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:

.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; }
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

@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) {
@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;
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';