Skip to content

Instantly share code, notes, and snippets.

View dikarel's full-sized avatar
🍪

Darius I. Karel dikarel

🍪
View GitHub Profile
// Download: go/codemod-tutorial
import { Project, SourceFile, SyntaxKind } from "ts-morph";
import { execFileSync } from "child_process";
const main = () => {
// Clean up this feature flag
cleanFeatureFlag("cnc_it_add_on");
};
@dikarel
dikarel / how-to-pipe.js
Created October 17, 2019 23:21
How to pipe shell commands in NodeJS
// In this example, we use ChildProcess and piping to perform the NodeJS
// version of `find ~/Documents | egrep '\.ts$'`
const ChildProcess = require(“child_process”);
// 1. Start both "find" and "egrep"
// "shell" has to be true, so that we have access to "~"
const find = ChildProcess.spawn("find", ["~/Documents"], { shell: true });
const egrep = ChildProcess.spawn("egrep", ["\\.ts$"], {
shell: true
@dikarel
dikarel / ml5.d.ts
Last active July 15, 2024 05:12
ml5.js TypeScript definitions draft
// Not quite there yet, but better than nothing
// TODO: JSDoc, based on website documentation
// TODO: Interface/class types for each of these ML algorithm instances
// TODO: Break this apart into multiple files for readability
// TODO: Test autocomplete in a vanilla JS project
// TODO: Test autocomplete in a TypeScript project
import { MediaElement } from "p5";
export as namespace ml5;
@dikarel
dikarel / docker-machine.md
Created December 10, 2016 10:14
Setting up a Docker machine for corporate environments

Create default Docker machine on VirtualBox with custom settings

You might want to do this to allocate extra RAM and disk size for Docker (esp. when dealing with large container images)

  1. Ensure that there's not yet been a Docker machine called 'default' (docker-machine ls). If so, you should remove it (docker-machine rm default).
    In theory, you can just create a second machine with a different name. This is not recommended since VirtualBox assigns IP addresses to each machine non-deterministically every time you restart your computer, causing docker-machine to choke on TLS cert-related issues
@dikarel
dikarel / hackerrank-util.js
Created October 2, 2016 07:14
HackerRank utilities
// Minified one-liner
var main=d=>{var l=[];return require('readline').createInterface({input:process.stdin}).on('line',i=>l.push(i)).on('close',()=>d(l))}
// Example
main(lines => {
console.log('My lines are', lines)
})
@dikarel
dikarel / hackerrank-helpers.coffee
Last active October 2, 2016 07:10
Helper classes for HackerRank
# Reads lines from stdin and run specified function
main = (done) ->
lines = []
readline = require 'readline'
readline.createInterface input: process.stdin
.on 'line', (line) -> lines.push line
.on 'close', -> done lines
# Minified one-liner
main=(d)->l=[];require('readline').createInterface(input:process.stdin).on('line',(i)->l.push i).on('close',->d l)