Skip to content

Instantly share code, notes, and snippets.

View monners's full-sized avatar

Josh Moncrieff monners

  • Bueno Systems
  • Melbourne
View GitHub Profile
@monners
monners / RenderCount
Created June 25, 2020 00:36
Component that counts and displays the number of times it has been rendered.
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 September 28, 2017 21:06
Atom 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 August 18, 2017 05:40
Basic scrollLock class for mobile menus
class ScrollLock {
constructor () {
this.pageBody = document.querySelector('.body');
this.scrollY = 0;
}
saveScrollY = (num) => {
this.scrollY = num;
}
@monners
monners / promise_example.js
Created January 23, 2017 21:55
Promise creation example
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 January 23, 2017 21:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
// 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 March 25, 2016 22:09
Utility function for making Objects iterable
function makeObjectIterable (obj) {
obj[Symbol.iterator] = function *() {
let properties = Object.keys(this);
for (let p of properties) {
yield this[p];
}
}
return obj;
}

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 September 28, 2012 07:21
javascript - continuous loop
var Loop = function() {
someFunction();
setTimeout(Loop, 10);
};
window.onload = Loop;
@monners
monners / gist:3798424
Created September 28, 2012 07:16
javascript - Continous function call
window.onload = function() {
setInterval( rotate, 50);
};