Subscribe RSS

Archive for the Category "Tutorials"

How to tether HTC Hero on debian linux Jan 14

1) Connect a cable
2) Applications -> Settings -> Wireless controls -> Mobile network sharing
3) ifconfig -a and you will see the phone appear as a network connection with
4) sudo ifcofng usb0 up
5) sudo dhclient usb0
6) Surf away!

Ive seen idiots faffing around with openVPN rooting their phones and arsing about with the android sdk to do something that works out of the box. -.-’

It’ll work on most distros it depends only on the rndis_host and the rndis_wlan modules.

And yes this post was made through my eeepc tethered to my mobile.

Enjoy!

Creating Thumbnails with imagemagick Dec 31
thumbnails with imagemagick

thumbnails with imagemagick

So you want little square thumbnails like Flickr. Here is a bash script that uses imagemagick to generate square thumbnails.


makethumb:

#!/bin/bash
#
# makethumb
#
# A bash script to generate square thumbnails using imagemagick.
#
# Feel free to use and abuse, its just a script. Requires imagemagick!
# See www.websurfshack.net for more stuff like this
#

if [ "$1" = "" ]; then
echo "Usage: makethumb source_file [size] [output file]"
echo ""
echo "e.g."
echo " makethumb large.jpg"
echo " makethumb large.jpg 65"
echo " makethumb large.jpg 45 thumb.jpg"
echo " makethumb large.jpg 25 thumb.gif"
echo ""
echo "Note: You may specify an output file of a different type to the source. The image will be converted automatically to that type."
echo ""
exit
fi

if [ ! -e "$1" ]; then
echo "Input file "$1" not found. Please specify a valid input file!"
exit
fi

ORIG_FILE="$1"

if [ "$2" = "" ]; then
SIZE="45"
else
SIZE="$2"
fi

if [ "$3" = "" ]; then
THUMB_FILE="THUMB_${ORIG_FILE}"
else
THUMB_FILE="$3"
fi

echo "Creating ${SIZE}x${SIZE} thumbnail '${THUMB_FILE}' from source image '${ORIG_FILE}'"

#Grab the image dimensions
WIDTH=`identify -format '%w' ${ORIG_FILE}`
HEIGHT=`identify -format '%h' ${ORIG_FILE}`
echo "Source image is ${WIDTH}x${HEIGHT}"

if [ $WIDTH = $HEIGHT ]; then
echo "Image is already square so just resizing..."
`convert ${ORIG_FILE} -thumbnail "${SIZE}x${SIZE}" -strip ${THUMB_FILE}`
else
if [ $WIDTH -gt $HEIGHT ]; then
echo "Image is landscape"
`convert ${ORIG_FILE} -resize "x${SIZE}" -gravity NorthWest -crop ${SIZE}x${SIZE}+0+0 +repage -strip ${THUMB_FILE}`
fi
if [ $WIDTH -lt $HEIGHT ]; then
echo "Image is portrait"
`convert ${ORIG_FILE} -resize "${SIZE}" -gravity NorthWest -crop ${SIZE}x${SIZE}+0+0 +repage -strip ${THUMB_FILE}`
fi
fi

NEWFILEDATA=`identify ${THUMB_FILE}`
echo "Output file: ${NEWFILEDATA}"
echo "Done!"

Apache Directory Access Control Oct 22

Apache configuration has a Directory directive. It is used like a .htaccess file to control access to said directory.

An example:

Order deny,allow
Deny from all
Allow from my.domain.com

The important bit here is the Order statement. Rules will be processed from right to left (in this case all of the deny rules then all of the allow rules. The LAST rule that is matched will the the rule that is used. We are denying everyone and allowing wo we specify.

If you were to specify allow,deny you will be allowing everyone and denying who you specify.

This is quite a complicated system and some personal experimentation should help you understand.

Category: Apache, Tutorials, Uncategorized  | Tags: ,  | Leave a Comment
Orbital Simulation on the iPhone Sep 15

Ive been playing with the excellent cocos2d iPhone game programming library, with the intention of making some sort of, no-doubt rubbish, game. So far i’ve just been experimenting and I’ve decided to, albeit briefly, write up my learnings as I go.

SimpleOrbitScreen

The simulation running (better in action!)

This article/project covers:

  • Cocos2d
  • Chipmunk collision detection
  • Orbital/gravity physics
  • Particle emitters

Cocos2d: for game mechanics

The cocos2d framework is quite simply amazing. Ricardo Quesada & co have done a excellent job of getting this together. Ive only rubbed off a miniscule amount of its power I suspect. The framework lets you put together a game, easily. It manages game logic (like menus, scenes,  and transitions), game mechanics (sprites, textures, animation, etc) and all manner of other things. This example simply uses the cocos2d framework to help glue everything together. A future post (and research) will(/may!) cover more of cocos2d in further detail.

Chipmunk: for physics collision detection and mechanics

One of the key concepts of the game I have in mind involves a satellite orbiting some planets. The cocos2d library comes with the Chipmunk physics library, so what better place to start. I spent some time playing with this library. It pretty clever and lets you very quickly setup a virtual reality physics environment (in 2d at least). Whilst Chipmunk  provides all manner of  useful stuff, one thing it doesnt really deal with, as far as I can tell, is simulate a ’space’ environment. So I had to look elsewhere for that…

So although not using Chipmunk to model my physics, I do use it to model collision detection (its very good at that) and also I use it for controlling the movement of my shapes around the simulation – it deals with rotation, mass, bounciness, all sorts of goodness.

Maths: for physics!

As I couldn’t make Chipmunk do what I wanted I had to find another solution. It turns out the math for orbital physics is either a) very simple or b) very complicated. I found a simple model which essentially says that the further an object is away from a given object the less effect it has on its velocity vector (direction and speed). So i simply take my object in question – a satellite – and on each step of the simulation work out the effect that all the other bodies have on its velocity vector. I then plug this into the Chipmunk simulation and all is good. You can find all this math goodness in the assessGravity method.

Particle Emitters

Particle emitters are fun and look cool for little work. I use a particle emitter to simulate a fiery tail of my satellite. I dont know why this satellite is on fire, it just is. The emitter used here is based on the one thats in the cocos2d emitter examples. Ive just pulled it out into its own thang. Now I know how to do that I should be able to plug it into other projects…

Try it Yourself

This article is brief, but the code is commented. Download it and give it a go. I’m sure there are better ways to do everything, but this is my first go so be kind! (improvements and recommendations welcome!)

X-Code files here: SimpleOrbit (ive removed the build dir so significantly smaller now!)