Friday, January 15, 2010

Chapter 1 summary

Life is getting better:
- life expectancy
- health
- income
- education
- entertainment

Economics: the study of how we make a CHOICE (selections amongst alternatives) under SCARCITY (concepts that there is less available form nature than one desires)

1. Scarcity does not equal poverty
2. Scarcity necessitates RATIONING (allocating scarce goods to those who want them)
3. Scarcity leads to competitive behavior

Resources: human, physical, natural

Capital: human made resources, used to produce other goods/services

Guideposts to economic thinking:
1. opportunity cost (highest valued alternative which you sacrifice when making your choice)
2. individuals are rational (try to get more value at less cost)
3. incentives matter (change incentives, change behavior)
4. individuals make decisions at the margin, using a cost-benefit analysis
5. information helps us make better choices
6. beware of secondary effects (intentions may not equal the result)
7. the value of goods/services is subjective
8. to test a theory = to be able to predict real world events

POSITIVE economics vs. NORMATIVE economics

Pitfalls to avoid economic thinking:
1. ceteris paribus (other things constant)
2. good intentions don't guarantee desirable outcomes
3. association is NOT causation
4. fallacy of composition (what is good for 1 may not be good for ALL)

Saturday, January 9, 2010

How to fix the error: "Linux: can't open /dev/dsp" while trying to use Festival

The error:

$ festival --tts read.txt
Linux: can't open /dev/dsp


The fix:
Create file .festivalrc in the home directory of the user and paste this in it:

(Parameter.set 'Audio_Command "aplay -q -c 1 -t raw -f s16 -r $SR $FILE")
(Parameter.set 'Audio_Method 'Audio_Command)

Then, try the "festival --tts read.txt" command again, the error should be gone, and you should hear the synthesized text to speech stream.


Share

Monday, January 4, 2010

networktraffic script - shows uploads/downloads in the shell

I didn't write this script. Credits for script: whoever wrote it and posted it on some random web site.

---

cat /usr/bin/networktraffic


#!/bin/sh

usage(){
echo "Usage: $0 [-i INTERFACE] [-s INTERVAL] [-c COUNT]"
echo
echo "-i INTERFACE"
echo " The interface to monitor, default is eth0."
echo "-s INTERVAL"
echo " The time to wait in seconds between measurements, default is 3 seconds."
echo "-c COUNT"
echo " The number of times to measure, default is 10 times."
exit 3
}

readargs(){
while [ "$#" -gt 0 ] ; do
case "$1" in
-i)
if [ "$2" ] ; then
interface="$2"
shift ; shift
else
echo "Missing a value for $1."
echo
shift
usage
fi
;;
-s)
if [ "$2" ] ; then
sleep="$2"
shift ; shift
else
echo "Missing a value for $1."
echo
shift
usage
fi
;;
-c)
if [ "$2" ] ; then
counter="$2"
shift ; shift
else
echo "Missing a value for $1."
echo
shift
usage
fi
;;
*)
echo "Unknown option $1."
echo
shift
usage
;;
esac
done
}

checkargs(){
if [ ! "$interface" ] ; then
interface="eth0"
fi
if [ ! "$sleep" ] ; then
sleep="3"
fi
if [ ! "$counter" ] ; then
counter="10"
fi
}

printrxbytes(){
/sbin/ifconfig "$interface" | grep "RX bytes" | cut -d: -f2 | awk '{ print $1 }'
}

printtxbytes(){
/sbin/ifconfig "$interface" | grep "RX bytes" | cut -d: -f3 | awk '{ print $1 }'
}

bytestohumanreadable(){
multiplier="0"
number="$1"
while [ "$number" -ge 1024 ] ; do
multiplier=$(($multiplier+1))
number=$(($number/1024))
done
case "$multiplier" in
1)
echo "$number Kb"
;;
2)
echo "$number Mb"
;;
3)
echo "$number Gb"
;;
4)
echo "$number Tb"
;;
*)
echo "$1 b"
;;
esac
}

printresults(){
while [ "$counter" -ge 0 ] ; do
NOW=`/bin/date`
counter=$(($counter - 1))
if [ "$rxbytes" ] ; then
oldrxbytes="$rxbytes"
oldtxbytes="$txbytes"
fi
rxbytes=$(printrxbytes)
txbytes=$(printtxbytes)
if [ "$oldrxbytes" -a "$rxbytes" -a "$oldtxbytes" -a "$txbytes" ] ; then
echo "$NOW RXbytes = $(bytestohumanreadable $(($rxbytes - $oldrxbytes))) TXbytes = $(bytestohumanreadable $(($txbytes - $oldtxbytes)))"
else
echo "Monitoring $interface every $sleep seconds. (RXbyte total = $(bytestohumanreadable $rxbytes) TXbytes total = $(bytestohumanreadable $txbytes))"
fi
sleep "$sleep"
done
}

readargs "$@"
checkargs
printresults




Example usage:

To monitor eth0 every 10 seconds, a total of 999 times:
networktraffic -i eth0 -s 10 -c 999

To monitor eth3 every second
networktraffic -i eth3 -s 1 -c 99999


Share

Saturday, January 2, 2010

Ubuntu: Fixing error "Error: /etc/resolv.conf must be a symlink"

My error:

root@myserver:~# sudo /etc/init.d/networking start
* Configuring network interfaces...
resolvconf: Error: /etc/resolv.conf must be a symlink
run-parts: /etc/network/if-up.d/000resolvconf exited with return code 1


The fix:

root@myserver:~# cd /etc
root@myserver:/etc# sudo rm -rf /etc/resolv.conf
(if you can't remove the file, try: chattr -i /etc/resolv.conf )
root@myserver:/etc# sudo ln -s /etc/resolvconf/run/resolv.conf
root@myserver:/etc#


Test if the solution worked:

root@zeta:/etc# /etc/init.d/networking restart
* Reconfiguring network interfaces... [ OK ]
root@zeta:/etc#