Skip to content

Instantly share code, notes, and snippets.

View gemmadlou's full-sized avatar

Gemma Black gemmadlou

View GitHub Profile
@gemmadlou
gemmadlou / CollectionOffset.php
Last active April 4, 2017 10:47
Using Guzzle With Events Plugin
<?php namespace Helper;
// This calculates the offset indexes for the Plugin
class CollectionOffset
{
private $postsPerPage;
private $page;
public function __construct($postsPerPage = 10, $page = 1)
{
@gemmadlou
gemmadlou / SimpleEventBus.js
Last active April 12, 2017 08:56
Simple Event Bus (ES6) < 20 lines
let bus = {
messages: {},
on(message, callback) {
if (!this.messages[message]) {
this.messages[message] = [];
}
if (typeof callback === 'function') {
this.messages[message].push(callback);
}
},
@gemmadlou
gemmadlou / fetch.js
Last active May 18, 2017 13:49
Fetch API js
var create = function(name) {
var data = JSON.stringify({
title: name, author: 'Gemma'
})
fetch('http://localhost:3000/posts', {
method: 'POST',
body: data,
headers: {
'Accept': 'application/json',
@gemmadlou
gemmadlou / 01-The-Builder-Pattern.md
Last active June 29, 2017 15:39
The Builder Pattern

The Builder Pattern

Why

  • You want encapsulation
  • You have too many parameters for your class constructor.
  • You want immutability

First Attempt

@gemmadlou
gemmadlou / 01.js
Last active July 14, 2017 21:06
Working Towards Functional Programming
console.clear();
let model = {
data: {
state: 'waiting'
},
set(type, value) {
this.data[type] = value;
@gemmadlou
gemmadlou / functional-domain-modelling-01.js
Last active September 28, 2017 11:13
Functional Domain Modelling
console.clear();
let initstate = {
attendees: [],
likes: [],
matches: [],
meetings: [],
}
let addDelegate = (State, name) => {
@gemmadlou
gemmadlou / example.js
Last active August 17, 2017 15:15
Simple Observer Pattern Again
var bus = {
messages: {},
on(message, callback) {
if (this.messages[message] === undefined) {
this.messages[message] = [];
}
this.messages[message].push(callback)
},
emit(message, data) {
if (this.messages[message] !== undefined) {
@gemmadlou
gemmadlou / swipe.js
Created August 26, 2017 17:07 — forked from SleepWalker/swipe.js
A simple swipe detection on vanilla js
var touchstartX = 0;
var touchstartY = 0;
var touchendX = 0;
var touchendY = 0;
var gesuredZone = document.getElementById('gesuredZone');
gesuredZone.addEventListener('touchstart', function(event) {
touchstartX = event.screenX;
touchstartY = event.screenY;
@gemmadlou
gemmadlou / objectToArray.js
Last active August 30, 2017 18:42
Object to array
let delimiter = ':';
Object.keys(obj).reduce((a, b) => {
return obj[b] !== undefined ? a.concat(b + delimiter + obj[b]) : a;
}, []);
@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)
// ----
/*
_ ______ _ __ _
(_) |___ / | | / _(_)
_ ___ ___ / /_______ _| |__ ______| |_ ___ __