Skip to content

Instantly share code, notes, and snippets.

@Jonarod
Jonarod / blob_conversions_util.js
Created December 7, 2019 04:56
Javascript utility to convert Blob to Base64, ImageData or ObjectUrl back and forth. Tree shakeable and promise based.
const BlobToBase64 = function(blob){
let blobUrl = URL.createObjectURL(blob);
return new Promise((resolve, reject) => {
let img = new Image();
img.onload = () => resolve(img);
img.onerror = err => reject(err);
img.src = blobUrl;
}).then(img => {
URL.revokeObjectURL(blobUrl);
@joeporpeglia
joeporpeglia / Counter.jsx
Created September 22, 2017 15:31
Redux as a Render Prop
import StoreProvider from './StoreProvider';
const increment = { type: '@counter/increment' };
const decrement = { type: '@counter/decrement' };
const initialState = { count: 0 };
const reducer = (state = initialState, action) => {
switch (action.type) {
case increment.type:
@coolaj86
coolaj86 / README.md
Last active September 6, 2021 20:20
Fastest uuid generator for node.js

Now published as @root/uuid

This is started out as a curiosity, pasted as a gist but now, years later, I've come back to it because there are too many of these uuid modules out there and they're too complicated.

This, however, is easy to read and understand (for me, at least). Even its tests are dependncy and build-step free.

node-uuid vs crazy-uuid vs fast-uuid

Folder Structure

Please note

While this gist has been shared and followed for years, I regret not giving more background. It was originally a gist for the engineering org I was in, not a "general suggestion" for any React app.

Typically I avoid folders altogether. Heck, I even avoid new files. If I can build an app with one 2000 line file I will. New files and folders are a pain.

@max-mykhailenko
max-mykhailenko / # Sublime Emmet JSX Reactjs.md
Last active November 25, 2022 23:25
Sublime text 3. Enable Emmet in JSX files with Sublime React plugin

This is no longer needed as Emmet supports JSX - you just need to turn it all on. Did a quick tutorial: http://wesbos.com/emmet-react-jsx-sublime/

Thanks, @wesbos

Problem

  • Using emmet in jsx files
  • Emmet expands text when js autocomplete needed
@branneman
branneman / better-nodejs-require-paths.md
Last active April 8, 2024 00:22
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@conorbuck
conorbuck / angle-between-points.js
Created May 5, 2012 22:51
JavaScript: Find the angle between two points
var p1 = {
x: 20,
y: 20
};
var p2 = {
x: 40,
y: 40
};