Tuesday, September 24, 2013

Dynamically altering filenames in a for loop using bash

So I had to move a couple of #flightgear screenshots around on my system, and came up with a oneliner to do it.

And of course, #bash, as always, fails horribly with spaces-in-filenames. So this one won't work if there are spaces.

for x in $(locate --regex "fgfs-screen-...\.png")
# in a subshell, execute a search to find the following files:
## any file beginning with fgfs-screen-
## followed by three of any characters
## followed by .png
# then, for each iteration of the loop, store the list element to $x
  do echo $x
# print the filename to the terminal
y=`stat -c %Y %x
# store the time of last modifcation, seconds since Epoch to $y
z=`basename $x`
# strip the directory path and store it to $z
mv -v "$x" "$z{%-*}-$y.png"
# move the original file to a new file with:
## in the current directory,
## everything with the basename stripped after the final -
## adding the epoch timestamp and file extension
done
# finish for loop


  



the results of this endeavor are viewable here: http://imgur.com/a/dkOu4#0 

Tuesday, December 4, 2012

Yet Another Bash Battery Monitor

I wanted to tweak my bash battery monitor so that it displayed an updated value everytime a sub-shell returned. Coloring code adds cruft, so I removed it for this example. Here is what works for me:

(Add to .bashrc, PS1 section):
if [[ ( -e $HOME/.battery_check )   ]]; then
    PS1="[\$($HOME/.battery_check)] ${debian_chroot:+($debian_chroot)}\u@\h:\w\$ "
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi


(create an executable file $HOME/.battery_check with the following)
#!/bin/bash
BATTERY=/proc/acpi/battery/BAT0
REM_CAP=`grep "^remaining capacity" $BATTERY/state | awk '{ print $3 }'`
FULL_CAP=`grep "^last full capacity" $BATTERY/info | awk '{ print $4 }'`
BATSTATE=`grep "^charging state" $BATTERY/state | awk '{ print $3 }'`

CHARGE=`echo $(( $REM_CAP * 100 / $FULL_CAP ))`

case "${BATSTATE}" in
   'charged')
   BATSTT="$BLD="
   ;;
   'charging')
   BATSTT="$BLD⚡"
   ;;
   'discharging')
   BATSTT="$BLD-"
   ;;
esac

echo -e "${CHARGE}${BATSTT}"

Saturday, November 24, 2012

List packages by installed size (Debian, Ubuntu)

Ever want to find out which packages on your Debian-based Linux system are taking up the most space? Want to list them by size? use this command

$ dpkg-query -W -f='${Installed-Size} ${Package} ${Version}\n' | sort -n
Today I installed Ubuntu 13.04 ("Raring Ringtail"). It should be called "Retarded Ricky", because even Ricky from the Trailer Park Boys would be able to use this, and in fact, only Ricky would be satisfied with it.

This version of Ubuntu, like the previous one, comes with Unity is installed. Unity < windows 95.

So, let's fix this rotten piece of crap and turn it into something usable. I never thought I'd have to uninstall bloatware from an Ubuntu system...

# apt-get install -y vim lynx byobu


let's look at the package list and see what I don't need.

# dpkg -l



# apt-get --purge remove bluez branding-ubuntu brltty empathy evolution-data-server evolution-data-server-common gwibber libreoffice radeontool remmina rhythmbox unity*


# apt-get install jwm afterstep gnome-themes-extras


Well, after logging out the graphics system refuses to start. Guess I'll just stick to Windows 95 for now.

Monday, February 20, 2012

a silly little script to calculate the differences between time

feed it a string from date using the format at the bottom of the script


#!/usr/bin/python

import sys
import datetime

class timediff:
  strarg=""
  def __init__(self, args=sys.argv[1:]):
    print 'time is now: ', datetime.datetime.utcnow()
    print 'your input was: ',args
    self.strarg=args


  def toDT(self, thenstr):
    strpformat="%Y,%m,%d,%H,%M,%S"
    try:
      return datetime.datetime.strptime(thenstr, strpformat)
    except:
      print "there is something wrong with your input, did you use format like: ", strpformat
      sys.exit(-1)

  def thennow(self, then, now=datetime.datetime.now() ):
    timediff = (now - then)
    minutes = timediff.days*1440 + timediff.seconds/60
    return minutes
  # print number of minutes between then and .now()
#  date +%Y,%m,%d,%H,%M,%S

Wednesday, February 8, 2012

settings ups of the vim editor for javascript development

So I've been following the tutorial here: http://arturadib.com/hello-backbonejs/docs/5.html
and I realized that my vim settings just weren't cutting it for the indentation in JS.

I found this blog: http://www.brankovukelic.com/post/2091037293/turn-vim-into-powerful-javascript-editor and followed the directions to install git://github.com/pangloss/vim-javascript.git

After using hardlinks to install the pertinent files (he uses ruby's rake instead of sh) and also using jsbeautify, it seems to be working nicely.

Here's a link to my current config: www.blackdotcompany.com/vim-js-conf.tgz

Tuesday, February 7, 2012

well that was interesting

Well basically I was having a very very annoying and very reproducible error with SSH and MAC packet corruption (Not the HWADDR MAC, but the SSH-TCP specific checksum).

I couldn't figure it out at all.

There was another problem as well -- on many websites, firefox would crash like nobody's business. Very reproducible on flickr and youtube. I even built firefox in debug mode and turned on gdb and couldn't figure it out!

It was getting so annoying I just installed Mint. See ya later Debian/Wheezy. Get your shit together.