index2019-04-16

week 11: $random

Screen Shot 2019-04-16 at 11.31.29 AM

What IS random?! This week, I made a really slow psuedo-pseudo random number generator and applied it to my computospirit project. There is now a single base 10 random number that is generated based on things like the time of the day, the weather in various cities across the country and the time in the last modified stamp of the file that all of this data is being written to.

After the number is generated the computospirit program finds all of the paths to PDF files on the system and pipes the words in the paths to a new file. The words are then shuffled inside that new file. Finally the program chooses a block of text starting at the line number of the generated random number. This block of text is printed as the computer’s message from the file spirits to you.

Screen Shot 2019-04-16 at 9.10.01 AM

Screen Shot 2019-04-16 at 9.06.45 AM

Screen Shot 2019-04-16 at 9.07.37 AM

Screen Shot 2019-04-16 at 9.08.26 AM

So far I have written three bash script meditations: computarot, computomancy, and computospirit. I’m thinking for the final project I will make an NPM package for all of these scripts. I think I’ll want to get a little more granular with each of them so that the computer trying to get in touch with its file spirits can have a bit more control. The NPM package will be called computomancy and the following programs will be available: randomNumber, deepestFile, fileType, compuTarot, and compuSpirit.

More notes on bash:

this is useful for displaying progress while script is running

PROGRESS=$!
while kill -0 $PROGRESS 2> /dev/null
do
	echo -n "..."
  sleep .2
done


this is useful for reading each line of a file and also adding a counter

n=1
while read line; do
	n=$((n+1))

	if [[ $n -gt 5 ]]
	then
		echo "${line} is greater than five"
	fi
done < $filename


this is what an if statement looks like with some math inside

if [[ $lineNo -gt 100 ]]
then
	lineNoMax+=`expr $lineNo \* 2`
else
	lineNoMax+=`expr $lineNo \* 3`
fi


this multiplies all of the numbers in a file and prints the sum to a new file

 grep -o '[[:digit:]]*' numbers.txt | paste -s -d* - | bc > sum.txt