Skip to content

Instantly share code, notes, and snippets.

@TrySound
TrySound / svgo.config.js.js
Created September 9, 2021 09:56
Fill paths with color
const renameMaskType = {
name: 'fillPaths',
type: 'visitor',
fn: () => {
return {
element: {
enter: node => {
if (node.name === 'path') {
node.attributes.fill = '#fff';
}
// @flow
import * as React from 'react';
import ResizeObserverPolyfill from 'resize-observer-polyfill';
import invariant from 'tiny-invariant';
const useLayoutEffect = (React: any).useLayoutEffect;
const useEffect = (React: any).useEffect;
type Rect = {|
const template = (code, options, state) => `
// @flow
// Generated from ${state.filePath}
import * as React from "react";
type Props = {
size?: string | number,
fill?: string
};
  • use only named exports
  • omit class constructor
  • don't use fucking for (;;) loops
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
import compose from './compose';
/**
* Creates a store enhancer that applies middleware to the dispatch method
* of the Redux store. This is handy for a variety of tasks, such as expressing
* asynchronous actions in a concise manner, or logging every action payload.
*
* See `redux-thunk` package as an example of the Redux middleware.
const postcss = require('postcss');
const plugin1 = postcss.plugin('test', () => {
return css => {
css.walkDecls(decl => {
if (decl.value === '10px') {
decl.cloneAfter({
value: '20px'
});
}
@TrySound
TrySound / flush-time.js
Last active August 14, 2016 08:14
Benchmark tool
var map = {};
var list = [];
function timeStart(label) {
if (!map[label]) {
list.push(label);
map[label] = {
time: 0
};
}

Incremental build with less

var gulp = require('gulp');
var less = require('gulp-less');
var concat = require('gulp-concat');
var cached = require('gulp-cached');
var remember = require('gulp-remember');
var watch = require('gulp-watch');
function template(txt, data) {
var key;
for(key in data) if(data.hasOwnProperty(key)) {
txt = txt.replace(new RegExp('\\{\\{\\s*' + key + '\\s*\\}\\}', 'g'), data[key]);
}
}
@TrySound
TrySound / gulp-svg-sprite.js
Last active March 29, 2016 19:19
SVG sprite example
gulp.task('sprite', function (done) {
return gulp.src('app/sprite/**/[^_]*.svg')
.pipe(rename({prefix: 'shape-'}))
.pipe(svgmin())
.on('error', done)
.pipe(svgstore({
inlineSvg: true
}))
.on('error', done)