Posts Tagged ‘battery’

Pause (and then resume) Battery-Guzzling programs

Wednesday, June 7th, 2017

My laptop battery dies quickly these days. Certain apps (cough, cough, Slack), have very high idle CPU-usage. You can pause these programs with

killall -STOP Slack

And later you can resume the application with

killall -CONT Slack

Coffee Shop Compiler

Monday, December 15th, 2014

Here’s a proposal for a compiler/build system for developers like myself who often find themselves coding in a coffee shop with strong wifi connection, but poor power outlet availability and limited battery life.

The standard coding and debugging cycle looks like:

  1. Code for a bit
  2. Think for a bit
  3. Repeat steps 1 and 2 for a bit
  4. Compile (make)
  5. If compile failed return to step 2
  6. Run executable
  7. Return to step 2

The power bottleneck (for my typical cycle) is by far step 4. My idea is to outsource compiling to a server (plugged into a wall outlet). The naive implementation would change the cylce to:

  1. Code for a bit
  2. Think for a bit
  3. Repeat steps 1 and 2 for a bit
  4. compile on server
    1. send code to server
    2. compile on server
    3. if compile failed, send back errors and return to 2
    4. send back executable
  5. Run executable
  6. Return to step 2

A better implementation might roll git into the make command on the local machine:

  1. Code for a bit
  2. Think for a bit
  3. Repeat steps 1 and 2 for a bit
  4. special make
    1. git commit; git push on client
    2. git pull on server
    3. regular make on server
    4. if compile failed, send back errors and return to 2
    5. send back executable
  5. Run executable
  6. Return to step 2

An even fancier implementation might try to keep the changing files in sync during idle time in step 2.

I guess this is assuming my executable is relatively small. Here dynamic (shared) libraries would be especially handy.

Battery level warning for mac os x

Thursday, September 23rd, 2010

My girlfriend’s MacBook has an embarrassingly short battery life and has a habit of just shutting off without any warning. I wrote a little bash script to pop up a warning if her battery gets below a threshold. Here’s the script, I save it in a file called ~/.battery_warning.sh:


#!/bin/bash
min_percentage="15"
percentage=`pmset -g batt | grep -o "[0-9]\+%; discharging" | \
  sed -e "s/%.*$//"`
if [ "$percentage" ]; then
  if [[ $percentage -lt $min_percentage ]] ; then
    osascript -e "tell application \"System Events\"
        activate
        display dialog \"Battery almost dead: $percentage%\" \
          with icon 0 with title \"Warning\" buttons {\"OK\"} \
          default button 1
      end tell"
  fi
fi

Then I set it up as a cron job to check every 5 mins:


*/5 * * * *  bash ~/.battery_warning.sh