Archive

Archive for the ‘Web Development’ Category

Open VIM From PHP CLI

August 31st, 2010
Ever wonder how to open text editor from php similar to SVN/GIT do when -m is not passed as an argument.
Create a filename this is going to be a temporary file and is possible that many users
will be running this same script at the same time so randomly generated name is ideal.
Then write to this file, I use echo with the output sent to a file.  This will create the file
as well as send the information.  Then make another system call to open the file using vim.  Since this is running
from a command line there is no terminal name.  We run a system call “`tty`” to get the terminals name
and use that as output buffer for vim.  If you do not use this you will get the error “Vim: Warning: Output is not to a terminal”

Ever wonder how to open text editor from php similar to SVN/GIT do when -m is not passed as an argument.

Create a filename this is going to be a temporary file and is possible that many users will be running this same script at the same time so randomly generated name is ideal. Then write to this file, I use echo with the output sent to a file.  This will create the file as well as send the information.  Then make another system call to open the file using vim.  Since this is running from a command line there is no terminal name.  We run a system call “`tty`” to get the terminals name and use that as output buffer for vim.  If you do not use this you will get the error “Vim: Warning: Output is not to a terminal”

Web Development , ,

Hammered Forums – Forms in an MVC Framework

August 27th, 2010

My first attempt at a full scale project is named Hammered Forums, it currently has a working copy. Do not judge it based off this working copy, if you’re interested you can download the source.   It is currently an extremely rudimentary forums.

Jform Overview

The current development cycle covers the form class, JForm.  Jform will eventually be powerful enough to encompass the whole site with an easy to use api.  The problem with writing a form class in an MVC Framework is where to keep the form creation code.  Should it be written in the Model Layer for use throughout the site?  Should it be written in the controller because it contains business logic?  Should I write a fourth subset(MVC+F).

Each form implementation comes with its own benefit and its own draw backs.  Using the Model Layer to house your form code keeps your controllers  clean, and makes forms easy to find as they would be in the model they most clearly pertain to.  But often forms contain business logic e.g., login restrictions, posting restrictions,  these do not belong in the Model Layer.  Using the Controller Layer can lead to some confusion and increased size in the controller, but the biggest draw back is replication.  If you want a form on multipages you have to write it in each controller or place it in the base controller neither of which is an ideal solution.  Creating a fourth Layer seems most logical, but this dirties up your MVC Architecture.  For Jlog(the framework) and Hammered Forums JForm is implemented in the controllers.  The site should not contain many global forms so this should be a non issue in this development.  However, keeping business logic in the Controller Layer was the most important reason for this selection.

JForm The Idea

The original outline of JForm comes from JLogs predecessor Vanilla’s form handler.  While working with Vanilla’s form handler I came across several short comings, lack of a feature environment and poor functionality.  The forms did not allow for easy label creation in the View Layer, support multi form fields(form fields with array results), or let you put the same form multiple times on the same page.  The forms also only implemented basic form structures.  I wanted forms where I could specify email address and have email address validation on the fly.  I wanted the ability to seamlessly integrate with javascript addons.  The declaration of a JForm element as a Date should automatically include a Javascript popup calendar onFocus.

JForm The Development

Though still in process I decided to go with the two level approach. 1: The Form Wrapper, this is an object that’s main data structure is an array of JForm_fields.  If you want to perform an action on the entire form it would go through the Form Wrapper.  Then JForm_fields are the second levels, these objects each represent their own specific form element.  I started by writing the wrapper and changing my forms as I went along.  As I needed new JForm_fields I would write them.  They all inherit from a base class that contains basic setters and getters.  The names for the JForm_fields are separate from their indexes in the Form Wrapper this allows for easy implementation of multi-fields.

Web Development , , , ,

New Layout

August 17th, 2010

This blog has been pretty lifeless and dull with small spurts of inspiration.  This week is one of those spurts.  I recently got a hold of a copy of http://www.sitepoint.com/books/wordpress1/.  Though I could probably figure most of it out, there will hopefully be some non straight forward information, and a more person and professional lay out and content coming to this blog.

Web Development

Sphinx Installation and Setup

August 17th, 2010

Sphinx is an open-source full-text search server, designed from the ground up with performance, relevance (aka search quality), and integration simplicity in mind. It supports multiple databases as well as files and streaming data. It has a command line implementation as well as API’s in many different languages. This guide will go over installation, setup, as well as some common problems that many first time users have while working with the LAMP stack. Read more…

Sphinx Search Engine Integration, Web Development , , ,

Calculating Business Week

August 11th, 2010

Need to calculate what day 10 business days ago was? This is how it is done.

Breaking it down
The function is passed the number of business days as an integer. It calculates the current day of the week 0-6, storing non-business days(Saturday and Sunday) as Mondays(1).

If the current day of the week is fewer than the given number of business days away from the previous non business day the function returns the number of business days. If this is not the case the function subtracts the number of business days already used this in week from the total number of business days(if today is Thursday then subtract 4 from the number of business days). The difference or remaining business days is divided by 5, the number of days in a business week. This number is then rounded down to the nearest even integer, it can be thought of the number of business weeks or the number of skipped weekends. Adding 1 accounts for the weekend that was skipped with the original subtractions. Multiplying the number of skipped weekends by 2 returns the total number of skipped business days.

skippedWeekend is added to account for days that were skipped if the current day is on a weekend.

Web Development

Setting Up MySQL Server on Ubuntu

March 12th, 2010

Pretty easy first:

Read more...

Web Development

Django On Mac OSx

March 8th, 2010

Originally battling with installing Django on OSx I decided to go with my host(dream host) then after battling with them and realizing that I did alot of my development on a train with out internet access that it would really benefit me to install it on my Mac OSx Laptop and to forgot the Apache Integration, I thought this would be a synch armed with my new book I leaped into the unknown.  The instructions were pretty easy to follow:

I installed a new version of MySQL, pretty easy find out what version of OSx you’re running and if you don’t know how many bytes your processor is go with 32.

Then using basic commands from the Django website.  (I’m a big fan of svn, as i use it at work, I also see it’s down sides though) I was able to install Django and begin with the “interesting chapters” of my book.

./django-admin.py startapp mysite
./manage.py startserver(You can verify this works here, but we’ll check later)

So I trucked onwards in my book with the next command that actually set the framework and got the ball rolling.

./manage startapp blog

Then I continued defined a Model and set my database information in the settings tab.  And that’s when I hit my first road bump, I’m a trained programming not really a systems guy.  Everything I learn about sysadmins is by total accident in an attempt to do something with a programming language.

The first of two problems was python could not find the mysql driver.  This isn’t a hard problem at all.

1. Download East Install(download the egg that is the same version as python you’re running)
2. run the command “sudo sh setuptools-0.6c9-py2.4.egg ” renaming 2.4.egg to the file you’ve downloaded
3.  Run this command “easy_install MySQL-python” (This will install the mysql patch)
3.5 (At this point feel free to try the “./manage syncdb” command again it should fail
4. Open ./bash_profile or ./profile in using vim ~/.bash_profile or vim ~/.profile
5. add the following line PATH=”${PATH}:/usr/local/mysql/bin” (and “EXPORT PATH” if needed, this will allow all binary files to be added to the global link, to test this run mysql_config from wherever you are)
6. At this point you should be able to run “./manage syncdb” with no problem

If you’re following the same book as me, Python Web Development with Django, it will have you setup the admin controller for the blog site.  Once you do this and visit your blogsite you will have some error saying that “NameError: name ‘admin’ is not defined”.  In the urls.py add the following line of code “from django.contrib import admin” and you should be golden

Web Development

Valid Credit Card Numbers for Paypal Sandbox

March 5th, 2010

When testing your paypal account in the sandbox you’ll sometime need a fake credit card, and the ones supplied by Paypal do not work.
The easiest way is to login/create an account in the sandbox. When you do that goto My Account > Profile > Credit/Debit Cards.
From here create a credit card, remember the information for this credit card, and yes you can leave the Card Verification Number as 000.
And there you go, a valid credit card number. Note if you save this credit card you will not be able to save it as it will be tied to a paypal account.

Web Development

Changing Search Engine in Chrome

February 24th, 2010

To use google search in Chrome all you need to do is type the search term in the address bar, simple.
But is there a way to change the search engine to yahoo? Can I have multiple search engines like Firefox supports with a drop down, the answer is two these is yes.
Right click the address bar and click “Edit Search Engines”. As you can see there is a pre-populated list of popular search engines, as well as search engines that you have transfered over from existing browsers. You can easily any of these to your default search engine by click “Making Default” on the bottom when the specific search engine is selected. But how do you change the search engine?

When you looking at the “Edit Search Engines” window there are two columns: Name, Keywords. You can edit these by simply double clicking on the row. But back to the browser window, highlight the address bar(ctrl L) type the keyword for the search engine you want to use yahoo.com and then tab. This should create “Search Yahoo!” box in the url so you are aware of what engine you are using. escape will set the url back to what it was originally

Web Development

My First Ruby Script

December 12th, 2009

I decided as PHP developer I should learn another scripting language.  After running into RoR several times I decided I’d be better off just learning Ruby.  Asking my boss for any advise he told me to just rewrite what I do at work with Ruby.

Well I didn’t take is advice on a per word basis, but This is my first ruby script.  It’s designed to be run from the command line.  Any suggestions on making it better are welcomed.

This is a pretty straight forward function, slightly harder than your normal “Hello World” but doesn’t do anything to revolutionary. Little surprised about the lack of increment/decrement operator, but I recall reading that it isn’t not there because it is unclear.

Web Development