Skip to content

Instantly share code, notes, and snippets.

View matthewstokeley's full-sized avatar
🎯
Focusing

Matthew Stokeley matthewstokeley

🎯
Focusing
View GitHub Profile
@matthewstokeley
matthewstokeley / elements.js
Last active December 14, 2018 14:28
an incredibly light-weight class for handling css classes of element with a jQuery-esque syntax
import './addClass';
import './removeClass';
import './addAttribute';
import './removeAttribute';
export default var elements = (element) => {
return {
addClass: (className) => { return addClass(element, className) },
removeClass: (className) => { return removeClass(element, className); },
@matthewstokeley
matthewstokeley / pojo-to-replace-conditional.js
Last active December 15, 2018 01:50
objects can be used instead of conditionals and switches
/**
* This is an object
* where we can store methods
* that are accessible with a string
*/
var conditional = {
humanities: () =>
@matthewstokeley
matthewstokeley / really-simple-form-to-xhr-request.md
Created December 15, 2018 15:23
really simple form to xhr request

Really simple form-to-xhr requests with FormData, Request and onclick

<form id="form">
    <input id="input" name="input" placeholder="" />
    <input type="submit" onclick="submitForm(event)" />
</form>
@matthewstokeley
matthewstokeley / grid-coordinates-with-drag-event.js
Created December 17, 2018 14:50
Find grid coordinates with the drag event object - needs testing.
var findX = () => event.clientX - event.target.offsetLeft;
var findY = () => event.target.offsetTop - event.clientY;
@matthewstokeley
matthewstokeley / whatis.js
Last active April 19, 2019 14:24
whatis - returns type
var given = function(object, property) {
var does = (property) => given(object, property);
var exist = () => {
if (!is(object).object) return false
!object.hasOwnProperty(property)
? false
@matthewstokeley
matthewstokeley / listening-to-the-lifecycle-of-a-mutating-object.md
Last active December 31, 2018 13:42
Listening to the life cycle of a mutating object
<block data-src="src" data-alt="hello"></block>
<button onclick="click(event)">
@matthewstokeley
matthewstokeley / promises-to-async-await.md
Last active November 9, 2019 22:27
a comparison of different ways to handle asynchronous responses

note: await is not available in ie

in this xhr library, which offers a simple xhr api and a request api using html data attributes, I used a pubsub pattern to listen for events. Until IE support is offered, this is a nice and agnostic client-side approach without needing polyfills or complicated build processes.

var events = {
    events: [],
    emit: function(event, response) { ... },
    addEventListener: function(event, fn) { ... }
}
@matthewstokeley
matthewstokeley / D3-sandbox.js
Last active January 2, 2019 02:56
D3 line graph encapsulation (WIP)
// type definitions needed
const scale = (scale: String, domain: Array<Number>, range: Array<any>) => d3[scale]().domain(domain).range(range)
const axis = (scale: D3Scale) => d3.axis(scale)
const data = new Set(
[], [], [], []
);
for (const gridCoordinate of data) {}
#!/usr/bin/env node
var express = require("express");
var app = express();
app.listen(process.env.EXPRESS_PORT || 3002,
"127.0.0.1",
function (error) {
if (error) process.exit(10);
});

SVG commands

WIP

M, m - moveto

(x, y)+