Skip to content

Instantly share code, notes, and snippets.

@cspotcode
cspotcode / example.bash
Created October 3, 2017 19:20
Logging all bash script output
#!/bin/bash -x
exec > /tmp/transcript.log 2>&1
# This trick means the bash scripts logs its entire execution,
# both the commands executed and the output of those commands,
# to the transcript file.
@cspotcode
cspotcode / example.ps1
Created September 30, 2017 00:01
Open a page in headless Chrome; open DevTools in another window
$headlessDataDir = "$( (Get-Location).Path )/headlessDataDir"
$devtoolsDataDir = "$( (Get-Location).Path )/devtoolsDataDir"
$remoteDebuggingPort = 9222
$urlToInspect = https://www.example.com
# Open headless browser
& 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' "--user-data-dir=$headlessDataDir" --headless --remote-debugging-port=$remoteDebuggingPort $urlToInspect
# Open DevTools
& 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' "--user-data-dir=$devtoolsDataDir" "http://localhost:$remoteDebuggingPort"
@cspotcode
cspotcode / delete-merged-git-branches.ps1
Created September 5, 2017 14:28
Delete old, merged git branches from a remote
# Recipe for deleting old, merged branches from a remote repository
# delete stuff already merged into this branch...
$developBranch = 'develop'
# ...and whose most recent commit is older than this...
$ifOlderThan = [datetime]'06-01-2017'
# ...on this remote
$remote = 'origin'
# Get list of all remote branches already merged into develop
@cspotcode
cspotcode / copy.js
Created January 24, 2017 23:04
Faster Grunt copy task
import {unique} from 'lodash';
import * as path from 'path';
/*
* Grunt copy task that's faster by eliminating unnecessary or redundant fs calls.
*
* Things it does *not* do:
* - set or copy file mode / permissions
* - "process"ing files
* - "process"ing files as raw buffers
@cspotcode
cspotcode / README.md
Last active February 28, 2017 08:18
ts-loader .jsx bug reproduction

To reproduce:

$ npm install
$ npm run tsc
# tsc emits all code to tsc-out as expected
$ npm run webpack
# Errors indicate that it can't find either .jsx files but it can find the .js files
@cspotcode
cspotcode / arun
Last active February 25, 2016 23:32
Reproduction of stylus/stylus#2125
#!/usr/bin/env bash
npm install stylus
# Dump all output into log.txt
exec > >(tee -i zlog.txt)
exec 2>&1
### Bug reproduction:
echo ====================================================================================
@cspotcode
cspotcode / index.js
Last active February 5, 2016 06:51
stylus-deps-bug
"use strict";
const stylus = require('stylus');
const path = require('path');
const fs = require('fs');
if(['before', 'after'].indexOf(process.argv[2]) === -1) throw new Error('bad argument');
const getDepsBeforeRender = process.argv[2] === 'before';
const files = [
@cspotcode
cspotcode / README.md
Last active January 11, 2016 18:52
Trails structure for large projects using transpiled languages

Sails and Trails current directory structures look like this:

/api/...
/config/...
/assets/...

The server executes code directly from the source code directory. It executes the same code files that are stored in version control.

When using compiled languages, we need to convert our TypeScript, CoffeeScript, ES2015, etc files to .js. Naively, we might add a few .gitignore rules:

@cspotcode
cspotcode / example.js
Created December 17, 2015 23:32
Parsing streaming JSON with Oboe
var oboe = require('oboe');
var stream = require('stream');
var Readable = stream.Readable;
var Writable = stream.Writable;
var readable = new Readable();
readable._read = function() {};
readable.push('{"some": "json"}{"more": [1, 2, 3], "json": true}{"final json object": 12345}{"stream continues...');
readable.push(null);
@cspotcode
cspotcode / Gruntfile.js
Last active April 25, 2016 05:44
Grunt template functions (alternative to template strings)
module.exports = function(grunt) {
// Store a reference to the template function constructor
var tmpl = grunt.template.fn;
grunt.initConfig({
// support running "copy:dev:blog", "copy:dev:homepage" or "copy:dev:contactForm"
copy: {
dev: {
files: [tmpl(=> { // look ma, all Javascript! No code hiding in strings.