How to Run Python Scripts in Windows

To process customer domain creations on BrainHoney I need to run a python script on my Windows machine.  Here are the steps to set it up:

  1. Install Python 3.2 (or another version you'd like to install)
  2. Copy necessary files into C\:Python 32 (these could be images, html pages, anything needed for the script)
  3. Open a command prompt
    • Type "C:\Python32"
    • Type "python [yourscript].py"
    • Follow script prompts if applicable

Eclipse Shortcuts

The more you use Eclipse the more efficient you want to be.  I'm becoming a big fan on keyboard shortcuts and the time they save me.  They make life easier and remove some of the frustration from school projects.  Some.  Here's my favorites. Ctrl+L - List all shortcuts

Ctrl+space - Autocomplete This has increased my ability for program for android apps both in time and functionality.  Hit ctrl+space and it will give you suggestions of what methods you may wants, what parameters to use, and it will auto-import a needed import for the class.

Ctrl+F - Find The traditional find (and replace).

Ctrl+H - Opens search box More than just a find box, this does a ‘find in files’ within the File Search tab. Within here, you can specify what you are looking for in the files, what you file types you want to search in, etc.

Ctrl+Shift+C - Comments a block of code Self-explanatory. Great for debugging.  Huge time-saver for multi-line comments.

Ctrl+D - Delete a line Self-explanatory. I spent the last 2 years doing a Shift-End, Delete or Shift-Home, Delete. What a waste of time!

Ctrl+E - Menu for opened files Brings up a list of opened files.

Ctrl+Shift+F - Auto-format Make your code look super nice and formatted!

Ctrl+K - Scan to next occurrence of variable

Ctrl+Click - Takes you to the method that you're currently moused over

Alt+Shirt+R - Rename (Refactor)

F4 - Show class hierarchy Useful for large projects.

Debug mode shortcuts: F5 – Step into a function F6 – Step F7 – Step out of a function

Alt+leftarrow or Alt+rightarrow - Jump back to a line, Jump forward to a line

And the most used at all:

Ctrl+S – Save

 

Android requires compiler compliance level 5.0. Please fix project properties.

In our Android mobile development class we constantly work on projects as a class and then Dr. Liddle sends us the updated zip containing the project to review after our in-class additions.  For some reason today I'm having some issues importing the Android project into Eclipse.  Problems and fixes below. Problem #1: Android requires .class compatibility set to 5.0. Please fix project properties.

Solution: 1. Fix project: Package Explorer -> Right click the project -> "Android Tools" -> "Fix Project Properties" 2. Restart Eclipse: "File" -> "Restart"

Problem #2: The following error appears many times The method xyz() of type ABC must override a superclass method

Solution: Package Explorer -> Right click the project -> "Properties" -> "Java Compiler" -> "Compiler Compliance Level" = 1.6

Problem #3: The import android.net.http.AndroidHttpClient cannot be resolved

Solution: Package Explorer -> Right click the project -> “Properties” -> "Android" -> "Project Build Target" = 2.3.3

Note: Also try Clean (On Windows: Project -> Clean) then Refresh (F5) at random.  There's a good chance this will magically solve all your problems.

Eclipse Error: Type cannot be resolved

EclipseProblem running an Android application in Eclipse: The type java.lang.Object cannot be resolved. It is indirectly referenced from required .class files

Solution: In Eclipse, the cause of this problem is that somehow the SYSTEM JRE LIBRARY associated with the project was deleted.  Simple fix in Eclipse:

  • Right Click Project you are working on from Package Explorer
  • Go to Properties
  • Go to Java Build Path from the right tree structure
  • Go to Libraries Tab
  • Choose Add Library Button
  • Select JRE System Library
  • Hit Next, the Radio button will prompt the Workspace default JRE, and let it be that way
  • Hit Finish

Still getting the error, though, in the case of an Android bundle... stay tuned....

Optimize your site for SEO

Been learning about increasing SEO for your website lately.  Couple tricks: Meta tags in your HTML files.  Put the following code in your header, aka in between the < head > and < /head > tags.  For example on my site my SEO code looks like this:

<!-- SEO CODE --> <meta name="description" content="The professional blog and portfolio of Kyle Clegg" /> <meta name="keywords" content="kyle clegg, who is kyle clegg, kyle mitchell clegg, kyle clegg byu" /> <link rel="canonical" href="http://kyleclegg.com/" /> <!-- /CLOSING SEO -->

Now, apply this to your site: <!-- SEO CODE --> <meta name="description" content="Company website for eLearning Interactive." /> <meta name="keywords" content="elearning, online learning, online training, hazcom training modules" /> <link rel="canonical" href="http://elearninteractive.net/" /> <!-- /CLOSING SEO -->

This will help optimize your site or blog.  I guess the best thing to up your site though is to get lots of other sites to link to it.  Then google indexing/web crawlers will think it's really popular.  So get your blog or your company published by some online newspaper or on del.icio.us!   That's the key... no more tricking Google by creating pages that say "elearning" ten thousands times to try and get your site to the top of the SERP.  Stop living in 2004.  They're too smart now.

 

Useful articles:

 

I'm new to SEO... any suggestions?  Let me know.

How to FTP with BrainHoney

I figured out how to FTP directly into a course's resources today using FileZilla. It only takes a couple relatively-simple steps. 1. After opening your course and navigating to the syllabus page the first thing you need to do is locate the FTP address. On the right side of the screen, under Resources you need to click +Add, then the Multiple Files tab and you'll see the FTP address and the user name to use.

2. Once you've got then, open up FileZilla and go to the Site Manager. Click new site and enter the following: (a) General tab:

    Host: gls.agilix.com
    Server Type: FTP
    Logon Type: Normal
    User: kc/admin (enter yours here)
    Password: XXXXX

(b) Advanced Tab:

    Default remote directory: Here you enter the course id. Make sure you begin with a forward slash. If not it won't be able to parse the directory path.

3. Everything else can be left as is. Now just click connect and you're in!  Drag and drop folders and files, then view the files in the UI to verify they've uploaded successfully.

Powershell 101

Well, I definitely got my hands wet with running Windows PowerShell scripts today.  I ran into a number of issues in the process, so I better make note of the solutions for next time around. First off, PowerShell is Windows' task automation framework.  Good for running scripts on windows machines.  As far as I can tell, you can run PowerShell in the command prompt with the command call PowerShell.exe: C:\Scripts>PowerShell.exe. Or, you can open the Start Menu and start typing PowerShell and open Windows PowerShell.

Now, you have a script and want to run it right? Pretty easy right? Not for me. I had to jump through some serious hoops here... so I tried typing Suspend.ps1. No dice. I'd get an error saying the command isn't recognized. Through some bing magic I found that you need to include the complete file path: C:\Scripts\Suspend.ps1

Or, if you are currently in the specified folder you can use the .\ notation: .\Suspend.ps1

It's better to use the full notation, to prevent it from finding a file of the same name in your current Windows path (it looks through the entire path, not just your current directory). FYI - you can see your current path with this command: $a = $env:path; $a.Split(";")

Anyways, once I figured out how to actually make the call from the command prompt, I kept getting this weird signing error: File C:\Scripts\Suspend.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get- help about_signing" for more details. At line:1 char:19 + C:\Scripts\Suspend.ps1 <<<< This is where it got tricky. I searched around for a bit and found that by default, windows machines are set to restrict you from running scripts. To see your execution policy try using the command Get-ExecutionPolicy. If you've never messed with this before, it'll probably say Restricted, like mine did. Now, the simple fix to change this is to use the following command call: Set-ExecutionPolicy RemoteSigned. If this works for you, congratulations! You're good to good. For me... it didn't. I got some weird error that looked like the following: Set-ExecutionPolicy : Access to the registry key ‘HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell’ is denied. At line:1 char:20 + Set-ExecutionPolicy <<<< RemoteSigned Is this familiar to you? Hopefully not, but it if is. There's a solution.

To fix this and add the RemoteSigned execution policy by hand you'll need to work a little Windows registry magic.

  • Open registry by opening the start menu and typing regedit into the search box
  • Browse to key HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell
  • If “ExecutionPolicy” does not exist, create it as REG_SZ with value “RemoteSigned”
  • Open PowerShell and use the command “Get-ExecutionPolicy” to verify it is set correctly

Now, you should be all set. Go back to the command prompt or PowerShell window and run your command. This time when I ran C:\Scripts\Suspend.ps1 it was beautiful.

If you have any other issues send me an email or leave a comment, I may have struggled with it too.

Useful pages for troubleshooting: http://technet.microsoft.com/en-us/library/ee176949.aspx http://bartvdw.wordpress.com/2008/04/22/powershell-executionpolicy/#comment-190

Indexing on FamilySearch.com

Giving indexing a shot for the first time.  It looks pretty simple and a good way to volunteer some time to a good cause.  Simple setup, too many menus and getting started options though.  They should have 1 super simple getting started path that you follow.  As is, you can "get started", watch some YouTube videos, check out the FAQ, tutorial, quick start, or just jump straight into it.  I mean, it's all good information, but it's a bit of an overload to me.  I just want to index, I mean COME ON!

Give it a shot: FamilySearch Indexing

Binary Bomb

ECEN 324 - Lab Assignment 2: Defuse a binary bomb.   Introduction: The nefarious Dr. Evil has planted a slew of “binary bombs” on our machines. A binary bomb is a program that consists of a sequence of phases. Each phase expects you to type a particular string on stdin. If you type the correct string, then the phase is defused and the bomb proceeds to the next phase. Otherwise, the bomb explodes by printing "BOOM!!!" and then terminating (and you lose 1/4 point per explosion). The bomb is defused when every phase has been defused.

The textbook appears to be so widely used that there's a lot of help out there when it comes to this lab. We found some notes that I thought were helpful as we reverse engineered our way to diffusion. Thought I should pay if forward by posting some of my own thoughts.

So, our mission was to diffuse Dr. Evil's binary bomb (bomb #39). We used GDB, the GNU debugger to inspect the bomb run by and stepping through the assembly code during each of the 6 steps, cracking each step one at a time. The total project took almost eight hours for us (2 of us) to finish.

------------------- phase_1 -------------------

This step was fairly easy. We could tell it was expecting a string right off the bat, then noticed that the solution string starts at a location 0xXXXXXXX (you'll have to look at the debugger) and compared it to the input string. Thus, the solution to phase_1 is one of the strings in the file. You could just guess and check here, too. Brute force should get the job done at this phase. We determined our string to be 48 characters long. Then we looked in the bomb file and found only one string 48 characters long.

Solution: I am not part of the problem. I am a Republican.

------------------- phase_2 -------------------

This one was rather tricky after an easy step one. First, we found that it was looking for 6 numbers, from the scanf function looking 6 times.  We eventually figured out that it the code consisted of a repeat of 3 decreasing numbers. 10 9 8 10 9 8, for example. That did the trick for us.

Solution: 10 9 8 10 9 8

------------------- phase_3 -------------------

This was the hardest phase for us. We seriously took 2 hours, then took a break for the day, came back the next day and spent another 45 minutes before we got it. I wish I could explain more by my lab partner carried us through this step. Our code was cracked by a single digit number followed by a 3-digit number we had to decipher.

Solution: 6 227

------------------- phase_4 -------------------

On this phase we could immediately tell there would only be one string to defuse this phase. Looking into it a little further, we found that 7 was being stored in %eax and also put into %edx, doing some sort of n^n type deal. Ours was calculating 7^n, so the code was simply n. Not too bad.

Solution: 4

------------------- phase_5 -------------------

This phase was really cool. Basically it was like solving the back of a cereal box. By inputting characters you'll see a code emerge, aka each letter will actually represent another character. For example in our case we eventually found:

  • a-s
  • b-r
  • c-v
  • d-e
  • e-a
  • f-w
  • g-h
  • h-o
  • i-b

And so on... We looked at the numbers each character was being compared against and deciphered our code.

Solution: aepkmq

------------------- phase_6 -------------------

Guess and check! Seriously... this is the only way to get this phase. By looking at the scanf calls and compare methods we could tell that it was expecting six numbers, all over which had to be 6 or less, non-repeating, nonnegative, nonzero numbers. We tried for hours (really) to figure it out and finally got somewhere by guessing and checking. Since we only had six possibilities and numbers can't be reused, these ended up being the best way to decipher the code. After we could tell we got past the first number it made it easier because there were less options for the next number, since the numbers can't repeat. After some good guessing and checking we finally got it.

Solution: 3 2 5 4 1 6

Done! Like I said above it took the two of us almost 8 hours to finish. There's probably people out there who can do it in half that time, but we diffused the bomb and saved the world, so I'm happy. If anyone has any input, corrections or questions just send me an email.

Disclaimer: I'm posting the solutions here to help see general format, and as a personal record (in case I still fail the class). There are at least 60 different bombs one could be assigned, each varying in approach and solution. The chances of these solutions working elsewhere are slim.