Skip to content

Instantly share code, notes, and snippets.

View gemmadlou's full-sized avatar

Gemma Black gemmadlou

View GitHub Profile
@gemmadlou
gemmadlou / serverless.yml
Created January 16, 2019 11:02 — forked from DavidWells/serverless.yml
DynamoDB custom index serverless.yml example
service: service-name
provider:
name: aws
runtime: nodejs6.10
functions:
myfunc:
handler: handler.myfunc
@gemmadlou
gemmadlou / gist:d36f1eefa98a1807c4625faa08de8554
Created January 11, 2019 18:36 — forked from tott/gist:7767218
.htaccess rule to force www and preserving the protocol http/https
# 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());
});
@gemmadlou
gemmadlou / execAsync.js
Created May 3, 2018 20:40 — forked from davidrleonard/execAsync.js
Node exec async (with shell.js and bluebird)
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:
*
@gemmadlou
gemmadlou / UserSingleton.php
Created April 23, 2018 10:21 — forked from amacgregor/UserSingleton.php
PHP Singleton pattern example
<?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
@gemmadlou
gemmadlou / nodejs-custom-es6-errors.md
Created January 16, 2018 14:11 — forked from slavafomin/nodejs-custom-es6-errors.md
Custom ES6 errors in Node.js

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.

Defining our own base class for errors

errors/AppError.js

@gemmadlou
gemmadlou / collection.php
Created October 19, 2017 14:47 — forked from ircmaxell/collection.php
Monads - PHP
<?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);
@gemmadlou
gemmadlou / inline-svg-function.scss
Created October 16, 2017 13:14 — forked from JacobDB/inline-svg-function.scss
Inline SVG function [SASS]
// 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;
}
@gemmadlou
gemmadlou / the-bind-problem.jsx
Created September 21, 2017 11:39 — forked from Restuta/the-bind-problem.jsx
React, removeEventListener and bind(this) gotcha
/* 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));
@gemmadlou
gemmadlou / SassMeister-input.scss
Created September 7, 2017 14:29 — forked from lunelson/SassMeister-input.scss
iOS 7 vh unit workaround MIXIN
// ----
// Sass (v3.4.12)
// Compass (v1.0.3)
// ----
/*
_ ______ _ __ _
(_) |___ / | | / _(_)
_ ___ ___ / /_______ _| |__ ______| |_ ___ __