Skip to content

Instantly share code, notes, and snippets.

View mnewt's full-sized avatar

Matthew Newton mnewt

View GitHub Profile
@mnewt
mnewt / dsr.js
Last active May 3, 2018 21:25
Get the current column and row in the terminal using ANSI Device Status Report
#!/usr/bin/env node
// Loosely based on https://stackoverflow.com/questions/36929209/read-ansi-escape-from-terminal
'use strict';
var deasync = require('deasync');
function asyncDSR(opts, callback) {
// opts is an optional object:
// { in: input }
@mnewt
mnewt / gh-download-latest
Created May 20, 2017 21:33
Shell script to download a github project's latest release
#!/bin/sh
# Download a github project's latest release
# $1: username/repo
# $2: regex to match download file
# example: ./gh-download-latest atom/atom gz
repo=$1
regex=${2:-gz}
wget -qO- https://api.github.com/repos/$repo/releases/latest | \
@mnewt
mnewt / source.cljs
Created November 6, 2017 04:33
Lumo script demonstrating environment variable exports
(require '[clojure.data :refer [diff]])
(def ^:no-doc fs (js/require "fs"))
(def ^:no-doc child-process (js/require "child_process"))
(def ^:no-doc os (js/require "os"))
(def ^:no-doc path (js/require "path"))
(def ignore-env-vars #{"_" "OLDPWD" "PWD" "SHELLOPTS" "SHLVL"})
(defn mktemp
@mnewt
mnewt / JSONHighlight.css
Last active October 11, 2017 03:19
pretty print and syntax highlight javascript object
pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
.string { color: green; }
.number { color: darkorange; }
.boolean { color: blue; }
.null { color: magenta; }
.key { color: red; }
@mnewt
mnewt / download_if_newer.sh
Created June 16, 2017 14:52
Download a file iff URL's HTTP If-Modified-Since header is more recent than the local file timestamp
#!/usr/bin/env bash
# Download a file iff URL's HTTP If-Modified-Since header is more recent than
# the local file timestamp
url="$1"
file="$2"
shift 2
curl -z "$file" -Lo "$file" "$url" "$@"
@mnewt
mnewt / mark_read.php
Created May 16, 2017 18:51
Search for matching miniflux items and mark them as read
#!/usr/bin/env php
<?php
require __DIR__.'/miniflux/app/common.php';
use PicoDb\Database;
use Miniflux\Model\Item;
if (php_sapi_name() !== 'cli') {
@mnewt
mnewt / calendar.js
Last active March 23, 2017 22:56
Print a simple HTML calendar using javascript with no dependencies (except pure.css)
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
@mnewt
mnewt / bash_prompt.pure.sh
Created August 4, 2016 14:58
clean and simple bash prompt
#!/usr/bin/env bash
# Cygwin is special
if [ -z "${OSTYPE}" ]; then
case $(uname) in
"CYGWIN*") export OSTYPE='CYGWIN' ;;
'Darwin') export OSTYPE='Darwin' ;;
'Linux') export OSTYPE='Linux' ;;
esac
fi
#!/bin/bash
brew_command=/usr/local/bin/brew
brew_cask_command="$brew_command cask"
echo '#!/bin/bash'
echo ''
echo 'trap ctrl_c INT'
echo 'function ctrl_c() {'
echo 'echo "** Trapped CTRL-C"'
@mnewt
mnewt / plus_equals.fish
Created May 28, 2016 17:13
add numerical value to variable, like +=
function plus_equals --no-scope-shadowing
set -l __fish_value $$argv[1]
set $argv[1] (math $__fish_value + $argv[2])
end