iTerm2: inline images(Ruby)

Because Python is slower on my machine, I made a little script to use the proprietary escape code of iTerm2 for printing pictures inline.

Nothing fancy, just to exercice.

require "base64"

def printi(α)
    χtmp = nilα, 'rb') { |χf|
        χtmp = Base64.encode64(χ
    puts("\x1b]1337;File=name=#{Base64.encode64(α)};inline=1:" + χtmp + "\a\n")

IPython: Rename images with their SHA1 chekcsum

I got lazy, I don’t want to rename pictures anymore so I name them with their own sha1 checksum, so I made a really quick script to do that under IPython.

def grapimages():
"""return a list of all images in the current folder """
μ = list()
tmp = !ls | grep '[PpJjGg][NnPpIi][GgEeFf][Gg]\{0,1\}'

for ii in tmp:
if ii.lower().endswith('png') or ii.lower().endswith('jpg') or ii.lower().endswith('jpeg') or ii.lower().endswith('gif'): μ.append(ii)

return μ

def rensha():
"""rename images from the current folder with their own sha1 checksum""" χt = ''
iu = ''

for ii in grapimages():

with open(ii, 'rb', ) as φχer:
χt = sha1(φχ

if ii.lower().endswith('jpeg'): # + exception for jpegs iu = '{}.jpg'.format(χt)
iu = '{}.{}'.format(χt, ii.split('.')[-1])

! mv $ii $iu

Yes I use IPython’s ability to use shell commands to populate python variables. But I told you it’s quick shit, or “life hack” like those pseudo geeks loves to call them. ;)