A blogspot journal showcasing computer programming, personal development, and other hobbies. Featuring Raspberry Pi, Petit Computer, and miscellaneous How-To.
Showing posts with label for. Show all posts
Showing posts with label for. Show all posts
Thursday, January 9, 2014
Book Review #18
RuleBook for argument
Anthony Weston
By chance, I picked this book up at a college bookstore. I was just shopping for the regular textbook, and I saw this little book. I was intrigued, and picked it up. In truth, I have learned all the rules described in the book, except I didn't have names to them. This book not only outlines the logic behind the rules, but also the fallacies that people use to fool you.
Nowadays, everytime somebody used any of the fallacies, instead of commenting and explaining their errors, which can take a while and may involve heated words, I simply say, for example, "ad populus" or "ad hominem" or "circular reasoning." And unless the other person corrects the error, I always leave the conversation. It has save me a lot of time in avoiding wasteful conversations with idiots.
The book was out of print for a while. I'm glad that the book has gone at least four printings, with the latest including a small treatment for the internet generation. I have since found that the wikipedia has a much more comprehensive set of logical rules and fallacies, but this book remains the gold standard not only in what it includes, but also what it excludes. It has that magic balance of not too much, not too little. Highly recommended.
Thursday, October 3, 2013
Book Review #4
Raspberry Pi for Beginner bookazine
This magazine-as-a-book is part of LinuxUser&Developer bookazine series. Just like a magazine, it is filled with large glossy color, and features easy to read passages. The problem with the format is that there are lots of different articles exploring different ideas, but limited in length. So, it's much of an exploration of ideas, as opposed to books that dwell in implementation details. The closest thing I can think of is O'Reilly Getting Started series, except it's light on resources, and plenty of photos. With that in mind, I still enjoyed the bookazine tremendously.
It starts with the basics, what is Pi, what do you do with it, and so one. It seems like every book about Pi deals with it. Considering the volume, though, it's clear that this bookazine is intended for extreme novice. For that, I think this is a good first Raspberry Pi book. My interest lies in the middle section: Projects. It's here that I find articles about remote control car, solar powered pi, webcam server, and so on. Unfortunately, these are light on details. Which means two things:
- The issues explored are necessarily brief, focusing only on core features and functions.
- The problem solving, in case something goes wrong, is non-existent.
To be fair, point#2 is also light in other works, including technical books. But with longer text, I can usually research such troubles on the Internet. I'm having trouble picking up keywords to research the problem further. In the end, if the project is successfully modified, it is because I spent hours, if not days, researching the subject matter. I don't think that's a good book implementation. But it's certainly acceptable for magazine implementation.
In other words, is this bookazine format successful? If you think of it as fountain of knowledge, then no. If you look at it as fountain of ideas, then it succeeds admirably. So, if you're a new Raspberry Pi user or someone who's interested in knowing what Raspberry Pi is all about, then this bookazine is a good first Raspberry Pi book to start.
Tuesday, September 17, 2013
Raspberry Pi Journal #23
Sorting Log Frequency List
A lot of times, in analyzing log files, you want to see how often something happens. Maybe you want to know how often a particular user logon in a day, or how many times a web page is accessed? If you want to do a daily report, you want to automate the process. Well, there is an easy way to do it using Perl. But since I'm still learning the shell, I want to know if there's a way to do it using shell, not necessarily the most efficient, but as long as it's relatively quick, then it should be alright.
The first thing you want is a way to get only the relevant piece of data. I want to do this in two steps:
1. Identify the wanted line
2. put the identifying unique word in a line in a file.
Let's say I want to parse /var/log/messages.1 for various processes. I would do this:
egrep -o 'raspberrypi [[:alnum:]]+' messages.1 | egrep -o [[:alnum:]]+$ | sort > messlist.txt
replacing "raspberrypi" with your unique SSID_hostname. The "-o" option says that only the matching text, instead of the whole line will be piped out. I do it twice, first with the tell-tale SSID token, then only the process name. I also sort the file and write it out to messlist.txt
We now have the frequency list. How will we get unique names of the list? Simplicity itself. I simply sort it out again, with the "-u" option.
sort -u messlist.txt > messuniq.txt
That's all there is to it!
Now that we have two files, one containing the unique id, and the other contains all the instances of the ids, we can now count them no problem.
for NAM in `cat messuniq.txt`;
do
echo $NAM `egrep $NAM messlist.txt | wc -l` ;
done
If you are familiar with computer programming at all, you will probably recognize that this algorithm is not at all efficient. What it basically does is for each entry in messuniq.txt, scan all entries in messlist.txt, outputting only those that matches, and count each occurrence. It's pretty easy to do. It's easy-as-a-bubble-sort, and just as inefficient.
But it works, and works well. So, there you go. If you want to do frequency counting, no need to bring out some large, bloated scripting engine. Just do it via shell!
By the way, I was confused by the instruction in using "for" loops. I keep using the square brackets, and keep getting invalid token error. It was only after I step back, and consider all possibilities that I guessed that the square brackets are there only to indicate optional entries. As such, I eliminate all the square brackets, and it works!
Here is the script in its entirety:
#!/bin/bash
egrep -o 'raspberrypi [[:alnum:]]+' messages.1 | egrep -o [[:alnum:]]+$ | sort > messlist.txt
sort -u messlist.txt > messuniq.txt
for NAM in `cat messuniq.txt`;
do
echo $NAM `egrep $NAM messlist.txt | wc -l` ;
done
And here is the output:
kernel 6379
motion 1545
mtp 34
rsyslogd 19
shutdown 14
wpa 366
Subscribe to:
Posts (Atom)