Skip to content

Instantly share code, notes, and snippets.

View iamnoah's full-sized avatar

Noah Perks Sloan iamnoah

  • Texas
  • 02:16 (UTC -05:00)
View GitHub Profile
@iamnoah
iamnoah / normalize-argocd-kustomization.sh
Created April 28, 2021 02:52
Convert ArgoCD source overrides into the equivalent kustomization.yml
#!/usr/bin/env bash
cd $1 || exit 1
to_json() {
ruby -ryaml -rjson -e 'YAML.load_stream(ARGF) do |doc| puts JSON.generate(doc) end'
}
(for override in .argocd-source*.yaml
do
@iamnoah
iamnoah / json-logs.sh
Last active March 30, 2021 23:44
Formats JSON log lines (naively assumed to start with "{") in console output while preserving the non-JSON lines
jlog() {
local FORMAT=${FORMAT:-'"\(.timestamp) \(.level)\t - \(.name) - \(.message)\t\t\(del(.timestamp, .message, .level, .name, .traceback))\(if .traceback then "\r\n\(.traceback | gsub("\n"; "\r\n"))" else "" end)\r"'}
tee >( grep --line-buffered -v "^{" > /dev/tty ) | grep --line-buffered "^{" | jq --raw-output --unbuffered "$FORMAT"
}
# USAGE: command that prints json logs | jlog
@iamnoah
iamnoah / console.viz.js
Last active August 29, 2015 14:04
console.viz
/**
* Usage:
console.viz("digraph foo { a -> b; }");
*/
(function(global) {
"use strict";
if (!global.console) {
return;
}
@iamnoah
iamnoah / SassMeister-input.scss
Created July 22, 2014 19:42
Generated by SassMeister.com.
// ----
// Sass (v3.3.10)
// Compass (v1.0.0.alpha.20)
// ----
.bar {
color: green;
}
define(function(require) {
var compute = require("can/observe/compute/compute");
/**
* Simple mixin that allows using CanJS Maps, Models and computes in React components.
*
* The render method becomes a compute. Any change calls forceUpdate.
* React will take the new virtual DOM and efficiently update the real DOM
* only if needed.
*
@iamnoah
iamnoah / webServer.groovy
Created March 6, 2014 16:33
Minimal Groovy for a static webserver. Suitable for use with gradle run
/**
* Usage:
groovy webServer.groovy [-Pport=80] [-PwebRoot=/path/to/files]
*
* Or with gradle, place in src/main/groovy, and place assets in src/main/webapp
* and use as the mainClassName.
*/
import com.sun.net.httpserver.*
// only supports basic web content types
@iamnoah
iamnoah / steal-warn.js
Created September 14, 2013 04:52
Convert steal.dev.warn calls to console.warns
/**
* Shaper for cleaning up steal 3.2 declarations. Multiple calls are collapsed into a single
* wrapped call and non-dependant arguments are sorted.
*/
if (typeof define !== 'function') { var define = require('amdefine')(module); }
define(['../shaper', '../fmt', '../ref', '../tkn'], function(Shaper, Fmt, Ref, tkn) {
"use strict"; "use restrict";
new Shaper("steal-warn", function(root) {
@iamnoah
iamnoah / amdify.js
Created September 14, 2013 04:50
Convert stealJS modules to AMD modules
/**
* Shaper for cleaning up steal 3.2 declarations. Multiple calls are collapsed into a single
* wrapped call and non-dependant arguments are sorted.
*/
if (typeof define !== 'function') { var define = require('amdefine')(module); }
define(['../shaper', '../fmt', '../ref', '../tkn'], function(Shaper, Fmt, Ref, tkn) {
"use strict"; "use restrict";
var args = process.argv,
@iamnoah
iamnoah / cleanup-modified-js.sh
Created July 12, 2013 14:28
Crude bash script to run my jsshaper quotes and alpha plugins on any file in the current git project that has been modified. i.e., a sort of pre-commit cleanup.
TARGET_DIR="`pwd`/"
cd `dirname $0`
for f in $(cd "$TARGET_DIR" && git status | grep "\.js$" | cut -c14- | awk -v root="$TARGET_DIR" '{ print root $1 }')
do
node run-shaper.js "$f" plugins/quotes.js plugins/alpha.js --source > "$f".fixed
mv "$f"{.fixed,}
done
@iamnoah
iamnoah / quotes.js
Last active December 19, 2015 16:38
Simple JS Shaper plugin to convert all single quoted strings to double quotes.
/**
* Usage:
* 1. git clone git://github.com/olov/jsshaper.git
* 2. mv quotes.js plugins/
* 3. node run-shaper.js TARGET_FILE plugins/quotes.js --source > CORRECTLY_QUOTED_FILE
*/
if (typeof define !== 'function') {
var define = require('amdefine')(module);
}