Tuesday, December 18, 2012

Worlds Cheapest Git Server Pt. 2


Here it is!  To install git, run "apt-get install git" (while online of course, which for me meant hooking up ethernet cables and a television at the local library).  "Wheezy" is the raspberry pi ported version of Debian, which has ssh pre-installed (although with strange defaults that I haven't worked through - it doesn't quite do keyphrases as expected right now).

Wheezy also comes with Scratch (an educational programming system for children) - worth checking out.

After setting up accounts, permissions and repositories, and Git Extensions on my Windows machine, and git-scm for Mac http://git-scm.com/download/mac, and turning on meta-files in Unity and following the other Unity documentation, it works!  Hurray!

[Somewhere in the process git asked if I wanted Windows-Unix line-terminator conversions, which I answered "no conversion" and that seems to work fine so far.]

Also, not only does it work - it works well.  There's some latency when checking out a 500MB repository for the first time, but it isn't bad.  I will have to put some mileage to see about making minor code changes and checkin/checkout waits.

The other downside - if the house burns down, so does the git server!  So it's either make a fire-proof housing for the server, or store it off-site when not in use.



Total cost:
Raspberry pi (Newark): $35
(but look at my previous post and you might get a better coupon price before January 30th or so)

Power Supply (Newark): $7

Newark shipping: $10

SanDisk 32GB SD-card (Newegg): $35 + free shipping
http://www.newegg.com/Product/Product.aspx?Item=9SIA12K0AT5024

Total: $52


Optional (really could have lived without this, since can use any t.v. screen, and after ifconfig to get IP address, just ssh remotely for setting up):

HDMI to DVI cable (Newegg): $7 + free shipping
http://www.newegg.com/Product/Product.aspx?Item=N82E16812576006






Also - to do a git push, you have to set up a git bare repository on the server.  Something like this:

pi@raspberry ~ mkdir myRepoDir

pi@raspberry ~ cd myRepoDir

pi@raspberry ~ git init --bare

Now from your client you can push to ssh://pi@192.168.0.100/~/myRepoDir (or whatever the IP of the raspberry is), and the repository is set up.  Now any other machine can pull from ssh://pi@192.168.0.100/~/myRepoDir.



Thursday, November 8, 2012

Worlds cheapest Git server

Yesterday I looked at Git.  This is a version control written by Linus Torvalds, and I'm not going to pretend I'm an expert.  However, github (https://github.com/) seems to be the favored place for open-source repositories.

Great!  What if I want to keep my code private?  Github allows private repositories for $7/month.

This might be a competitive price to Amazon Web Services (http://aws.amazon.com/) - although for the CPU bandwidth, it's more cost-effective to build a machine from scratch (I'm assuming their prices haven't gone down significantly since I last tried them about a year ago).  It's certainly competitive to Linodes which go for $19/mo and up.

So how cheap can you build a PC for nowadays?

If you're not in ANY hurry - take a look at the quite awesome Raspberry Pi:

http://www.alliedelec.com/lp/120626raso/

Turnaround is months from placing the order, unfortunately.

You'll need a power supply and SD Card - which will run a total cost under $60.  For small projects that you want to keep private and quickly set up a git server, this looks like the right way to go.  There are also rumors of an Android build for Raspberry Pi, and those GPIO lines... something about them calls out "make something!"

Sunday, October 28, 2012

Reading the PHP manual...

Today I decided to read as much of the PHP manual as I could.  While working through examples, multiple times the thought "coding horror" came to mind.  But I can't afford to be that kind of snob can I?


I finally hit a language "feature" where variable names can be created by other variables.  They are called "Variable variables".  So if a script assigns a string to a variable $a:

$a = "horrifying";

that string can become the name of another variable:

$$a = $a." is as ".$a." does.";

It can be referenced as ${$a}.  Or it can be referenced as $horrifying.


Did I mention coding horrors?  Can anyone explain a legitimate use of such a construct?  What drove the language to put it in there in the first place?

This language feature reminds me of the first assembly language code I wrote in High School, on a Sharp PC-1500 Hand-held Computer.  [I had to use POKE commands to enter the ASM code in by hand - there wasn't any assembler.]  What was cool was that the code was self-modifying!  It wrote to a relative address in the code itself to increment a comparison, and change the minimum pitch of an oscillating tone.  At the time, I didn't know that self-modifying code was a bad idea.  It was just pretty cool how it all worked to make a wah-wah- gaming sort of sound.  And I could brag about it to whoever understood what I was talking about.


So web-searching for "coding horror PHP" yields no shortage of blogs complaining about how bad a language PHP is.

My theory at the moment, is that this is fine.  Really bad code can continue to be generated, and there is no shortage of enthusiastic 14 year old's out there to wade through it all.  For the price of 1 experienced engineer, you can hire 10 teenagers instead.  They won't know why the above example is a bad idea - they'll think it's really cool.

This gives me great pause at considering any work prospects involving PHP coding.  As a good friend of mine once advised: 

"Always read the whole prospectus before making any investment."

Friday, October 12, 2012

Parrot Engineering

Last night I finally got a Maqetta website to run on the App Engine launcher.  For most new development stuff, there are several blogs and youtube tutorials on how to use the stuff.  Not so for Maqetta.  I was beginning to wonder if I could pull it off in the next few days or I'd actually have to RTFM - if there even are such manuals.

Maqetta's website has tutorials.  They go as far as showing how to use the tool, and assume the developer is stuff is something you already know.

App Engine - almost the same story.  I've gone through their tutorials, but still wasn't clear on the how these tools really work with each other.


Luckily one of the Google tutorial videos "Google I/O 2012 - HTML5 and App Engine: The Epic Tag Team Take on Modern Web Apps at Scale" also includes a Github link.

http://www.youtube.com/watch?v=v9TG7OzsZqQ


https://github.com/greenido

Downloading his code, and comparing with my files, eventually yields an app.yaml file that looks like:

application: heyworld
version: 1
runtime: python27
api_version: 1
threadsafe: yes

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: /images
  static_dir: images

- url: /lib
  static_dir: lib

- url: /static
  static_dir: static

- url: /themes
  static_dir: themes

- url: /samples
  static_dir: samples

- url: /stylesheets
  static_dir: stylesheets

- url: /
#  script: main.app
  static_files: file1.html
  upload: file1.html


libraries:
- name: webapp2
  version: "2.5.1"

#- url: .*
#  script: main.app
#


Where all the Maqetta directories that contain Dojo libraries, etc, are specified.  The downside to this, is you can enter directories and it serves up all of their files - not very clean.  I'm not sure there's any workaround for that problem, as app.yaml seems to work like a file system directory for the whole site - if it doesn't show a directory, none of the scripts seem to have a way to get to those directories.  [Yes?  No?  Anyone?  Please leave comments clarifying if you know!  Thanks!]

I call this "parrot engineering".  Not a proud badge - but if it gets the job done, do it.  If I can't find the answer on youtube or google, or by looking at a website's source code, Github seems to be another great source.


Wednesday, October 10, 2012

The Three Motivators


There were 3 warriors who needed to cross a great desert on horseback.  Nobody had ever crossed that desert and lived to tell about it.

Not only was the desert hot and dry, it was on fire.  Clouds of black smoke blocked all view, and obscured the sun overhead.

But there was no other way.

So the first warrior set off.  After 2 days his horse was starting to show fatigue.  But the warrior had seen many battles, he had commanded armies, he knew something about survival.  He dismounted and looked his horse in the face.  "We'll die here if you give up.  You can't get tired now.  Keep going!"

After 2 more days the horse had collapsed.  The warrior found his way, but not without a great loss.


The second warrior went through similar circumstances, but rather than talking about death - he tried feeding his horse treats, and entertaining him by telling a wide variety of "a horse walks into a bar" jokes.

"So, why the long face?"

Same outcome as the first warrior - the horse eventually collapsed.



Now what did the 3rd warrior do?  He and his horse made it through alive.  How?

This warrior first of all had keen control of his senses.  This came with training - he didn't just read a story or a book and learn that control.  It took practice and a transformation of his conditioned mind into an awareness of the most subtle cues.

As a result, the warrior knew when he was acting out of compulsion and fear and when he was acting fluidly.  He made no distinction between himself and the horse, or himself and the desert.  The horse was also aware the warrior had no fear.  Not as a contrivance "no fear", like what you might see on a bumper-sticker.  "No fear" doesn't describe it positively.  "All clarity" would be more accurate.  The warrior was "all clarity" and the horse could see that.

So when the horse was beginning to show fatigue, the warrior also dismounted, and looked his horse in the face.  "I have seen a vision of our arrival - and they are waiting for us with great anticipation!  Today, we will not die!"  The warrior's face was completely radiant!  This was because he really had seen such a vision.


The affect on the horse was an invigoration - a perfect dissolution of fatigue.  He was completely renewed, and continued through the desert refreshed.  Such refreshment, when moments before he had been so tired, how can this be?



The 2 motivators commonly talked about are "fear" and "greed".  But both of them, in whatever form they take, are really forms of harassment, and not based in true Authority.  They are two demons, that drive common people mad chasing this way and that, both tormenting themselves and others.

Don't do that.


The 3rd motivator is like "Soul".  It is much more subtle, and sometimes seems miraculous!  Performance is maximized in such a place.  The body relaxes without fear, and the blood vessels aren't constricted by tension.  Everything flows.  It isn't a question of "how can we motivate you?"

It's a selfless, pure, abiding in love.

And isn't that why we are all here?  Because deep down, we really love what we do?  Why would anyone resort to any smaller Vision than such an abiding?


Monday, September 24, 2012

Call for Android testers

Pre-Alpha Unity build for Android.

Ship shoots on a timer.  Touch the screen and ship follows your finger.  My high score is 200,000.

Feel free to try it.  Please let me know your results, heap size, etc.


http://tinyurl.com/cuwjmuk

Copyright 2012 Frank Braker

DIRECTIONS:

Download file from your Android phone.  Click on "Downloads" and click the 
downloaded file - it will ask if you want to install "SpaceWithText".  Install it and run.

This is a 3D test and AI demonstration.  It might not run on all Android phones.

Spawning cubes show their current behavior, which is driven by a behavior tree.

Saturday, September 15, 2012

Running an android app on the emulator


$ ./emulator.exe -avd dodo

Javabrain@ShinyGrand /cygdrive/c/Users/Javabrain/AppData/Local/Android/android-sdk/tools
$ cp /cygdrive/c/Users/Javabrain/Downloads/airnow.apk .

Javabrain@ShinyGrand /cygdrive/c/Users/Javabrain/AppData/Local/Android/android-sdk/tools
$ ./emulator.exe -avd dodo &
[1] 6412

Javabrain@ShinyGrand /cygdrive/c/Users/Javabrain/AppData/Local/Android/android-sdk/tools
$ adb install airnow.apk
        pkg: /data/local/tmp/airnow.apk
Success
683 KB/s (141336 bytes in 0.202s)

Javabrain@ShinyGrand /cygdrive/c/Users/Javabrain/AppData/Local/Android/android-sdk/tools
$


Thursday, September 13, 2012

Patterns and Rules

Here's a good link:

http://www.gamasutra.com/view/feature/132649/the_case_for_game_design_patterns.php?print=1


While the author is talking about "Game Design Patterns", it brings up a progression of Design Pattern discussion:

http://www.slideshare.net/JoshuaKerievsky/a-timeless-way-of-communicating-alexandrian-pattern-languages

Perhaps most well known among software engineers is the "Gang of Four" Design Patterns book.  Whenever I've heard the term "patterns", I've assumed this was the usage.  Not true!  Design Patterns seem to have originated in architecture, with applications in gardening, theme park design - not just software.

The progression for game design continues to "The 400 Project", which is deliberately a list of "rules" rather than patterns, as discussed in the GDC presentations:

http://www.finitearts.com/Pages/400page.html


This is all fine.  It provides a great framework and vocabulary for discussion.  These are recipe books in architectural and experiential domains.


[Edit:  What I'm wondering now, is how to put wieners, rocks, paper and scissors to good use!]

[Edit: For GoF patterns, this also looks like a good discussion: http://www.oodesign.com ]

Tuesday, August 14, 2012

Behavior Trees

The general design in Unity is to write multiple behavior scripts, and attach them to a game object.  For example, a "rotate" script and a "shoot-at-anything-that-gets-close" script are attached to an object separately, rather than combining all behaviors into one script.

I like this approach - until an object needs to only apply behaviors selectively.  At that point I realized a finite state machine (FSM) was probably the way to go.  If an object had several scripts attached to it, there would need to be an FSM script which messaged all the other scripts so they knew what state the object was in.  Ugly.

Fine - ask Dr. Google.

People are still using FSMs out there - but the new glorious technology now seems to be Behavior Trees (BT).

I'm just beginning to teach myself about this tool.  There is some comparison between BT and hierarchical finite state machines (HFSM) - the latter which I have no experience with.

An FSM will go from state to state with transition events, and have the capacity to become a fascinating conversation piece among the more super-genius programmers spaghetti nightmare.  Even very simple FSMs can be painful to look at.

BT appears to remove some of the FSM free-form.  They seem to provide a framework of limited logic-flow.  It makes me wonder if eventually processors will be optimized around BT - because it looks like a sort of graphical programming language.  More importantly, it looks like a new way of thinking and building engines.

Here is the best summary page I've found so far (and an excellent blog overall on the subject):

http://aigamedev.com/open/articles/popular-behavior-tree-design/


Thursday, April 19, 2012

Browser Sandboxing

"Dad?  What's the safest way to browse the internet?"

"Oh.. borrow your friend's PC.  After you finish browsing, ask them to re-install everything.  Do this every day."


Have you ever wished you had a friend who was this kind?


Here's how.  Please take a close look at this screenshot:





This screenshot was taken from Windows Vista (see the tab at the bottom), running VirtualBox, which is running Linux Mint 12, which has Firefox browsing webpages and AdBlock Pro installed.
It is not the fastest way to browse the web.  But it is the safest.


Why would you want to do this?

The advantage to running a virtual machine (VirtualBox, VMWare, there are many to choose from) - is that it sandboxes whatever applications are running on the machine.  It's easy to take a snapshot of the machine's state and revert to that snapshot later.

Can't you do that in Windows?  Yes.  Sort of.  Windows has System Restore - but it has it's problems.

Windows System Restore automatically creates restore points, that allows reverting the state of executable files.  There are many details of System Restore I won't go into - nor claim to know anything about.  What's important is - it's all automatic.  If you wait a month or two, old restore points will be overwritten with newer restore points.

If you inadvertently install malware, if it isn't detected before an old enough restore point is overwritten, the only mechanism for removing the virus is an AntiVirus (AV) program, or manually.  So you're at the mercy of AV and websites to keep your browsing safe.

Also, System Restore is a time consuming process.  You might not want to spend 10 minutes every day restoring your system to a restore point.  With VirtualBox, restore points snapshots can be restored relatively quickly, depending on the size of the virtual machine.  I've got Linux Mint set up on a small, 8GB drive, so snapshots take about 15 seconds to save and restore.


My Horror Story

Last week I was getting ready to do my taxes on my laptop, when, browsing to yahoo.com to check e-mail, the website returned with "Welcome to nginx!".  After looking into this problem for several hours, it became clear that:

1) no antivirus program website says anything about "Welcome to nginx!"

2) the anti-spamware program I was using didn't find all the cookies that another program found

3) the process for fixing "Welcome to nginx!" involved posting log output onto a forum and waiting for experts to respond with recommendations

4) "Welcome to nginx!" issues have been showing up for several years now, with apparently many different causes


Number 3 killed me.  I didn't have several weeks to figure out what was wrong with my laptop - I needed to go forward with my taxes right away.  And doing my taxes on a potentially infected machine was not an option.

 Time to format the hard-drive and re-install the whole laptop from the ground up!

I suppose I could have relied on System Restore - but even if I reverted to the oldest restore point, there was no way to know if my system would be clean, because the source of the problem couldn't be found.


Using VirtualBox as a Sandboxed Browser

At this point it became clear that I would always be at the mercy of someone else to keep my system clean.  Websites have to be free of malware.  Antivirus programs have to stay up to date.  It's an endless cycle of malware development and anti-malware response.

The source of all malware is almost always the internet.  The only alternative is someone giving you a CD/DVD/USB disk that is infected.


So why not uninstall the browser from the main OS?  This is exactly what running the browser exclusively on a virtual machine allows you to do.  For most browsing it does the job quite adequately.


Do It Yourself Steps

Here's how:

- Download VirtualBox (or whatever virtual machine you like best).  [If you like another virtual machine better - please tell me and I might switch.]

https://www.virtualbox.org/wiki/Downloads

- Download Linux Mint (or whatever OS you like best).  [I like Linux Mint because it's free, and it comes with Flash Player, and websites like youtube and vimeo work fine.]
  Download the iso image, which VirtualBox can open just as if it was an installation CD/DVD.  You can also burn the iso image to a CD if you like - but it isn't required.

http://www.linuxmint.com/download.php (DVD, 32-bit - or try the others)


- Create a virtual machine in VirtualBox, set it up as recommended (1024MB RAM might be overkill, but it's what I'm using, and an 8GB disk, although smaller might reduce snapshot saving/recovering).

- Run the virtual machine in VirtualBox.  This will bring up the first boot wizard and you can select the Linux Mint ISO file as a boot in the browse folder button.  This is identical to booting a machine from a CD.  Linux Mint should come up (it may require you to create a user account before logging in - just follow the steps).

- Install Linux Mint onto the virtual machine.  Once the OS is up, you'll be tempted to run various apps - go ahead.  But it's still running like an OS from a CD.  The Install To Harddrive should be right there on the desktop which will start the process of installation.  Run this.  Answer all the questions.  Wait for it to install, which takes about 20 minutes or longer.  After the install is finished and Linux has booted up from the hard-drive,  you can add the Guest Additions

- Install Guest Additions and a File Share.  If you want to transfer files between your main OS and the virtual machine, install the guest additions from VirtualBox (not from Linux) - it's in the Devices pull down menu.  It will start an app and it might complain "are you sure?" - type "yes" and hit return.  When this has finished, you should be able to create a file share from VirtualBox as part of the virtual machine's settings.  [If you took any machine snapshots before this, it may complain that the machine is not mutable and can't add a share, so do this before taking any snapshots.]

 I created a file share called VirtualBoxShare.  At this point, I could open a terminal (UXTERM or some such) and type "su" to log in as superuser, then type "ls /media" and sf_VirtualBoxShare shows up in the list.

- Mount the file share.  This is optional.  As superuser, you can transfer files around, but if you want access from the regular account, log in as su, and type "mount -t vboxsf VirtualBoxShare /home/<your username>/ShareDir" where you replace ShareDir with whatever directory you want, and <your username> with whatever your username is.  If this doesn't work, try just typing "mount" to see all the mounts available and find the file share that VirtualBox created in the previous step.  "chmod 777 /home/<your username>/ShareDir" or "chmod 777 /media/sf_VirtualBoxShare" might help too...


Bask In the Boundless Safety of Sandboxed Browsing

That's it.  From there it was easy to take a screenshot from Windows, paste it into Paint, and save the file into the VirtualBoxShare directory I had set up on VirtualBox, then open Firefox from Linux Mint, log into blogger.com and post that picture by selecting it from ShareDir - the directory I had mounted.

[And at this point, there's really no more need for any browser in Windows.  All file downloading can take place in the virtual machine, and files saved in the file share if you want to run them from Windows.]


Don't forget to take a snapshot of the disk image.  Then upon closing the virtual machine, restore to the snapshot.  Any malware that might infect the machine after taking a snapshot is wiped out in the few seconds it takes to restore to the snapshot.