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.

Thursday, January 26, 2012

Disabling the default usb autosuspend in userspace on Debian Linux for keyboard and mouse

I've got a Microsoft USB 3000 mouse and a portable mini Holtek Semiconductor keyboard for my laptop. When the laptop is on battery power the default timeout for these devices is just 2 seconds, which is really mode. I mean really dumb. I mean just annoying. There's a few informational articles online that led me to this fix most notably : http://forums.whirlpool.net.au/archive/350749 

The only real problem was that the devices in /sys/bus/usb/devices don't match up to the device ID's in lsusb. But not to be deterred, by plugging and unplugging the devices in question, and comparing the output of  ls -latr /sys/bus/usb/devices  I was able to determine their correct device path in the filesystem.

So from there the fix was easy. Just find the path of the Microsoft USB 3000 mouse in the linux usb device directory, in this case, ./1-1.3 and
# cd /sys/bus/usb/devices/1-1.3/power; cat 60 > autosuspend; cat 60000 > autosuspend_delay_ms



Now my mouse doesn't suspend for a minute. Much more usable. I just wish this logspot had markdown or code tags.

Tuesday, January 24, 2012

TL;DR Here's the code:
search="font"; for x in $({ apt-cache search $search | grep $search | cut -f1 -d' ' ; dpkg -l | grep $search | awk '{print $2}' ; } | sort | uniq -u ); do apt-cache show $x  | sed -n '/Package/p;/^Description-en:/,/^Description-md5:/p'; done


Unfortunately not every package info given by apt-cache show has the same layout, so sometimes Package: is printed twice and sometimes all the package's info is printed out. We'll have to work on that.

So let's say you wanted to do the following in Debian/Ubuntu:
compare the packages you have installed pertaining to term "A" (dpkg -l | grep $A) with a list of all available packages pertaining to term "A" (apt-cache search $A | grep $A) and then print a list of those which are NOT currently installed but which pertain to term A.
The easy way to say that is "print me all packages i don't have installed containing $A in their name or short description". I believe this would be accomplished in yum with ``yum show uninstalled | grep $A'' but not totally sure.

Furthermore, I want to take that list and print the descriptions of those packages with their Package Name, so I can browse what I want to install.

Yes yes you may say I could use a software center or synaptic but whatever. This is way easier and I figured out two important things about both sed and bash.