Skip to content

Instantly share code, notes, and snippets.

View scarolan's full-sized avatar
🤸‍♂️
In whatever position one is in...one must find balance. -BKS Iyengar

Sean Carolan scarolan

🤸‍♂️
In whatever position one is in...one must find balance. -BKS Iyengar
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/(\w,\w,\w),\w/\1/g;/mage/d'|awk '{print $1,$2}'|python -c "import sys;f=sys.stdin.read().split('\n');f=filter(None,f);print 'tput rev;'+''.join([''.join(map(str,('echo;' if x.split(' ')[0].split(',')[0] is '0' else '','tput setaf '+str(sum(p*q for p,q in zip([36,6,1],[int(min(int(c),254)/42.5) for c in x.split(' ')[1].split(',')]))+16)+';echo -n \"  \";'))) for x in f])+'echo;tput sgr0'"|bash
<% if @port != 80 -%>
Listen <%= @port %>
<% end -%>
<VirtualHost *:<%= @port %>>
ServerAdmin webmaster@localhost
DocumentRoot <%= @document_root %>
<Directory />
Options FollowSymLinks

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
<% if @port != 80 -%>
Listen <%= @port %>
<% end -%>
<VirtualHost *:<%= @port %>>
ServerAdmin webmaster@localhost
DocumentRoot <%= @document_root %>
<Directory />
Options FollowSymLinks
<% if @port != 80 -%>
Listen <%= @port %>
<% end -%>
<VirtualHost *:<%= @port %>>
ServerAdmin webmaster@localhost
DocumentRoot <%= @document_root %>
<Directory />
Options FollowSymLinks
<#
.SYNOPSIS
Create a new desktop wallpaper from various sources and optionally overlay some text.
.DESCRIPTION
The script can be run manually, at logon or even as a scheduled task to update the wallpaper regularly
Wallpaper sources include:
- A solid colour
( •_•)
( •_•)>⌐■-■
(⌐■_■)
@scarolan
scarolan / gist:794132f8a5befe227b49
Created October 6, 2015 03:03 — forked from jimcroft/gist:3878113
Enable WinRM for Chef bootstrapping via EC2 user data
<powershell>
winrm quickconfig -q
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allow
netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow
use_inline_resources
action :create do
# Set the document root
document_root = "/srv/apache/#{new_resource.site_name}"
# Add a template for Apache virtual host configuration
template "/etc/httpd/conf.d/#{new_resource.site_name}.conf" do
source "custom.erb"
mode "0644"
@scarolan
scarolan / gist:f93a8f9b362c4d3a4436
Last active November 20, 2015 19:27
Set the tab name in iTerm to contain the current directory and git branch
function set_iterm_title {
echo -ne "\e]1;$1\a"
}
function git_branch {
BRANCH_REFS=$(git symbolic-ref HEAD 2>/dev/null) || return
GIT_BRANCH="${BRANCH_REFS#refs/heads/}"
[ -n "$GIT_BRANCH" ] && echo "$GIT_BRANCH "
}