Skip to content

Instantly share code, notes, and snippets.

View gemmadlou's full-sized avatar

Gemma Black gemmadlou

View GitHub Profile
@gemmadlou
gemmadlou / breakpoint.scss
Created September 13, 2017 09:46
Media Queries
// Stolen from awesome dev cboakes
@mixin breakpoint($min-width: null, $min-height: null, $medium: screen) {
@if ($min-width != null and $min-height != null) {
@media #{$medium} and (min-width: $min-width) and (min-height: $min-height) {
@content;
}
} @else if ($min-width != null and $min-height == null) {
@media #{$medium} and (min-width: $min-width){
@content;
@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 / parseparams.js
Created September 27, 2017 10:42
Parse Params Function Stolen
/**
* JavaScript Get URL Parameter
*
* @param String prop The specific URL parameter you want to retreive the value for
* @return String|Object If prop is provided a string value is returned, otherwise an object of all properties is returned
*/
function getParam(str, prop) {
let params = {};
let search = decodeURIComponent(str);
let definitions = search.split( '&' );
@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 / 2.1-functional-domain-modelling.js
Last active October 22, 2017 18:32
Functional Domain Modelling When You Only Have Classes
class PreFlightService {
goToGate(flight) {
if (flight instanceof Flight !== true) throw new Error('Must be a flight')
if (flight.atGate) throw new Error('Flight is already at the gate');
return new Flight(Object.assign({}, flight, {
atGate: true
}));
}
refuel(flight) {
if (flight instanceof Flight !== true) throw new Error('Must be a flight')
@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 / 01-Why-Rehydrate.md
Last active October 28, 2017 15:49
Rehydrating A Domain Object (Model)

Why Rehydrate Models In The First Place?

The problem

You've gone to lengths to model your domain with the correct behaviours, the common language and the business constraints.

For example, for a music venue, here'd be a simple model.

class Show {
@gemmadlou
gemmadlou / authentication.php
Created November 22, 2017 13:10
JWT Auth Helper For Wordpress
<?php
namespace Voting\Infrastructure;
use Firebase\JWT\JWT;
use DomainException;
use SignatureInvalidException;
use UnexpectedValueException;
use Exception;
use Date;
@gemmadlou
gemmadlou / funny.js
Created November 23, 2017 07:31
Funny
console.clear()
let state = {
todos: []
}
let box = data => ({
map: fun => box(fun(data)),
fold: fun => fun(data),
val: data
@gemmadlou
gemmadlou / 001-Frameworkless.ts
Last active December 15, 2017 17:07
Frameworkless
console.clear();
type model = {
input: {
type: 'text',
class: 'someclass'
},
output: ''
}