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
@scarolan
scarolan / movein.sh
Created June 12, 2013 14:25
movein.sh - Nice little "move in" script from O'Reilly's excellent Linux Server Hacks book.
#!/bin/sh
# movein.sh - shamelessly stolen from O'Reilly's excellend "Linux Server Hacks"
# http://oreilly.com/pub/h/72
# Version 0.2 - Added some comments and error checking
if [ -z "$1" ]; then
echo "Usage: `basename $0` hostname"
exit
fi
@scarolan
scarolan / Vagrant_SSH_Shortcuts
Last active December 18, 2015 11:29
"vlist" and "vssh" commands for working with Vagrant virtual machines. Drop these in your .bashrc. vlist creates a list of all your running VMs. vssh loops through all your VMs, and attempts to run commands on each of them.
# vlist generates a list of running Vagrant VMs
vlist ()
{
vagrant status | awk '/running/{ print $1 }'
}
# vssh runs your command(s) on all VMs. Enclose in quotes to run multiple commands.
vssh ()
{
[ $# -ne 1 ] && (echo "Usage: vssh command"; return 1)
@scarolan
scarolan / Vim_Syntax_for_Vagrantfile
Created June 14, 2013 14:01
Vim syntax highlighting for Vagrant. Drop this into $HOME/.vim/plugin/vagrant.vim to activate.
" Teach vim to syntax highlight Vagrantfile as ruby
"
" Install: $HOME/.vim/plugin/vagrant.vim
" Author: Brandon Philips <brandon@ifup.org>
augroup vagrant
au!
au BufRead,BufNewFile Vagrantfile set filetype=ruby
augroup END
@scarolan
scarolan / AWS_Unixify_Windows
Last active June 7, 2018 15:02
This gist will create a new user with Administrator rights on a Windows server AWS instance, install Cygwin and SSHD, and open port 22 so that you can access the machine using SSH. This makes using Windows *much* more tolerable for the Unix administrator. Simply use the script below in your "User Data" field when deploying a new instance. The <p…
<powershell>
# First we add our administrative user, replace username and password with your own
$computer=$env:ComputerName
$user="username" ## Change this!
$password='password' ## And change this too!
$objOu = [ADSI]"WinNT://$computer"
$objGroup = [ADSI]"WinNT://$computer/Administrators,group"
$objUser = $objOU.Create("User", $user)
$objUser.setpassword($password)
@scarolan
scarolan / Powershell_Install_Cygwin_Packages
Created July 7, 2013 22:09
Powershell code for installing cygwin packages.
# Download and install cygwin and some packages
function Install-Cygwin {
param ( $TempCygDir="$env:temp\cygInstall" )
if(!(Test-Path -Path $TempCygDir -PathType Container))
{
$null = New-Item -Type Directory -Path $TempCygDir -Force
}
$client = new-object System.Net.WebClient
$client.DownloadFile("http://cygwin.com/setup.exe", "$TempCygDir\setup.exe" )
# This does a vanilla installation of Cygwin

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
@scarolan
scarolan / console_screensaver.sh
Last active December 20, 2015 02:39
Grabs image thumbnails from Flickr's API, then uses @heptal's most excellent "image" function to convert them into images in your terminal. If you want to search Flickr for multiple tags simply enclose them in quotes. ImageMagick and Python are required to use this.
#!/bin/bash
# Set a higher ulimit so we don't segfault
ulimit -s 32768
search_string=$1
search_string=${search_string// /%20}
# Courtesy of heptal's Console Colors
# https://gist.github.com/heptal/6052573
function image() {
@scarolan
scarolan / console_screensaver_large.sh
Last active December 20, 2015 02:49
Same as console_screensaver.sh but with the width set to 150. Make sure to maximize your terminal window before running!
#!/bin/bash
# Set a higher ulimit so we don't segfault
ulimit -s 32768
search_string=$1
search_string=${search_string// /%20}
# Courtesy of heptal's Console Colors
# https://gist.github.com/heptal/6052573
function image() {
@scarolan
scarolan / user_data.ps1
Last active December 22, 2015 10:19
Powershell script to be used with the AWS user_data field, to prepare Windows instances for bootstrapping with the knife tool.
<powershell>
# Set the administrator password
$ComputerName = $env:COMPUTERNAME
$user = [adsi]"WinNT://$ComputerName/Administrator,user"
$user.setpassword("******")
# Get the instance ready for our bootstrapper, commands courtesy of Julian Dunn
winrm quickconfig -q
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
@scarolan
scarolan / httpd_cookbook_centos6.rb
Last active December 15, 2019 07:54
Refactored Apache default recipe for Chef Fundamentals Training - CentOS version
#
# Cookbook Name:: apache
# Recipe:: default
#
# Copyright 2013, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#
package "httpd" do