Skip to content

Instantly share code, notes, and snippets.

  • 🎨 when improving the format/structure of the code
  • 🚀 when improving performance
  • ✏️ when writing docs
  • 💡 new idea
  • 🚧 work in progress
  • ➕ when adding feature
  • ➖ when removing feature
  • 🔈 when adding logging
  • 🔇 when reducing logging
  • 🐛 when fixing a bug
@pocotan001
pocotan001 / globals.snippets.js
Last active April 29, 2023 15:03
Finding improper JavaScript globals.
// globals.js
// https://gist.github.com/pocotan001/6305714
// Finding improper JavaScript globals
(function() {
var prop, cleanWindow,
globals = new function globals() {},
body = document.body,
iframe = document.createElement('iframe'),
ignore = {
@pocotan001
pocotan001 / ico.css
Created April 25, 2013 10:50
ico.css
/*
# .ico-
*/
[class^="ico-"]::before,
[class*=" ico-"]::before {
display: inline-block;
content: "";
vertical-align: middle;
}
[class^="ico-"]:not(:empty)::before,
const error = new Error('unicorn')
const serialized = JSON.stringify(error, ['name', 'message', 'stack'])
console.log(error) // { name: 'Error', message: 'unicorn', stack: 'Error: unicorn\n at Object.<anonymous> …' }
@pocotan001
pocotan001 / times.js
Last active April 8, 2019 04:42
Loop for N times
const n = 10
Array.apply(null, Array(n)).forEach( … )
// or
[...Array(n).keys()].forEach( … )
// or
Array(n).fill().forEach( … )
@pocotan001
pocotan001 / reduce.js
Last active June 1, 2018 09:33
Create an object instead of an array
const ABC = ["a", "b", "c"];
ABC.reduce((acc, key) => {
acc[key] = `${key}!`;
return acc;
}, Object.create(null));
ABC.reduce(
(acc, key) => Object.assign(acc, { [key]: `${key}!` }),
@charset "UTF-8";
/* ================================================== [ Reset ] */
* {
margin: 0;
padding: 0;
}
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
display: block;
@pocotan001
pocotan001 / Route.js
Last active December 20, 2016 11:19
client router
import pathToRegexp from 'path-to-regexp'
import queryString from 'query-string'
export default class Route {
/**
* @param {string} path
* @param {Function} handler
*/
constructor (path, handler) {
this.path = path
@pocotan001
pocotan001 / Store.js
Last active July 5, 2016 07:44
Higher-order component form of connectToStores
import { EventEmitter } from 'events'
import Dispatcher from '../Dispatcher'
const CHANGE_EVENT = 'change'
/**
* Extend certain stores from a this `Store` class
*/
export default class Store extends EventEmitter {
emitChange () {
@pocotan001
pocotan001 / removeReactIds.js
Last active July 5, 2016 05:36
func: removeReactIds
removeReactIds() {
const children = this.el.querySelectorAll('[data-reactid]');
this.el.removeAttribute('data-reactid');
Array.prototype.forEach.call(children, (child) => {
child.removeAttribute('data-reactid');
});
}