Skip to content

Instantly share code, notes, and snippets.

View joshwcomeau's full-sized avatar

Joshua Comeau joshwcomeau

View GitHub Profile
const flipMatrix = matrix => (
matrix[0].map((column, index) => (
matrix.map(row => row[index])
))
);
const rotateMatrix = matrix => (
flipMatrix(matrix.reverse())
);
const flipMatrix = matrix => (
matrix[0].map((column, index) => (
matrix.map(row => row[index])
))
);
const rotateMatrix = matrix => (
flipMatrix(matrix.reverse())
);
const rotateMatrix = matrix => (
matrix[0].map((column, index) => (
[...matrix].reverse().map(row => row[index])
))
);
const flipMatrixCounterClockwise = matrix => (
rotateMatrix(matrix).reverse()
);
const flipMatrix = matrix => (
matrix[0].map((column, index) => (
matrix.map(row => row[index])
))
);
.drawer {
position: absolute;
z-index: 10;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow: hidden;
.backdrop {
@joshwcomeau
joshwcomeau / fibonacci_abridged.js
Last active June 11, 2016 19:26
Fibonacci Generators
////// Fun with ES2015 Generators & Fibonacci Sequence //////
//
// Generators are awesome for lazy calculations, but they're less
// than ideal for certain use-cases (give me the result of the
// 1000th iteration).
//
// This is an experiment where I try to have my cake and eat it too,
// by wrapping a generator with a factory function.
//
//// Note: This is the comment-free version!
@joshwcomeau
joshwcomeau / fibonacci_unabridged.js
Last active June 11, 2016 19:25
Fibonacci Generators
////// Fun with ES2015 Generators & Fibonacci Sequence //////
//
// Generators are awesome for lazy calculations, but they're less
// than ideal for certain use-cases (give me the result of the
// 1000th iteration).
//
// This is an experiment where I try to have my cake and eat it too,
// by wrapping a generator with a factory function.
//
//// Note: This is the annotated version!
app.post('/process-upload', upload.single('image'), (req, res) => {
// Define some helper methods that provide semantic names to the
// actions in our route.
const resizeAndConvert = buffer => (
imConvertPromise({
srcData: buffer,
width: 32,
height: 16,
format: 'PNG'
})
// If the function does not take an 'errback' callback, we can still wrap our
// functions. Let's use a fictional method:
fictionalMethod(data, successCallback, failureCallback) {
fictionalAsyncOperation(data, result => {
if ( !result ) {
return failureCallback(new Error('Result not found'))
} else {
return successCallback(result);
}
})
@joshwcomeau
joshwcomeau / colours.js
Last active May 8, 2016 14:48
letter-animation
class LetterDemo extends Component {
constructor(props) { ... }
componentWillMount() { ... }
componentWillUnmount() { ... }
onStart({entering, leaving}, node) {
if (entering) {
node.classList.add('enter');