No more comments
August 18, 2008 on 5:33 pm | In Site | No CommentsUntil I can install another spam blocker, comments are disabled.
Very Useful MySQL command
August 13, 2008 on 10:24 pm | In SQL | No CommentsIn my continuing work on the new Community Council Database, I’ve moved into the database storage engine. I recently encountered a perplexing problem: I want whoever created a case to automatically vote it up. The table that stores the votes information has 4 user fields: `id` for the vote id, `case_id` for the case it is about, `user_id` for the user who cast the vote, and `vote` for what they voted.
The problem here is that I don’t know the id of the case that’s just been created. After some searching, I noticed that MySQL has an operator LAST_INSERT_ID. I simply modified my SQL to be INSERT INTO `cases_votes` VALUES (NULL,LAST_INSERT_ID(),$user,1);
Color your Bash
August 13, 2008 on 12:30 am | In Programming | No CommentsAt home, I use two computers: a desktop and a server. The server is headless, I access it only via SSH. If I’m mucking around with it, I’m regularly SSH’d into the box using a gnome-terminal I have embedded in my desktop. The only problem is that I regularly use Bash to access my local computer such as killing tasks and shutting down.
The problem, here, is that I constantly forget which computer I’m logged into. killall firefox doesn’t work on my server, and shutdown -h now is a real pain because the server needs a few keystrokes to bootup.
At school in the Computer Science Club’s room, our firewall runs a version of Smoothwall. Smoothwall’s terminal is vey different than the normal username@box:directory$ approach that most Linux terminals use. Its most striking figure was that it was blue and red instead of the normal terminal default. This made it very easy to tell when I was working with the firewall.
I decided to take this approach to my server. I did a quick google for “color bash prompt” and ended up at this lovely page.
The tutorial led me to the variable that controls the bash prompt: PS1. In shell scripting in UNIX-like operating system is used only when reading a variable, not when assigning it. To view your PS1 value, you can type echo $ps1. You use the normal = operator to For example, if for some reason you wanted a smiley face at the end of your prompt, you would type PS1="$PS1:-)“.(To reset your terminal, you can just log in and out, or close and open your terminal.)
The username@box:directory$ that is so common would be \u@\h:\w\$. The linked site above explains each individual meaning. It also explains the color tags: '\e[x;ym $PS1 \e[m' The only part you need to replace is x;y within that block. I chose brown, so I would use '\e[0;33m $PS1 \e[m'.
As I explained above, however, you will lose changes to whatever you have done once you logout. to preserve these changes, you must edit .bash_rc. This file will be in your home (~) folder. Simply paste the command you wish to run at the end of the file, it will execute on startup.
teeg@bubs:~$
Hopefully, this color change will help you remember what computer you’re working with. Also, you can mix and match more than one color within the command (like smoothwall did), so be creative!
Crossword Puzzles
July 30, 2008 on 9:54 pm | In Mini script, Programming | 1 CommentMy mum is a crossword puzzle person. She gets her puzzles from The Washington Post’s website. Generally, I print of 3-4 at a time for her. Today, I decided to automate that process.
I wrote a short little batch script to handle the job for me.
#!/bin/sh
num=`zenity –entry –text “How Many Puzzles?”`
if [ ${#num} -eq 0 ]; then
zenity –warning –text “No number entered!”
exit 1
fi
for i in $(seq $num); do
date=`date –date=”$i days ago” +%y%m%d`
wget “http://crosswords.washingtonpost.com/wp-srv/style/crosswords/util/csserve$
lp cwpuzzle.gif -o fitplot -s
rm cwpuzzle.gif
done
exit 0
Some explinations:
lp is the command I used to print the images I got from wget. I had to define my printer as a variable using PRINTER=’i560′ (where i560 is the name of my printer)
zenity is a command to display windows in gnome, sort of like a very flexible alert() in javascript.
This script is most likely worthless to you as is (unless you’re a crossword fanatic as well) but you should be able to modify it to your own needs pretty easily.
SSL
July 19, 2008 on 9:35 pm | In Personal | No CommentsFor some reason, I’ve started becoming more and more paranoid. I think it’s that I’m going back to school soon(ish), and I’ll have someone constanly monitoring my web traffic. Also, with the return of Benedetto, I’m using more and more open wireless networks. I can’t really get a VPN setup going for my house, as my upstream bandwidth is rated at a solid ‘trickle’. One thing I do do, however, is to use SSL (https) for as many sites as possible.
This is pretty simple. Any site you visit regularly, especially those with personal information on them, often offer secure access to the site. Simply replace the http:// in front of the url with https://. My results so far:
Many Google services work with https://
Facebook has https, but half the links will take you back to plain http.
Netvibes, unfortunately, does not appear to have a secure edition.
Beep
June 14, 2008 on 11:17 pm | In Mini script, Python | 1 CommentI wrote a really short python script today. It plays an octave from an optional starting point (as a command line parameter) using system beep.. If you don’t know, an octave is twice a given frequency. I used the standard 8 notes. So if you specify a frequency that is a note on a normal scale, it will be a normal octave.
note: This script assumes some form of Unix with the beep command installed (sudo apt-get install beep on ubuntu/debian). If you know how to do a system beep from a command line in Windows, tell me.
Ajax Demos
June 13, 2008 on 10:28 pm | In Javascript, PHP, SQL, Web Design | No CommentsAnother 3 months, another blog post!
I’ve been playing a bit with AJAX recently. For these little projects, I’ve been using JavaScript client side, PHP server side, and basic CSS for prettiness. None of the things I’ve been doing have been terribly complex, just little proof-of-concepts.
- A basic sorting implementation
- A basic filter
- Page changes
- Not technically AJAX, but it is JavaScript. Tic Tac Toe.
(The SQL account these are connected to only has SELECT permissions, so no funny stuff)
Say No to Cloning
March 16, 2008 on 2:47 pm | In Design, Programming | No CommentsBeing the rebellious, zealous soul that I am, I recently began using Open Office at school to the exclusion of Microsoft Office. The first major difference I noticed was… nothing. Everything looked almost exactly the same, right down to the gradients on the toolbars.
This is not what the free software movement is about. We all want a greater user share, but if we’re just copying Redmond, what’s the point? They’re still calling the shots.
I’ve been seeing this quite often lately in the Open Source world. I’m afraid that in our quest to ‘win’ the user’s support, we will end up simply as Microsoft Office you don’t have to pay for. This would certainly be a very hollow victory. If free software is to ‘win’ at all, it should be from merit.
Keep this in mind, developers. Make sure you place innovation before friendliness to switchers.
Cross-table SQL Queries
February 19, 2008 on 7:52 pm | In SQL | No CommentsI was doing some work on a new MySQL Database, and I came a across a problem. I needed to access data from two different tables. I have two tables. The first is a table of students (name, parent name, etc.) and the other is a database of break plans. There is a field in break plans called `student_id` which corresponds to the `id`field in students. I need to run queries that return results from fields on both tables. I could run seperate queries and join them with coding later. However, the reason for the existance of a language like SQL is not having to do everything yourself. I did a bit of digging, and came across a solution:
SELECT `students`.`first_name` , `students`.`last_name`,`breaks`.`destination` FROM `plans` , `students` WHERE `students`.`id` = `plans`.`student_id`
The SELECT `students`.`first_name`, `students`.`last_name`, `breaks`.`destination` is easy enough to understand. Not that it in necessary to include the `table`. is necessary, as you have more than one table in the FROM `plans` , students` makes all the row names ambiguous. The WHERE `students`.`id` = `plans`.`student_id` is the important bit. This statement tells SQL to link together these two tables by this factor. When you run this query, you will get results that are combined appropriately.
How to Teach Programming
February 11, 2008 on 10:22 pm | In Java, Programming, Wetware | No CommentsMy first real programming experience was with Java at a WCATY summer program. The course was extrodinarily effective, I learned about as much in two weeks as I did in a semester-long course at school. The teacher was charismatic (He pointed and shouted ‘eeeeevil’ whenever anyone but a semicolon after an if stamement), and it was a lot of fun.
The style of the class was quite simple. Our instructor gave us a number readings to do, and we worked at our own pace through the material. The most essential part, though, was that our instructor was always available and willing to help us at every possible turn. This prevented most of the frustrations I had, which would have derailed me for a long time.
Because this was a 6-7 hour a day class, it’s not really feasible for a normal classroom environment. However, the general ‘work at your own pace’ model is a good one to follow, as most of the greatest programmers taught themselves completely. I believe that this has to do with the fierce independence that is necessary to become a successful programmer. Conventional programmers who are never willing to break molds will never truly innovate.
Entries and comments feeds. Valid XHTML and CSS. ^Top^ Powered by WordPress with jd-nebula-3c theme design by John Doe.