Skip to content

Instantly share code, notes, and snippets.

View heptal's full-sized avatar

Michael B heptal

View GitHub Profile

Displaying images in the terminal with tput and echo

output

Requires ImageMagick, easily available from your favorite package manager. Tested on Linux and OSX
convert image.png -resize 40 txt:-|sed -E 's/://;s/\( ? ?//;s/, ? ?/,/g;s/\)//;s/([0-9]+,[0-9]+,[0-9]+),[0-9]+/\1/g;s/255/254/g;/mage/d'|awk '{print $1,$2}'|sed -E 's/^0,[0-9]+ /print "echo;tput setaf "\;/;s/^[0-9]+,[0-9]+ /print "tput setaf ";/;s/(.+),(.+),(.+)/\1\/42.5*36+\2\/42.5*6+\3\/42.5+16/'|bc|sed 's/$/;echo -n "  ";/'|tr '\n' ' '|sed 's/^/tput rev;/;s/; /;/g;s/$/tput sgr0;echo/'|bash
@heptal
heptal / terminal_gif.md
Last active December 20, 2015 03:58
GIFs? In MY terminal?!

Video

Seems to run stable for hours!

If you can't see your cursor after killing it, run tput cnorm

Sometimes you may see a seq error if you run it multiple times with different resolutions in the same session. Easier to make a new session, or you can change it unset the variables used initially.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Getting started with IPython Notebook and Anaconda

For beginners and experts alike, IPython Notebook, along with the package collection Anaconda, has to be the premier interactive Python environment for playing, learning, prototyping, and exploring data. IPython Notebook is a browser-based environment where you can combine code execution, text, mathematics, plots and rich media into a single document. Look at these awesome examples (

@heptal
heptal / NSInputStreamHelper.swift
Last active October 20, 2015 12:57
Some convenient Swift extension methods for reading raw or binary data in NSInputStream
// Convenience extension for reading from NSInputStream from swift
// Useful for reading binary data in chunks using arbitary structs
extension NSInputStream {
func readByteArray(len: Int) -> [UInt8] {
var readBuffer = Array<UInt8>(count:len, repeatedValue: 0)
let numberOfBytesRead = self.read(&readBuffer, maxLength: readBuffer.count)
assert(numberOfBytesRead == len)
return readBuffer
}
@heptal
heptal / amphetamine.md
Last active December 27, 2023 20:30
Hammerspoon replacement for Caffeine

Amphetamine

Simple toggleable menubar replacement for Caffeine in Hammerspoon, utilizing ASCIImage (for vector) to create the amphetamine icons. Motivated by the official Caffeine app's icon looking bad on Retina

Get latest version here: amphetamine.lua

Save as amphetamine.lua in ~/.hammerspoon/ and put amphetamine = require "amphetamine" in your init.lua

@heptal
heptal / hs_autocomplete.md
Last active January 26, 2016 20:39
hammerspoon autocomplete

Hammerspoon console autocomplete

Hackjob of autocomplete in the Hammerspoon console
Binds tab to autocomplete when console window has focus using hs.window.filter
This is all user lua except for the added hs.console.getInput which returns text and cursor position
Autocompletes on everything in _G, help.hs.whatever, hs.thing.otherthing, etc. Autocompletes userdata object methods via getmetatable

local function complete(consoleInput)
    local text, position = consoleInput['text'], consoleInput['cursorPosition']
@heptal
heptal / volumes.md
Last active July 18, 2016 10:02
Removable volume manager in Hammerspoon

A simple menubar utility for opening/ejecting/managing removable volumes that looks good in OSX Dark mode:

Conveniently hides itself when no volumes are mounted and reappears when one is mounted:

Get it here - volumes.lua

Save as volumes.lua in ~/.hammerspoon/ and put volumes = require "volumes" in your init.lua

@heptal
heptal / docker.md
Last active March 9, 2016 21:36
Docker manager in Hammerspoon

Docker management menubar utility

Got tired of having to constantly manipulate the docker CLI commands for basic operations and for which the API has changed rapidly in the past year (much top-ranked info out there is out of date)

Assuming docker is installed (brew cask install dockertoolbox):

  • Start/stop/remove docker containers
  • Easily copy container IP to pasteboard addresses by just clicking
  • Conveniently open browser on container's exposed port
  • Open Kitematic GUI app included with dockertoolbox by clicking Docker