Optimizing Grocery Shopping – Superbetize

You run to the grocery store. You forgot all about your hot date who’s coming over soon and expecting a lovely home-cooked meal. As you run down the aisles, picking up the ingredients you typed in on your phone, you realize you’re going to be late. Not a good first impression… The items in the list are all over the place, making you run back and forth through the grocery store aisles as if you work there. If only there was a quick and easy way to view your shopping list already categorized…

Well now there is!

I’d like you all to meet Superbetize. This site will take your list of groceries, and categorize (super-betize!) them in different sections found in most grocery stores (e.g. produce, frozen foods, household supplies, etc.). The site provides a nice mobile interface as well so you can easily use it on your phone while traversing the grocery store aisles.

I am very proud of Superbetize. Some may even say that I’m super proud of it. I believe I’ve managed to solve a problem experienced by many, but spoken about by none. I also used this project as an excuse to learn some new and interesting technologies. Those include: Bootstrap, mod_rewrite, and cron jobs.

 

I want to introduce you to a problem I had while developing this site. The ‘groceries array’ that I use to actually sort through the grocery list was manually created by yours truly. I knew there was no way I’d be able to get everything right the first time, between all the different brands, categories, and spellings of product names. I needed a way to update this groceries array regularly with items that weren’t already in the list. This is where cron jobs come in to play.

Cron jobs are scripts that run on a schedule. These are usually used for automated backups or system administration. For each script, you can simply tell it the interval to run (daily at noon, Fridays at 5pm or once a year on April 20th). I created a simple cron script to run once a week that will collect all of the ‘Uncategorized’ items (which were stored in a separate table in my database) that went through Superbetize, and email that list to me. It works beautifully.

Once a week, on Sunday nights at 1am, I get an automated email coming from my hosting provider (where the cron script is hosted), with a list of all of the uncategorized items that were sorted in the past week. I simply add those items manually to my groceries array in the proper category, and update the live grocery array! This way you know if Superbetize couldn’t get your item once, next time it’ll be in the proper place 😉

Ideas, suggestions, and criticisms are welcome! Enjoy!

 

The Homes, Sweet Homes Content Management System

For a while now, I’ve been managing the web site for NC Student Rentals. Having to constantly make small adjustments and updates led me to the idea for the Homes, Sweet Homes Content Management System; I would create a CMS that would give the owners of the site the ability to make those small yet crucial updates on their own, without having to go through me. Using my recently learned PHP skills, along with a custom database framework I built, I started construction.

The final product is a ‘niche-specific’ (as I like to call it) content management system, built for controlling a rental properties web site. It has the ability to add, edit or remove properties, add a custom stylesheet to the main site, have multiple user accounts, and even add a rental application. This was my first front-end AND back-end project, and boy did I learn a lot from it. The back-end must be secure to prevent outsiders from changing content. The front-end must be dynamic to factor in error on the user part. And there are many little features you need to include, such as notifications for the user, and convenience features on the front-end when the user is still logged in on the back-end.

The Homes, Sweet Homes CMS is now live, along with the front end of the site. You can view a demo here. Please check it out and let me know what you think. Have any ideas for it? Please shoot them by me.

This project was a monster, and, like just about any other project, took a bit longer than I expected to be pushed out. However, now that that’s done, I can get back to work on some interesting stuff I have in store for you guys 😉

FB Friend Selector

It doesn’t happen often, but when you’d like to invite ALL of your friends to your Facebook event, you’re left with the daunting task of having to go through and click on each person, one by one.

Well not anymore!

Using what I learned from my previous project, a simple bookmarklet will allow you toggle all of your friends with one click.

To use it:

1. Drag the following link to your bookmarks bar.

2. Go to your Facebook event page and open the ‘Invite Friends’ dialog.

3. Make sure to scroll all the way down, so it loads all of your friends.

4. Click on the link you just bookmarked.

5. Depending on how popular you are, it may take a second. Then you’re done!

As per usual, here is a link to the pure JavaScript file.

Enjoy!

FCCheck

If you’re simply looking for FCCheck, a quick and easy way to make sure lyrics are FCC clean, click here! To install this on your computer, simply drag this link to your bookmark bar. Or copy the Link Location from the link and save that as the URL for a new Bookmark item.

What?

FCCheck is a tool that will allow you to very easily view all the FCC 7 dirty words on a page. This can be especially useful for DJ’s looking to clean up some (potentially) dirty songs.

Why?

For those of you who don’t know, I am an underground hip hop DJ on WKNC. Check out my co-host (Casual-T) and me (tomeslice) on Sunday nights, midnight-1:30 am. Tune in: http://wknc.org/listen.

It didn’t take us long to find out that one of the hardest parts of being hip hop DJ’s was finding clean music. For each song we wanted to play, we had to look up the lyrics, use the Find command and search for the ‘dirty 7’, an informal list that the FCC uses to make sure radio broadcasts are age-apropriate, and then skim the page just in case we missed something. This process became long and tedious after some time, as you might imagine. So I threw my thinking cap on, and in just one afternoon was able to come up with a solution: FCCheck.

I wanted to automate the process of searching for the dirty 7 in a lyrics page. I’ve used UserScripts before, but the nature of the UserScripts wasn’t what I was looking for. I wanted a button of some sort that I could click on while I was browsing any page, and for it to count how many occurrences of each word was on the page. And just for fun, highlight each occurrence as well. I was sadly coming to the realization that I may need to turn this project into a browser add-on. This isn’t a big deal, except for that I didn’t want to have to make 4 browser add-ons for each browser. Plus, I wasn’t familiar with how to go about doing this.

And then it hit me: bookmarklets.

If you haven’t heard of bookmarklets, you’re missing out. Bookmarklets let you store a JavaScript function, as a URL, in your bookmarks. This means that you can have the power of JavaScript, on any page you’re browsing, just a click away. To see how powerful these can be, check out some of these:
Kick Ass – Turns any page into an interactive, Asteroids-like game
Mark Up – Let’s you draw and write notes on any page you’d like, and then share it with the Mark Up Community
Urban Dictionary Lookup – Looks up the selected term on the page on Urban Dictionary
Wikipedia Lookup – Looks up the selected term on the page on Wikipedia

A bookmarklet was so perfect for this project, I don’t know how I didn’t realize it earlier. A few hours later, FCCheck was born. Try it, click on it! (To install FCCheck, drag the previous link to your bookmarks bar. You’re done!)

How?

The first thing I did was made sure the bookmarklet pointed to my servers to fetch the script. This has a few advantages. If I ever want to update the script, make it more efficient, or add some features, it will automatically show up for everyone who’s using the same bookmark! Plus, I can easily track and see how many people use the script. However, hosting the script on my server means that it can’t be edited by the user. And for that purpose, as well as if you’d just like to check out my code, here is a link straight to the JavaScript so you can do with it what you please!

Next, I needed a good way to count occurrences of words on the page, and then highlight them. As of now, RegEx is used to count the occurrences, and a third-party script searches through the page’s source and highlights each word on the page. Then an alert is shown displaying the number of occurrences of each word in the dirty 7 array, and a total at the bottom.

While I can say with great certainty that it should work correctly most of the time, please make sure you look over FCCheck’s results. I do not want to be held liable in case of any mishaps. Also, keep in mind that FCCheck will scan the WHOLE PAGE when looking for cuss words. On lyric sites where people post comments at the bottom, or if there are links to other songs at the sidebars, FCCheck will tally up those words as well. In other words, please use caution while using this bookmarklet and remember that it is not a one-all solution.

Thoughts? Improvements? Efficiency boosts?

Simple PHP + JavaScript CAPTCHA

While I was developing Fuck It All, I came across an issue that I’ve never had to deal with before. Since I was accepting user input that would in turn be posted on my site, I needed a way to make sure SPAM bots wouldn’t be able to make posts. There is quite a simple solution to this and I’m sure you have all come across it before, CAPTCHA inputs.

CAPTCHA inputs are small verifications, usually found on forms, which are easy enough for all humans to solve, but something that an automated machine wouldn’t be able to compute. These are commonly just a few words, but with some sort of distortion applied to them. Such text is, up until now, unreadable for computers. However, most humans can distinguish the individual characters without a problem.

For me to set up a system like that (without outsourcing), was way beyond what I wanted to do/had time to do. I could have easily used a publicly available widget and integrated that into my site, but I wanted to keep it classy and in-house. My friend helped me implement a simple CAPTCHA mechanism that can easily be implemented into a site using only PHP to generate the CAPTCHA and JavaScript to validate it.

HTML entities are reserved characters in HTML. To read more about HTML entities, go here.

Now for the actual CAPTCHA. Using these HTML entities, we can show a simple addition problem with two numbers. Most humans should be able to pass this quick test, while spam bots won’t be able to recognize what your site is asking them due to the HTML entities.

In your form, add the following PHP code:

<php 
   $num1 = "&#" . rand(49,57) . ";";
   $num2 = "&#" . rand(49,57) . ";";
   echo "<label for='captcha'>* <span id='captchaval1'>$num1</span> + <span id='captchaval2'>$num2</span> = </label><input type='text' name='captcha' id='captcha' maxlength='2' required /> (just making sure you're not a robot)";
?>

This generates two random numbers between 1 and 9 and tells the user to solve the math problem. Now we need to check if the user is correct using the following JavaScript code:

<script type='text/javascript'>
function validate() {
   var passed;
   var val1 = document.getElementById('captchaval1').innerHTML;
   var val2 = document.getElementById('captchaval2').innerHTML;
   var captchaval = document.getElementById('captcha').value;
   var result = parseInt(val1) + parseInt(val2);
   if (result != captchaval) {
      passed = false;
   } else {
      passed = true;
   }

   return passed;
}
</script>

By returning the ‘passed’ value to the form, you can check whether the user got the simple math question right or not. From there, you can handle the form submission as you please.

I would also like to thank my good friend Daniel for bringing this to my attention and helping me out with this code. If you have a second, you should check out some of his stuff as well. Right along the same alley: http://omniimpact.com/

Thanks for reading! I hope you guys enjoyed my first code posting!

Fuck It All

For a while now, I’ve been working on a new project. Fuck It All (FIA) is a simple site where you can go online and rant about anything anonymously. The domain? http://f.ckitall.com.

It’s a very simple concept but I have not seen it done well. In my research prior to the production of FIA, there were a few alternative sites with similar functionality, but I was not happy with their design/simplicity. I believe I have managed to create a site with that specific function, but with a very simplistic design and no unnecessary bells and whistles.

FIA was my first legitimate project working with a database. I can proudly say that I am now pretty sufficient with PHP, MySQL and the sorts. Working on FIA has also given me some excellent ideas I can start working on to push out to you in the future.

I have been waiting a while to release this product; lots of last minute adjustments and delays. Even so, I am very proud of the final creation. Please let me know what you guys think about it in the comments! After you post to FIA, of course 😉

Hello, World!

This is my first post in my new blog. I kinda wanted to try out something like this for a while but haven’t really gotten around to it. I’ve also been putting it off because I didn’t have much to post on a blog of my own. Recently though, I’ve been working on a lot of little simple solutions, just elegant scripts or programs that I feel like sharing but didn’t have a way of sharing them, until now at least.

So, a tiny bit about me; my name is Tomer, and well, I’m kind of a geek. I was never really intrigued by video games, fancy web applications or cool gadgets (well maybe a bit), but rather how they worked, what made them tick. Then I learned that with a bit of independent study and research, I could make video games and web applications myself. This is where I will try to turn my ideas and creativity into reality.

I hope you enjoy what I have to say and let me know what you think in the comments. Let the blogging begin!