Friday, December 12, 2014

A Real Ajax Login System

Dashed borders lets you know this is
hard core web design.
Demo | Source

After a bit of Google searching, I could not find the login system I want. I would say 'fit my needs', but that's not accurate. There were tons that could fit the need, but I want a back end php system that allows a user to login by way of ajax calls. Specifically one that didn't require all my file names to end in .php. Is that necessary? No. Is that being picky? Probably. Is it fun to make it work anyway? Of course.

There are plenty of php ajax style login systems and examples out there. I started with this one from 9lessons.

I have no right to complain about other people's work, but wow this code is hard to read and inconsistent. It works though, so I chose to clean it up and start making changes.

DISCLAIMER: I would like to note I am not a security expert. While I feel this system is decent enough, I cannot advise using it in a real application environment.

Here is a demo, note all pages end in html. You can log in with demouser and password, but check out the registration. That's where most of the magic is.

Saturday, November 29, 2014

jQueryFileTree - an old plugin

I've been on a project at school for some time, it's a lot of fun. I enjoy working with others for a change. The project uses jQuery and we had a need to view directories from the server. Originally I wrote a very messy class that got the job done, but then one day I stumbled on jQueryFileTree.

Over all it was much simpler than my implementation. The only thing I don't like about it is it passes raw html from the connector script. My implementation passed a json object. Still, didn't take much work to get everything changed over. Most importantly, jQueryFileTree's implementation looked prettier... a lot prettier.

My lame file tree.
jQueryFileTree's default.


If there is anything I've learned about working with web interfaces, it's this: noone cares how efficient/useful/pretty/awesome your underlying scripts is, they only look at the surface. It's actually unfair the value placed on aesthetics. Cover some craptacular code with bootstrap, everyone think's it gold.

Why am I even writing about this?

For as much as I like jQueryFileTree, there were a couple of things it couldn't do. Now it can do those things, because open source!

One part of our project didn't need files, only folders. The user selects a folder and magic happens no matter what is inside. I added a Boolean option called 'folderSelect' to handle this behavior. By default it's false, but if set to true files are not displayed and when the user clicks a folder that directory path is passed to the callback.

The other thing we needed was a way to exclude files by name or extension. The new option 'exclude' is an array of strings. Any strings that match a folder or file name is given a hidden class. In contrast 'folderSelect' does not return files at all, this will return the excluded names but not show them. I did this just in case we wanted to have an option to show hidden files. In addition to names, any string that starts with '*.' will exclude by file extension.

jQueryFileTree with these new options can be found at this fork of the original. The exclusion code get's complicated, no doubt there are ways to improve it (I'm all ears if anyone has a suggestion).

Maybe I'll change it up to pass json in the ajax call, and have a way for the user to change up the look. I think that would be better. I don't have a need for that right now though, so I won't be surprised if it doesn't happen.




Monday, September 29, 2014

Steal These Ideas

September is almost over, and I've come up with many excuses to do something other than write this months post. I'm not going to lie, this month I'm cheesing it.

I've found several sites with a similar "steal my idea" theme. Usually they are bad ideas. Today I'm going to share my idea math. Copied and pasted from my journal:


Crazy Idea Math
---------------
Ideas are a dime a dozen, and anyone can come up with a dollar's worth in a day.

    $0.10       $1.00
    12 ideas    120 ideas
    
    100 are gibberish
    19 suck
    1 mediocre  --------\
    1/10,000 decent      }--- good ideas
    1/1,000,000 gold ---/

Based on that math, it will take $8,334 worth of ideas to get to the golden one. That's almost 23 years if you can do a dollar a day.

Writing Them Down
-----------------
Writing down the mediocre ideas is the only way to accelerate the process, or at least increase the percentage of good ideas.


The bottom line is ideas are the easy part. Implementation is hard. I don't write down as much as I should, but in the "steal my idea" spirit I'm going to share a handful of my mediocre ones.... okay some are not even mediocre.


Saturday, August 30, 2014

Game Development Practice

LCR Tubes with less fun instructions inside.
I found Eric Zimmerman's blog a while back and have enjoyed his series of posts about how he teaches game design. Particularly this one about fixing broken games. Like most geeks, I like games. I like playing them, thinking about them, how could I make them better, how can I make my own...

Zimmerman explains broken games as ones with no meaningful outcomes. Almost exactly the same conclusion I made, except I defined it as the player having no bearing on the outcome. No doubt I picked this idea up years ago from Sid Meier's idea of games being "a series of interesting choices".

Zimmerman lists five broken game examples; War, Rock-Paper-Scissors, The Dice Game, The Number Guessing Game, and Matching Pennies. The assignment in his post is to create a variation on one of these games to fix the broken aspect.

I'd like to do this assignment, but I'm going to choose a different broken game: LCR. Here are the original rules (as best I can recall).
  • The game has 3 custom dice; half the sides are a dot, one side is an R, one is an L, and the final is C.
  • There must be 3 or more players (too many make for a long game too few is more boring).
  • Each player starts with 3 tokens (or quarters to make the random win more exciting).
  • On each players turn they rolls a die for each token they control, max 3.
  • If a player controls no tokens, they are still in the game but cannot roll dice on their turn.
  • The player will pass a token right for each R rolled, to the left for each L rolled, and put a token in the center for each C rolled.
  • The final player to be the only one with tokens, wins (and gets the quarters in the center if playing with money).
It's a simple game, and can even be fun. I think it's a party favorite because inebriated people don't have to make decisions.

I've played this silly little game many times, and every time I can't help but think we're just waiting to find out what the random outcome will be (I'm rarely inebriated). Until I read Zimmerman's post, it never occurred to me to think about how I could change the game. 

This is what I came up with (unchanged rules are grey):

  • The game has 3 custom dice; half the sides are a dot, one side is an R, one is an L, and the final is C.
  • There must be 3 or more players (too many make for a long game too few is more boring).
  • Each player starts with 4 tokens (or quarters to make the random win more exciting).
  • On each players turn they rolls a die for each token they control, max 3.
  • Before dice roll, the player will pass one token to the right or left.
  • If a player controls no tokens, they are still in the game but cannot roll dice on their turn.
  • The player will pass a token right for each R rolled, to the left for each L rolled, and put a token in the center for each C rolled.
  • If a player rolls three dots, they take a token (if available) from the left or right player.
  • The final player to be the only one with tokens, wins (and gets the quarters in the center if playing with money).

I didn't change much. I felt it was important to use the same dice as the original game. Everyone will start with 4 tokens (now a nice round dollar if you're playing with quarters), and pass one before the roll. At the beginning of the game the choice is arbitrary. As it goes on though I hope this will make things more interesting. Will you pass to the player with more tokens than you, or to the player with none? Having the player pass before the roll makes players with only one token effectively out of the game, but still with a decision to make.
The other decision making change is when a player rolls 3 dots, there is a 1 in 8 chance a player will roll this if they have 3 tokens (based on my experiences this is more common than you'd think). These two changes give players some deciding power on tokens going out and coming in.

Unlike the real assignment I haven't been able to do any play testing (the number of people I know willing to play table top games is sad).

Saturday, July 19, 2014

My First WildStar Addon - Kael's Housing Tour

Hard to see, but there is a handsome
warrior with new PvP gear in this picture.
The screen shows it's not much of an addon, but the person I made it for is ecstatic about it.

This post isn't about how to use Kael's Housing Tour. I spent more time writing a readme than it will be cumulatively read by users. It's available on the git repo. After some tweaks I'll put it on Cursed Gaming too.

EDIT: It's on cursed now too.

The look of this addon was made by Kaelish (that's who Kael is). If you are curious why it's her housing tour I suggest the aforementioned readme file. Obviously this will get better over time, for example I'd like to grey out the Guide and Change Guide button if you haven't clicked join a tour.. or not show them.

Development wise, lua is kind of strange. I'm not a huge fan of Houston, the official addon development tool. I only used it for making changes to the graphical form. All the lua editing was done in Notepad++. This was the first time I ever used git in Windows. I was told there was some pretty gui for it, but I found Git Bash and did what I usually do (except no copy and paste, lame).

The API is lacking in official documentation. Most unofficial documentation is just lists of libraries and methods available. Most of my real insight was gained looking at other addons. There are some area's my code is very similar to others. At first I thought that was kind of wrong, but the right click menu code for every addon I saw was virtually identical. I cyclomatic complexity-ed mine up by changing the right click menu option based on if you are a tour guide or not. Also, if you click on yourself the text is different.

The Visitor addon's function for searching random properties was decent, but I had to do some tweaking. The most notable (imo) improvement is I pass the unique properties searched to the form instead of searches done. Searches done will always increment until the user clicks stop. Unique Properties will eventually hit a cap, so the user can see they probably aren't going to find the property they're looking for. Future improvements a visual indicator that the search is still going, and I'd like to add an auto stop after so many searches with no more unique properties found. The are really a ton of things I want to add... some are in that readme.

This addon also marked the next iteration of my 10 minute hack experiment. I wrote a quick blurb in my notes for almost every day. I'm happy to share it, but these are just notes for myself (nothing juicy). They're in markdown, but I only ever view them in a text editor so it might not be perfect markdown.

Friday, June 20, 2014

Just Another Tetris Clone

Someone sucks at Tetris.
Despite WildStar's critical hit on my free time this past month, I've managed to code a little. Let me introduce both of my blog readers to the buggiest and most poorly coded version of Tetris they've ever seen.

http://geekwagon.net/projects/flipsy/

Don't ask why it's called Flipsy. That was just the name of the
folder when I started and I didn't bother to change it.

I did follow the Tetris guidelines to the best of my coding ability. The obvious things, like piece colors are there. With the exception of the square. One cube on the square red so I could see it was rotate. Less obvious Tetris familiarity is the piece randomness. There are a ton of guidelines I haven't implemented yet.

The primary goal of this project was to increase my familiarity with Phaser.io, an HTML5 game framework. It takes care of the lame part of game crafting, drawing stuff on a canvas, and lets you focus on the look and logic of the game. Their site has a lot of examples to help you. I found most of their examples are for every game type imaginable except a falling block puzzle game. They are none the less helpful at getting concepts across.

This was also a personal experiment with the 10 minute hack.

The idea behind the 10 minute hack is to work on something for 10 minutes every day. The idea is that once you get into a project it is easier to keep going. If you are just not in the mood you can at least say you thought about it for 10 minutes. I am certain, had this stupid WildStar game not come out there would have been less days of only 10 minutes. To be honest there were a couple of days I didn't even get my 10 minutes in. Every day I did do the 10 minute hack I made a note of it in a text file. Like a 10 minute hack daily journal. Most entries were a sentence, but I found the reflection to be useful.

I'd post my 10 minute hack journal, but my biggest mistake was using the hack to work on multiple projects at once. I think in the future, for at least a few weeks at a time, decide which project the 10 minute hack will be used on.

For the future of this project, first thing will be some major refacroting. Then some bug fixing. For example; if you go nuts with the rotate key and left/right arrows at the same time you can split a piece apart. Especially weird stuff can happen at the edge of the screen. After that I'd like to start making some serious changes, like make it more than another Tetris clone.



Thursday, May 29, 2014

Damn you Avat... I mean Carbine

This might be my last post, save yourselves! It's too late for me. WildStar comes out in two days and I already know my weekend is ruined. This game is too much fun.

Warning: personal insights that don't generalize nerds ahead. I'm also linking to phrases that come from pop/nerd culture that have influenced my way of thought over the years. It's an experiment to out the random clutter in my conscience.



Like many, I want to be productive. I want to be successful. I want to balance between what is fun and what makes me those things I said. I'm the only one that struggles with this balance, right?

I get it, there is dopamine in the brain that responds quicker to games. The immediate satisfying feedback that I did something awesome (those epic level up lines don't help). What bothers me, is I can feel this way about writing code, or writing creatively, or doing almost anything else. It just takes longer to get into it the flow, and it's easier to fall out of. I believe Jane McGonigal is right. If we can make real life feel like playing games we can solve all the worlds problems.

I hit a good code writing snag and one of two things will happen. It will invigorate me to find the solution, or it will seem to daunting of a task and make me quit for the day (most code I write is for my own projects so I have that luxury). In my defense, after a good nights sleep I'll come back and push through it. I'm almost certain there is a level of complexity versus how tired I am that determines if I'll push through or quit.

On the other hand games aren't like that. They seem to offer just as much challenge as I need to keep going. For some reason I'm not deterred when I do meet something challenging. Remember pre-internet gaming? Someone who reads this post might. It was hard core. I literally walked all over Hyrule burning every bush and bombing every wall because that's how you found secretes. Why can't I be that motivated when it comes to coding? Why is it a problem that doesn't come up with multiple stackoverflow results on a search considered hard? I'm sure developers in a pre-internet age spent just as much time hammering out problems as I did finding secretes in video games. Except now they answer those stackoverflow questions for people like me.

I have to wonder how successful I will be if I'm willing to spend the time to find secrets in a game, but give up when I hit a snag in real life? I take it back I don't wonder, I know. It just makes me sad when the right answers are staring me in the face, but I will still lose this whole weekend to gaming on. You know, instead of updating the template for my blog because it's absolutely horrible.

The struggle for balance continues... In the mean time I will be blowing that balance out my butt by fighting for the Exiles right to a decent (virtual?) life on Nexus. My only hope is that I can get it out of my system this weekend, then go back to trying balance again.



Wednesday, April 30, 2014

Habits

No doubt, the world of
Habitaria fears the might
 of a level 4 habit builder
and his magic helmet.
I admit, the primary point of this post is to keep my resolution of one post per month. It seems like an easy goal; until finals. Warning: this post contains a bit of personal junk.

On that note, I find personal productivity (and tracking it) an interesting field. If my RSS reader is a metric of any kind, there are a lot of people interested in it. It makes sense, we're all selfish to some extent and personal productivity is all about ourselves.

Some years ago I read 7 Habits of Highly Effective People. I'm leery of book titles with numbers and 'ly' words in the title, but it remains the only book I've ever recommended to others. It was the book that made me realize I can learn how successful people do things. I still need to refine it, and practice it, and make it work for me; but I'm not starting from scratch (note: more proof we are living in a cool future).

I don't consider myself a success, but I feel like I'm finally on the right path. Over the years I've used a number of tools to aid me in being a productive or successful person. I think many of us struggle with what works for our tastes.

For me, the task managing tool I use most is the one in gmail (you know that one no one knows about and almost doesn't make sense it's even in there). When I am not at home I can add to it from my email account. When I am at home I use this link to manage the list.

https://mail.google.com/tasks/canvas

I don't recall where I found it, or why it exists, or when Google will take it away (RIP Reader). I like it though. I don't even bother with separate lists, just one big list. For example I'll have stuff like this:

  • COMP3223 - Assignment 3 due
  • COMP3053 - Group Project due
  • Research Group - Setup bitbucket repo
  • Personal - taxes
  • Personal - look into dropbox alternatives
I generally group them by what comes before the hyphen, but I can also sort by due date. Tasks can be edited like one big text document, and you can add notes to a specific task. The only thing simpler would be a text document (which I've been known to use but it not as satisfying to delete tasks as it is to check them off and see the line through them).

A couple of weeks ago I started using habitrpg.com. It also has a task list with satisfying checkboxes, and it's kind of fun. I've particularly enjoyed the daily tasks, I have a bad habit of skipping breakfast. Since I've started using HabitRPG I have yet to miss breakfast. 

Time will tell how well I stick to this one, but so far it is more promising than many of the other tools I've used. It caters to the gamified desire for immediate feedback. Just the other day I was so close to level 3, I did a Project Euler problem (which is one of my regular habits) just to level up.

If this post has a point to make, it is try new stuff. I hear a lot of people say "Have a system and stick to it." I feel that is bad advice. I say stick with what works, but don't let that stop you from checking out everything else.

Sunday, March 23, 2014

Responsive Break Points

geekwagon.net at 325px
I've been playing around with bootstrap more, and I like almost everything about it.

I'm not a fan of where they choose break points for responsive design. No doubt they've put in more effort than me, but with their defaults a half-sized browser window on a 1280 x 1024 monitor brings up the shortened "hotdog" style menu.

I am old fashion, I still have a 4:3 monitor (in my defense it is my secondary monitor). For geekwagon.net's more responsive redesign I made up my own break points. They are not perfect, but here is the thought behind them.


Sunday, February 16, 2014

Non-stop Bitcoin Mining

It's no secret I mine Bitcoins, but I don't bring up that I'm not very good for the obvious geek creed reasons. Today I finally made a change to my mining rig that I hope will end the occasional dreaded "Idle Miner Notification" from btcguild.com.

Screen shot of the log file, how interesting and inefficient.
I have small mining setup, a mix of Block Eruptors and a single Butterfly Labs Jalapeno. We started having strange Internet connection issues, and I immediately assumed it was AT&T's fault (to be fair it usually is). Also about the same time bfgminer reported the Jalapeno was sick. Never crossed my mind these issues were related, but once I sent the Jalapeno off to be RMA'd all most of our Internet problems cleared up.

With the Jalapeno gone, bfgminer ran with no problems. With the Jalapeno the program would inexplicably give up, even with the new one back in action this still happens. As a good administrator I'm sure I could have looked for a log or an error message or something, but it is very easy to putty back in, hit the up arrow, enter, ctrl+A+D, and go on with life. I can even do it remotely with TeamViewer because my home PC is on almost all the time (thanks for nothing logmein). Sometimes it goes for months without my need to intervene, other times only hours (and in the middle of the night).

After nearly a year of manual restarts and an immeasurably small loss of Satoshis, I've finally made a script to continually check if bfgminer is running and restart it if it's not. My apologies for not giving credit where it is due, most of this script came from a post on stackoverflow, but I'm not sure where.

It is far from perfect, but so far so good. I'd love to hear anyone's two cents  Satoshis on how to improve it. I also hope this is an aid to other small time miners.

EDIT: March 4, 2014
It didn't take me long to realize this was better to run as a cronjob. The biggest problem I had was multiple screens running, so I changed it over and made my log file a little better.

My first attempt was to remove the pause line and add the script as a cronjob that runs every 5 minutes.

The Ubuntu Wiki CronHowto was helpful, especially the Enable User Level Cron section.

I also update the log file to show a time. For weeks I thought everything was good, because you know, nothing went wrong. I was suspicious something wasn't quite right because the log file never showed the miners being restarted.

Today the power went out, and when the server came back on I expected miners to be running within 5 minutes... they did not. I dug a little deeper and this comment on the Ubuntu forms pointed out my issue. There were a lot of comments about making sure the script was executable and user level cron was set up. My problem specifically had to do with how screen works. I needed a -d for detach. The new script is in the gist, it's been tested and rocks along well.


Saturday, January 25, 2014

Ultima VII Party Planner

In an effort to learn more about backbone.js I made a web application that is easily considered beautifully useless (beauty in the eye of the beholder, useless in the eye of everyone else). Really, this is probably one of the finest work of code writing I've accomplished to date and there are maybe ten people in the world who will use it.

Menion makes out like a bandit.
There is plenty of room for improvements, but I'd like to write about it anyway.

The picture is an example of a typical, eight character, all level six party. You have a list of all trainers to go visit, who to train when you get there, and about where they are on the map. It also shows how much gold to take to each trainer, and the total cost of all training.