Skip to content

Instantly share code, notes, and snippets.

View tscanlin's full-sized avatar

Tim Scanlin tscanlin

View GitHub Profile
# Use preact
# Switch a react project to using preact if its isn't using it already.
#
# EX: grep -rl "preact-compat" ./node_modules/react-scripts/config/
# EX: find ./node_modules/react-scripts/config/*.config.* -type f -exec sed -i "s/alias: {/alias: {\n\t\t\t\'react\': \'preact-compat\',\n\t\t\t\'react-dom\': \'preact-compat\',/gi" {} \;
searchString=${1:-preact-compat}
filePattern=${2:-./node_modules/react-scripts/config/}
replaceString="alias: {"
const exec = require('child_process').exec
exec("npm --save uninstall react react-dom", (err, o) => {
console.log(err, o);
})
exec("npm --save install preact preact-compat", (err, o) => {
console.log(err, o);
})
var fs = require('fs')
var path = require('path')
var argCount = process.argv.length
var lastArg = process.argv[argCount - 1]
// From
// http://stackoverflow.com/questions/11194287/convert-a-directory-structure-in-the-filesystem-to-json-with-node-js
function dirTree(filename) {
var stats = fs.lstatSync(filename),
info = {
Find and replace in nodejs:
var fs = require('fs');
fs.readdirSync('.').forEach(function(path) { fs.rename(path, path.split('}').join('')); });
@tscanlin
tscanlin / gist:986262b222b60c0ff002
Created April 28, 2015 04:37
In Atom.io, if indexing a project is ever super slow, I've found adding this line under 'Ignored Names' in Setings speeds things up a lot.
*.scssc, **/node_modules/*
@tscanlin
tscanlin / 0_reuse_code.js
Created October 1, 2013 03:52
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