Archive for the ‘int main()’ Category

Adventures With VPython – Pong

No Comments »

So, it’s been a crazy quarter here at UCLA – general education really is a giant time sink. Thankfully, that’ll be done after this quarter and I’ll hopefully have more time to do inane side projects like the one I’m going to talk about today.

Everyone knows about Pong – the little game that you all played on your TI-83 in high school when you were supposed to be paying attention in math class. Along with all the other games you played on your calculator – I’m hoping to play with those later. Anyway. I’ve always had an interest in 3D graphics and how they relate to games. I did some dabbling in OpenGL last summer and it was painful to say the least. I’ve also been dabbling with Python lately, so the next obvious step was to figure out how to do graphics in Python. There a lot of libraries to do this (pygame comes to mind), but I decided to use VPython. It provides all sorts of nice little things – namely the code to construct a shape.

from visual import *
square = box( pos = (0, 0, 0), size = (3, 3, 3), color = color.green)

Nice. You can give the box a velocity by doing something like:

box.velocity = vector( 5, 0, 0 )

Then you can update the position of the box accordingly using your basic physical relationships. You know, Vf = Vi + at, and all the other stuff you learned in physics. Unless you took Physics 1A with Professor Corbin at UCLA, in which case you learned all sorts of other cool stuff and aren’t sure how you passed the class. But I digress.

I started this project just trying to learn how VPython works, and I ended up implementing a version of Pong that is playable, but slightly boring. There is no score display, end-of-game info is displayed in the console, and there is no vector math implemented. Therefore, the ball always bounces at a 45 degree angle from the wall or the paddle. This is both unrealistic and boring. I’m no mathematician, and I don’t currently have the time to implement the vector math. I’ll leave that as an exercise to the reader. If you do end up implementing it, please let me know. I’m sure I’ll get around to it eventually, I just have finals coming up in the next week so it’s low on the priority list.

Anyway. That’s what I’ve been up to lately. I’m working off and on on doing a Tetris clone, and I’ll probably eventually get to Space Invaders. Maybe not with this library though. I’ll probably pick up something else (maybe a new language). Maybe I’ll go back to OpenGL or DirectX if I’m bored enough (and in a slightly masochistic mood). For those who are interested, the code is uploaded here. Comments and edits appreciated. Thanks for reading!


Happy Holidays!

No Comments »

Merry Christmas and Happy Holidays from those of us at int main()!


Testing Google Public DNS

No Comments »

In the spirit of testing things before concluding anything, I decided to test Google’s new Public DNS service against OpenDNS, 4.2.2.2 (a DNS server owned by Level 3), and the DNS servers on my network.

To test the service, I modified the excellent script created by Manu J.

#!/bin/sh
 
cur_dns=`cat /etc/resolv.conf | grep "nameserver" | tr -cs '0-9.' '[\n*]'`
 
for i in "lifehacker.com" "facebook.com" "manu-j.com"  "reddit.com" "tb4.fr" "bbc.co.uk" "intmain.net"
do
  for j in "4.2.2.2" "8.8.8.8" "208.67.222.222" $cur_dns
  do
    echo "\n$i\n$j"
    for k in $(seq 1 100)
    do
      echo `dig @$j $i | grep Query | awk -F ':' '{print $2}' | tr -cs '0-9' '[\n*]'`
    done
  done
done

My two changes were to grab the DNS servers defined in /etc/resolv.conf and to query each service 100 times. Of course, the only downside to this test is that it does not account for the DNS server caching the result of repeated queries. This effect shows up in a few of the graphs (included below).

Google’s DNS service is very consistent in speed, but is also consistently slower than any of the other servers tested. Google’s DNS service also shows very little difference with repeated requests, except for the lookup of intmain.net, where the first request took significantly longer than the others. Similarly, Google’s DNS took over 2 seconds to respond to a request of reddit.com. The final ordering is as such: the fastest in most cases was the DNS servers local to the network (except for uncommon sites, which took between 100ms and 150ms for the first request), followed by 4.2.2.2, followed by OpenDNS, and trailed by Google Public DNS.

I encourage you to perform the same (or similar) tests on your own computers and share the results. It’s very hard to tell if the differences in response times are caused by latency or lookup time, but it is clear that the best DNS servers for me to use are the ones local to my network at UCLA.

dnstest lifehacker Testing Google Public DNSdnstest facebook Testing Google Public DNSdnstest manu j Testing Google Public DNSdnstest intmain Testing Google Public DNSdnstest reddit outlier Testing Google Public DNSdnstest reddit Testing Google Public DNSdnstest tb4fr Testing Google Public DNSdnstest bbccouk Testing Google Public DNS


Paul Eggert speaks at UCLALUG

No Comments »

Sorry for this being a little late, but Paul Eggert came and spoke to the UCLA LUG and interested parties this past Wednesday.

Eggert spoke about several things, including how he became involved with free software, his take on the free software community, how to get involved in free software, and projects he thinks would be great to have done.

Eggert mostly became involved with free software as a result of what he calls laziness. Essentially, he got tired of re-patching emacs to work on his (unusual) architecture, so he started submitting patches to Stallman. From there, he just continued submitting patches.

Similarly, Eggert thinks that the best way to get involved in free software is to just start contributing. In order to get noticed, he recommends that people pick “medium-sized” patches; not something small enough that another person could do in 15 minutes, but also not large enough that it makes any major changes. An example of a “medium-sized” project would be patching to take advantage of multi-core systems. Since most programs currently are designed with a single-core architecture in mind, some significant improvements in speed could be obtained by moving it to multi-core. Doing something like this would help to build one’s reputation in the meritocracy of the free software community.

In terms of the future, Eggert thinks that we need new languages to properly take advantage of multi-core. In particular, he mentioned projects like Hadoop are steps in the right direction. Additionally, he thinks that the current shell is too complicated for non-trivial tasks.

Anyway, happy halloween!


Paul Eggert is coming to UCLALUG!

No Comments »

The below information is from the UCLA Linux Users Group.

All Engineering students — particularly those in CS — are invited to hear
Professor Paul Eggert speak on Open Source software, how he got involved over
his career, how he has contributed. The GNU Core Utilities project includes
such all-important programs as “ls”, “cp”, “sort”, “echo”, “cat”, and many more.

Wednesday, October 28, 2009
6 PM
Boelter Hall 4760
Details: http://linux.ucla.edu/sean/eggertflyer.pdf

Paul Eggert is a lecturer in the Computer Science department here at UCLA. He
teaches operating systems, programming languages, software development, and
more.


A .vimrc Discussion

No Comments »

So, I’ve recently converted to using VIm. Textedit irritates me to no end, and I don’t want to pay money for Textmate. I decided I would post my .vimrc file up here and talk about it a little bit. For those who just want to read the file, it’s attached at the bottom of the post. Snippets of code follow, however.

map <space> /

All you VIm users out there know how to search for text – this enables me to search with the space bar, which feels more natural and quicker than having to type a special character.

set nocompatible
set number
set columns=80
set ruler
set background=light
set wrap!
syntax enable

This turns off emulation of bugs from Vi, enables line numbers, restricts my window to 80 columns, displays some basic information about where I am on a line, tells VIm to use fonts optimized for a light background (corresponds with my terminal colors), turns off word wrap, and turns on syntax highlighting. These options are all configured for programming.

set showmatch
set ignorecase
set hlsearch
set incsearch

This is extremely useful for searching in a file. The first line highlights matching braces, which is very nice for nested statements and complex conditionals. It also makes searching case-insensitive, highlights search matches, and starts searching with the first letter that you type. If you pay close attention when searching you only ever have to type the minimum amount of letters to find what you want. I find this greatly speeds up moving through a document.

set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab

These settings tell VIm what to do with tabs and indents. The first two lines tell the program to format indents according to the file type. As long as you’re using a C type language, this works extremely well. The second two lines tell VIm to use 4 spaces when the tab key is pressed, and the final line expands all tabs into spaces. This helps remove compatibility problems between tabs and spaces.

set vb t_vb=

This just turns off those pesky beeps when you enter an invalid command. Instead, the screen flashes for an instant. Much nicer in my opinion.

set gfn=BitStream\ Vera\ Sans\ Mono:h14

This sets the default font for the editor – Monaco Size 10. My current favorite programming font on OS X. Anyway, that’s a bit of a discussion about my .vimrc. The full file is below for anyone who wants to read the whole thing or copy/paste it for their own use.

".vimrc
"Author: Eric Hertz
"Date: 10.14.2009
"
"This is a configuration file for VIm, the terminal text editor. Feel free
"to use this however you wish.
 
"Key mappings
map <space>  /
 
"Interface settings
set nocompatible
set number
set columns=80
set ruler
set background=light
set wrap!
syntax enable
 
"Search settings
set showmatch
set ignorecase
set hlsearch
set incsearch
 
"Indent settings
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
 
"Audio settings
set vb t_vb=
 
"Font settings
set gfn=BitStream\ Vera\ Sans\ Mono:h14

Automating Calculations in Physics 4AL

No Comments »

This isn’t really related directly to anything of importance in terms of CS, but it does relate a fundamental difference in those who program versus those who do not. My suitemate and I are both taking Physics 4AL this quarter, a lab which requires a large amount of calculation. However, it is the same calculation with different masses over and over. Last night, I was fed up with putting it in my calculator over and over again, so I wrote a little program. Presented below is this little program, which calculates the error σ = √( ((mg/(M+m)²)²*&sigma²) + ((M/(M+m)²)²*σ²) ).

:Prompt M
:Prompt W
:0.0001→S
:9.8→G
:((((W*G)/(M+W)
²)²*)+(((((M+W
)*G)-(W*G))/(M+W
)²)²*))→X
:Disp "SIGMA",X

Howdy!

No Comments »

Hi there!  My name is Sam and I’ll be your host tonight…

No, really.  My friend Eric and I conceived of a place where we could talk about issues and challenges faced by today’s Computer Science students.  Accordingly, int main() is a place to do that.  Over the coming weeks, months, years (or however long we’re kept interested), we’ll be talking about this junk.

If you are interested in writing here, send us a quick email!

As for a little background: the two of us  are entering our second year as Computer Science students at UCLA who have very much enjoyed the curriculum.  I will not be taking any CS classes this quarter; Eric will be taking one.

Other contributing authors may include David Wieser, Hugo Fuentes (Senior at UC Davis), and Vyvy Dao.

Anywho, now you know.  Happy coding.