Here's how you could create custom error classes in Node.js using latest ES6 / ES2015 syntax.
I've tried to make it as lean and unobtrusive as possible.
errors/AppError.js
service: service-name | |
provider: | |
name: aws | |
runtime: nodejs6.10 | |
functions: | |
myfunc: | |
handler: handler.myfunc |
# Force www | |
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ | |
RewriteCond %{HTTPS}s ^on(s)| | |
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] |
import {createServer} from 'http'; | |
function waitForChromeToTerminate() { | |
let retry = 5; | |
return new Promise((resolve, reject) => { | |
const server = createServer(); | |
server.listen(9222); | |
server.once('listening', () => { | |
debug('Port is free') | |
server.close(() => resolve()); | |
}); |
const Promise = require('bluebird'); | |
const sh = require('shelljs'); | |
/** | |
* Asynchronously executes a shell command and returns a promise that resolves | |
* with the result. | |
* | |
* The `opts` object will be passed to shelljs's `exec()` and then to Node's native | |
* `child_process.exec()`. The most commonly used opts properties are: | |
* |
<?php | |
/** Example taken from http://www.webgeekly.com/tutorials/php/how-to-create-a-singleton-class-in-php/ **/ | |
class User | |
{ | |
// Hold an instance of the class | |
private static $instance; | |
// The singleton method |
<?php | |
class CollectionMonad extends Monad { | |
public function __construct(array $value) { | |
$this->value = $value; | |
} | |
public function bind($callback) { | |
$newValues = array(); | |
foreach ($this->value as $value) { | |
$newValues[] = $this->callCallback($callback, $value); |
// Replace letters | |
@function str-replace($string, $search, $replace: '') { | |
$index: str-index($string, $search); | |
@if $index { | |
@return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace); | |
} | |
@return $string; | |
} |
/* Sometimes it's pretty easy to run ito troubles with React ES6 components. | |
Consider the following code: */ | |
class EventStub extends Component { | |
componentDidMount() { | |
window.addEventListener('resize', this.onResize.bind(this)); //notice .bind | |
} | |
componentWillUnmount() { | |
window.removeEventListener('resize', this.onResize.bind(this)); |
// ---- | |
// Sass (v3.4.12) | |
// Compass (v1.0.3) | |
// ---- | |
/* | |
_ ______ _ __ _ | |
(_) |___ / | | / _(_) | |
_ ___ ___ / /_______ _| |__ ______| |_ ___ __ |