Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh Moncrieff monners

  • Bueno Systems
  • Melbourne
View GitHub Profile
@monners
monners / RenderCount
Created Jun 25, 2020
Component that counts and displays the number of times it has been rendered.
View RenderCount
import React from 'react'
import styled from 'styled-components'
export default function RenderCount() {
const renders = React.useRef(0)
return <Circle>{++renders.current}</Circle>
}
const size = 30
@monners
monners / keymap.cson
Last active Sep 28, 2017
Atom keymap.cson
View keymap.cson
# Your keymap
#
# Atom keymaps work similarly to style sheets. Just as style sheets use
# selectors to apply styles to elements, Atom keymaps use selectors to associate
# keystrokes with events in specific contexts.
#
# You can create a new keybinding in this file by typing "key" and then hitting
# tab.
#
# Here's an example taken from Atom's built-in keymap:
@monners
monners / gist:330f8c59b5fbfc9b140b10d948ce5263
Created Aug 18, 2017
Basic scrollLock class for mobile menus
View gist:330f8c59b5fbfc9b140b10d948ce5263
class ScrollLock {
constructor () {
this.pageBody = document.querySelector('.body');
this.scrollY = 0;
}
saveScrollY = (num) => {
this.scrollY = num;
}
@monners
monners / promise_example.js
Created Jan 23, 2017
Promise creation example
View promise_example.js
function ajaxRequest (url, cb) {
setTimeout(() => {
cb({ height: 1000, width: 500});
}, 2000)
}
const p = new Promise((res, rej) => {
ajaxRequest('url', (data) => {
res(data);
})
@monners
monners / 0_reuse_code.js
Created Jan 23, 2017
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View Flexbox-grid-extended
// Disabling the linter on this for now.
// scss-lint:disable SelectorFormat
// NOTE: Inactive to avoid potential conflicts - We might use this later in the Consumer project rebuild
// .container-fluid,
// .container {
// margin-right: auto;
// margin-left: auto;
// }
//
@monners
monners / makeObjectIterable.js
Created Mar 25, 2016
Utility function for making Objects iterable
View makeObjectIterable.js
function makeObjectIterable (obj) {
obj[Symbol.iterator] = function *() {
let properties = Object.keys(this);
for (let p of properties) {
yield this[p];
}
}
return obj;
}
View gist:6061271

So, you want to send a motherfucking XMLHttpRequest (XHR, or commonly and falsly known as AJAX.) Too bad, just ran out of motherfucking XMLHttpRequests; but I still have one regular. XHR is not magic. It does not autofuckinmagically send things the way you want them do be sent. It does not do the thinking for you. It just sends an Http Request.

You get a hold on such a prime beast like this:

@monners
monners / gist:3798438
Created Sep 28, 2012
javascript - continuous loop
View gist:3798438
var Loop = function() {
someFunction();
setTimeout(Loop, 10);
};
window.onload = Loop;
@monners
monners / gist:3798424
Created Sep 28, 2012
javascript - Continous function call
View gist:3798424
window.onload = function() {
setInterval( rotate, 50);
};