Friday, December 12, 2008

Connecting to OS X from Linux

I'm done school for the semester, so hopefully that means I'll have some more time to work on programming and the like. Yesterday I was trying to get my Ubuntu laptop to connect to my Mac OS X desktop. Accessing a networked OS X computer as a windows share is pretty easy under Ubuntu. But you can only see a few files. When networking OS X to OS X you can access pretty much the whole computer. I found a package called afpfs-ng that allows you to do essentially the same thing from Ubuntu. Unfortunately this program requires you to use the command line to connect. Once I figured it out I started making my own GUI interface for afpfs-ng. I used python and am just about finished. Here's the source code so far:

#!/usr/bin/python

import Tkinter
import subprocess
import os.path



# Define input retrieve function for application input
def retrieve_text():
global volume
global mounted
if mounted is 0:
afp_ip = afp_host.get()
username = user_name.get()
volume = volume_in.get()
password = pass_word.get()
if os.path.exists('\"/tmp/'+volume+"\"") != 1:
output_string = "mkdir \"/tmp/" + volume + "\""
retcode = subprocess.Popen(output_string, shell=True)
output_string = "mount_afp \"afp://" + username + ":" + password + "@" + afp_ip + "/" + volume + "\" \"/tmp/" + volume + "\"\n nautilus \"/tmp/" + volume + "\""
retcode = subprocess.Popen(output_string, shell=True)
mounted = 1

def unmount():
global mounted
if mounted is 1:
retcode = subprocess.Popen("afp_client unmount \"/tmp/" + volume + "\"", shell=True)
mounted = 0

if __name__ == "__main__":

volume = 0
mounted = 0

# Create Window Object or Window Form
app_win = Tkinter.Tk()

# Create label object
labeltitle = Tkinter.Label(app_win,text="Connect to AFP Server\n")
labeltitle.pack()

# Create label object
label1 = Tkinter.Label(app_win,text="Host IP")
label1.pack()

# Create User Input Object
afp_host = Tkinter.Entry(app_win)
afp_host.pack()

# Create label object
label2 = Tkinter.Label(app_win,text="Username")
label2.pack()

# Create User Input Object
user_name = Tkinter.Entry(app_win)
user_name.pack()

# Create label object
label2a = Tkinter.Label(app_win,text="Password")
label2a.pack()

# Create User Input Object
pass_word = Tkinter.Entry(app_win)
pass_word.pack()

# Create label object
label3 = Tkinter.Label(app_win,text="Volume")
label3.pack()

# Create User Input Object
volume_in = Tkinter.Entry(app_win)
volume_in.pack()

# Create Button Object
app_button = Tkinter.Button(app_win,text="Connect",command=retrieve_text)
app_button.pack()

# Create Button Object
unmount_button = Tkinter.Button(app_win,text="Unmount",command=unmount)
unmount_button.pack()

# Initialize Graphical Loop
app_win.mainloop()


If you copy that into an empty text document, save it as "afp.py", open a terminal, type "python " and then drag the "afp.py" file into the terminal, you can run it. Of course, you'll have to download afpfs-ng first. Your command line should look something like this:
dustin@dustin:~$ python '/home/dustin/afp.py'

I'm still working on adding some more features and packaging this in an easier to use manner.

Friday, October 17, 2008

Pythons

I just wanted to mention two interesting python libraries I have recently discovered:
1. Pyglet
This seems to be replacing pygame as the best choice for making games in python. It uses OpenGL instead of SDL, which means faster games!

2. Pymunk
A port of the Chipmunk 2d physics engine to python. A recent PyWeek contest was based on the use of Chipmunk in python games.

I haven't yet tried either of these myself, but they look very useful. I'll keep you posted.

Thursday, October 2, 2008

7 Ubuntu Tweaks and Hints

Download Restricted Formats
By default Ubuntu does not come equipped with the ability to playback the most popular audio/video codecs. This means that you won't be able to listen to your mp3's or play your DVDs. Fortunately this can be solved fairly easily by downloading the Restricted Formats package:
1. Go to Applications->Add/Remove...
2. Change the 'Show' option to 'All available applications'
3. Search for 'ubuntu-restricted-extras' and install it by checking the box next to it and clicking 'Apply Changes'
More info on Restricted Formats can be found
here.


Download AWN Manager
Avant Window Navigator is a clone of the OS X dock for Linux. It provides easy access to your favourite applications from one convenient location. To download:
1. Open Synaptic Package Manager (System->Administration->Synaptic Package Manager)
2. Search for 'awn manager'
3. Right click the 'awn-manager' package and select 'Mark for Instillation'
4. Click 'Apply'
5. Once AWN is installed it should open automatically each time you start your computer. To launch it the first time however you will have to open it from Applications->Accessories->Avant Window Navigator. You can change your settings by going to System->Preferences->Awn manager.


Get The Gimp
The Gimp or GNU Image Manipulation Program is an open source program akin to Photoshop. Download it using Add/Remove... and searching for 'gimp'.

Enable ALSA
For some reason Ubuntu doesn't like multiple applications playing sound at once. Trying to do this may simply result in no sound from one program or might cause the entire application to crash. Fortunately this can be solved quite simple by going to 'Sound Preferences' in System->Preferences and changing all the sound devices to "ALSA - Advanced Linux Sound Architecture."


Test and Fix Suspend/Hibernate
Ubuntu offers two methods of putting your computer to sleep for power saving purposes. Suspend saves the system state to your RAM and puts the machine into low-power mode. Hibernate saves the system state to the hard drive and shuts the computer down completely. Unfortunately both of these options do not work on many computers. Go ahead and give both a try. If you encounter problems you will want to try to use uswsusp instead. Compared to the tweaks I have mentioned so far this task is fairly involved. Rather than walking you all the way through it I am going to direct you to another blog for details. Please be aware that trying to fix this can turn out to be quite a headache and may require additional google searches. A look at the aforementioned blog is likely to fix your Hibernate function, however, and is thus worthwhile. As of yet I haven't had any luck fixing Suspend on my own machine.

Remember the Ctrl+Alt Combos
Although Ctrl+Alt+Delete doesn't do anything in Ubuntu there are several Ctrl+Alt combos that will come in handy.
Ctrl+Alt+(F1-F6) will take you out of the GUI into a terminal at any time. This can be useful if one program is causing your entire system to freeze up. Simply switch over to a terminal and type 'kill (application name)' and then flip back to the GUI to continue whatever it is you were doing.
Ctrl+Alt+F7 will bring you back to X (the GUI).
Ctrl+Alt+Backspace will restart X. If you're having trouble killing an unresponsive program this gives you the option to restart X, which should solve the problem much quicker than a normal restart would.

Other Important Software
Download these open-source programs by searching for them in Synaptic Package Manager:
Bluefish Editor - I'm sure there are other good code editors out there, but this one has served me well and I highly recommend it.
Freeciv - A google search for the best game for Linux yielded Freeciv as the result. It's basically an open-source Civilizations.
Audacity - A good tool for editing audio.
Wine - A Windows emulator. Allows you to run some Windows programs in Linux (although I'm not sure why you'd want to).

Monday, September 15, 2008

Ubuntu really is Linux for Human Beings

For years I have been a strong advocate of Apple and it's Macintosh operating system. The biggest reason for this is that I flat out hate Windows (and Microsoft in general). OS X seemed like the only viable alternative, and I found it to be far superior. Of course, I also knew that there was also this little, relatively unknown, OS know as Linux; but I never bothered to actually try it.
This summer I officially made the jump and installed Ubuntu Linux on a laptop a friend gave to me. And boy was I surprised. I've always thought of Linux as the geek's OS, but I quickly discovered that it can give both Windows and Mac a run for their money when it comes to ease of use. If you're interested in trying it out head on over to the Ubuntu website. Download a LiveCD or request that they mail you a free copy. Plop it in your disc drive and give Linux a test drive without ever having to actually install the OS. Once you've decided to permanently install it on your hard drive, stay tuned to my blog where I will soon be making a list of my favourite Ubuntu tweaks.

uDevGames

My favourite game development community, http://www.idevgames.com/, is going to be running a contest. In the past they ran a competition known as uDevGames which was probably the biggest contest in the OS X development community. It's been a few years since it has run, but it's looking to make a strong return in the near future! Check out this thread for more info.

Thursday, July 17, 2008

3D Games

If you're looking to make 3D games on a Mac there is no better tool than Unity. It's easy to use, with a great GUI and all the scripting done in the familiar javascript. You can use it to build games for OS X and Windows. There are also plans to make Wii and iPhone builds possible. It costs $200 to buy the indie licence, but even if you can't afford that it is worth checking out the free 30-day trial. If you need a free alternative Dim3 is a popular open-source 3D engine. My own experience with it is fairly limited but, while it is certainly not as easy or powerful as Unity, it looks to have some potential and is certainly worth looking in to.

Saturday, June 7, 2008

PyGame

At some point you will run into the limits of web technologies and GameMaker and you will need to learn another language. Python is an excellent next step. Pygame is a module for python that will allow you to easily import and use sprites in your games. Check it out at http://www.pygame.org/. Once you've downloaded and installed Python and Pygame I recommend that you get started by looking at the Chimp Tutorial. You will also want a good code editor to work in. I'm on a Mac and I highly recommend Aquamacs Emacs. Please note that programming with something like Python is a little more complicated since there is no GUI, but if you're used to using something like PHP or GameMaker code, you should be able to figure it out without too much difficulty.

Tuesday, May 20, 2008

Making a DIV 100% of the Document Height

A friend told me that IE 8 is supposed to be fully compliant with CSS. I went to test a website on Browsershots the other day and discovered that it didn't work in IE 7 or 8. So much for compliance. The problem I have is that the height of my main div is set to 100% but it only goes part way down the page and then ends while its content continues. Its a bit difficult to explain so hopefully it will make more sense if you look at the image on the left.
The white background is supposed to go to the end of the page, since all of the other page elements are enclosed in it.

The Solution
I couldn't find a way to fix this problem using CSS/HTML alone. Instead I had to use a piece of javascript to resize the div to the actual height of the page.

<script type="text/javascript">
function resize()
{
document.getElementById('maindiv').style.height =
document.body.parentNode.scrollHeight + 'px';
}
</script>

Just let your body tag know that it should run the resize function onload and the result in IE 7 and 8 is as follows:

Saturday, April 26, 2008

Jumping in Head First - Making Your Own Computer Games

In my last post I suggested that web design is the ideal way to get your feet wet in the ocean of computer programming. Some of you have been there and done that. Others just want to dive right into the world of game making. One of my favourite game creation tools is Game Maker. I love it because it is fairly simple to use if you are new to this type of thing. It has a drag and drop interface that doesn't require you to type a single line of code. Once you master that you can begin to use the advanced features including coding with the well documented GML (Game Maker Language).

Thursday, April 24, 2008

First Steps - Creating Web Sites

Getting started with computer programming can be a challenge. Where is the best place to start? Designing websites is an easy way to see quick results for your efforts. The most basic way to get started with web design is to use a WYSIWYG (What You See Is What You Get) web editor. Dreamweaver is the champion of this type of software. For the amateur who is just beginning the open source NVU should do fine. However, I highly recommend that you learn to create your own websites using only a text editor and html, javascript, and php. The most difficult part of learning to design web pages will be finding the right sites to learn from.

Learn HTML - DaveSite.com
I highly recommend using DaveSite.com for an HTML tutorial because it assumes no prior knowledge and emphasizes practical application.

Learn CSS - DaveSite.com
CSS is an important part of defining the layout of your web page. To find out more about CSS and how to use it use Dave's tutorial. Visit the W3Schools website for more tutorial and a handy reference guide.

Learn Javascript - Thau's Javascript Tutorial
Thau's Javascript Tutorial on Webmonkey.com was by far the best Javascript tutorial I could find. Once you've completed it you can move on to the Advanced Javascript Tutorial.

Learn PHP - PHP From the Ground Up
By now we are getting into designing more advanced websites. Many websites will not require PHP or another server side language. If you feel limited by the capabilities of html and javascript then it's time to check out this tutorial.