Archives
Darth
Ezra Selfie
My First iPhone App, One Step at a Time – Part 1
I’ve recently started trying to learn how to create iPhone apps and 20 or so tutorials later I’m no better off then when I started. I could follow someone else’s instructions step by step but when I got to the end I had no idea what I had just done or how to reproduce it. So I decided to stop the tutorials and start my own app and just do one thing at a time and maybe this will help me learn in baby steps. I’m going to try and write it all down here for my documentation but maybe it might help someone else as well. So, here we go.
Part 1
Goal for this step: Read from a database and display the data in a UITableView
Let’s create a new project in Xcode and create a new Single View Application.
Once the project is created, click on the MainStoryboard.storyboard and delete the view controller created by the project. Then drag a new Table View Controller onto the storyboard.
Now go into the ViewController.h and change the ViewController to inherit from UITAbleViewController instead of UIViewController.
@interface ViewController : UITableViewController
Now go back to the storyboard and click on the view controller, then click on the Identity Inspector tab and make sure the class is set to ViewController.
Save the project and run. You should see an empty TableView.
Now its time to create the database. Download SQLite Manager for FireFox and create a very simple table. For now all the column are going to be text just to keep things simple.
Drag the database mySchedule.sqlite and drop it on Xcode. Be sure to select “copy” items into destination group’s folder.
Create a class for the database by clicking “file” on the menu and then “new” then “file”. Select the “Objective-C class” and select “next”.
Change MySchedule.h to look like below. Defining the pointers and properties of the table columns.
@interface MySchedule : NSObject{ NSString *weekof; NSString *monday; NSString *tuesday; NSString *wednesday; NSString *thursday; NSString *friday; NSString *saturday; NSString *sunday; } @property(nonatomic, copy) NSString *weekof; @property(nonatomic, copy) NSString *monday; @property(nonatomic, copy) NSString *tuesday; @property(nonatomic, copy) NSString *wednesday; @property(nonatomic, copy) NSString *thursday; @property(nonatomic, copy) NSString *friday; @property(nonatomic, copy) NSString *saturday; @property(nonatomic, copy) NSString *sunday; @end
Add “import sqlite3.h” to both ViewController.h and ViewController.m.
Create an NSMutableArray called scheduleArray to hold the data we will read from the database.
Create a method called scheduleList.
ViewController.h should look like this.
Set the identifier in the proptype cell to ScheduleCell so we can refer to it by name in our code
Now set the text of the table cells initial view in cellForRowAtIndexPath
Compile and Run and we have an app that displays dates from a database in a tableView.
Download the project files for Part 1 – MySchedule Part 1
Automate File Attachments on your WordPress Posts
UPDATE 4/24/2010: I updated the audio section to automatically wrap the audio with the flash player based on the example provided by Joseph Hinson
I’ve been coding WordPress sites for 4 or 5 years now. The more I use it, the more I love it. WordPress is an awesome CMS tool. When I create a site for a client, I want the site to be as easy as possible for a “non” web designer/developer types to maintain. One of my latest clients wanted to be able to create a post and attach a file for download. The client found it a little confusing to attach the file to a post and then include that file as a link. They also wanted to show an icon specific to the document type they had uploaded. With a little code, I was able to automate the process of linking to files attached to a WordPress post and specify the icon based on the files MIME type. There are plenty of articles on the web about WordPress attachments so I’m not going into any detail about that. Here is an article on attachments by Jeff Starr I’ve bookmarked for reference. Digging into WordPress
Here is an example of what we are about to create. I’ve attached several sample files to this post and that’s it. By the way, the zip file listed below is a zip of all the icons for you to download.
First let’s create the function and the shortcode. Go to your themes folder and open functions.php. If you don’t have one, just create a new file named functions.php and save it to your themes folder.
Create a new function with the following code.
function get_attachment_icons($echo = false){
//PDF Documents
if ( $files = get_children(array( //do only if there are attachments of these qualifications
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1,
'post_mime_type' => 'application/pdf', //MIME Type condition
))){
foreach( $files as $file ){ //setup array for more than one file attachment
$file_link = wp_get_attachment_url($file->ID); //get the url for linkage
$file_name_array=explode("/",$file_link);
$file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
$sAttachmentString .= "<div class='documentIcons'>";
$sAttachmentString .= "<a href='$file_link'>";
$sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/mime/pdf.png'/>";
$sAttachmentString .= "</a>";
$sAttachmentString .= "<br>";
$sAttachmentString .= "<a href='$file_link'>$file_name[0]</a>";
$sAttachmentString .= "</div>";
}
}
This block is for PDF files. You can tell that by the line that says ‘post_mime_type’ => ‘application/pdf’,. Just change the MIME type for the type of file you are expecting. In the final code, I’ve added a new loop for each MIME type below:
- PDF = application/pdf
- Word Documents = application/msword
- PowerPoint = application/vnd.ms-powerpoint
- Excel = application/vnd.ms-excel
- Zip = application/zip
- Audio files = audio/mpeg
Now at the bottom of the function we will add the hook for the shortcode and we’re done!
add_shortcode('attachment icons', 'get_attachment_icons');
Usage
Just include a shortcode in any post
[attachment icons]
or place one line in your single.php file (or where ever you’d like the document icons to show up)
<?php get_attachment_icons($echo=true); ?>
Final Code
Here is the code altogether for your copying and pasting pleasure. Enjoy!
function get_attachment_icons($echo = false){
$sAttachmentString = "<div class='documentIconsWrapper'> \n";
if ( $files = get_children(array( //do only if there are attachments of these qualifications
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1,
'post_mime_type' => 'application/pdf', //MIME Type condition
))){
foreach( $files as $file ){ //setup array for more than one file attachment
$file_link = wp_get_attachment_url($file->ID); //get the url for linkage
$file_name_array=explode("/",$file_link);
$file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
$sAttachmentString .= "<div class='documentIcons'>";
$sAttachmentString .= "<a href='$file_link'>";
$sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/mime/pdf.png'/>";
$sAttachmentString .= "</a>";
$sAttachmentString .= "<br>";
$sAttachmentString .= "<a href='$file_link'>$file_name[0]</a>";
$sAttachmentString .= "</div>";
}
}
//Word Documents
if ( $files = get_children(array( //do only if there are attachments of these qualifications
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1,
'post_mime_type' => 'application/msword', //MIME Type condition
))){
foreach( $files as $file ){ //setup array for more than one file attachment
$file_link = wp_get_attachment_url($file->ID); //get the url for linkage
$file_name_array=explode("/",$file_link);
$file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
$sAttachmentString .= "<div class='documentIcons'>";
$sAttachmentString .= "<a href='$file_link'>";
$sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/mime/word.png'/>";
$sAttachmentString .= "</a>";
$sAttachmentString .= "<br>";
$sAttachmentString .= "<a href='$file_link'>$file_name[0]</a>";
$sAttachmentString .= "</div>";
}
}
//Powerpoint Documents
if ( $files = get_children(array( //do only if there are attachments of these qualifications
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1,
'post_mime_type' => 'application/vnd.ms-powerpoint', //MIME Type condition
))){
foreach( $files as $file ){ //setup array for more than one file attachment
$file_link = wp_get_attachment_url($file->ID); //get the url for linkage
$file_name_array=explode("/",$file_link);
$file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
$sAttachmentString .= "<div class='documentIcons'>";
$sAttachmentString .= "<a href='$file_link'>";
$sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/mime/PowerPoint.png'/>";
$sAttachmentString .= "</a>";
$sAttachmentString .= "<br>";
$sAttachmentString .= "<a href='$file_link'>$file_name[0]</a>";
$sAttachmentString .= "</div>";
}
}
//Excel Documents
if ( $files = get_children(array( //do only if there are attachments of these qualifications
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1,
'post_mime_type' => 'application/vnd.ms-excel', //MIME Type condition
))){
foreach( $files as $file ){ //setup array for more than one file attachment
$file_link = wp_get_attachment_url($file->ID); //get the url for linkage
$file_name_array=explode("/",$file_link);
$file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
$sAttachmentString .= "<div class='documentIcons'>";
$sAttachmentString .= "<a href='$file_link'>";
$sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/mime/XLS8.png'/>";
$sAttachmentString .= "</a>";
$sAttachmentString .= "<br>";
$sAttachmentString .= "<a href='$file_link'>$file_name[0]</a>";
$sAttachmentString .= "</div>";
}
}
//Zipped Files
if ( $files = get_children(array( //do only if there are attachments of these qualifications
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1,
'post_mime_type' => 'application/zip', //MIME Type condition
))){
foreach( $files as $file ){ //setup array for more than one file attachment
$file_link = wp_get_attachment_url($file->ID); //get the url for linkage
$file_name_array=explode("/",$file_link);
$file_name=array_reverse($file_name_array); //creates an array out of the url and grabs the filename
$sAttachmentString .= "<div class='documentIcons'>";
$sAttachmentString .= "<a href='$file_link'>";
$sAttachmentString .= "<img src='".get_bloginfo('template_directory')."/images/mime/zip.png'/>";
$sAttachmentString .= "</a>";
$sAttachmentString .= "<br>";
$sAttachmentString .= "<a href='$file_link'>$file_name[0]</a>";
$sAttachmentString .= "</div>";
}
}
//Audio Files
$mp3s = get_children(array( //do only if there are attachments of these qualifications
'post_parent' => get_the_ID(),
'post_type' => 'attachment',
'numberposts' => -1,
'post_mime_type' => 'audio', //MIME Type condition
) );
if (!empty($mp3s)) :
$sAttachmentString .= "<ul class='audiofiles'>";
foreach($mp3s as $mp3) :
$sAttachmentString .= "<li>";
if(!empty($mp3->post_title)) : //checking to make sure the post title isn't empty
$sAttachmentString .= "<h4 class='title'>".$mp3->post_title."</h4>";
endif;
if(!empty($mp3->post_content)) : //checking to make sure something exists in post_content (description)
$sAttachmentString .= "<p class='description'>".$mp3->post_content."</p>";
endif;
$sAttachmentString .= "<object width='470' height='24' id='single".$mp3->ID."' name='single".$mp3->ID."'>";
$sAttachmentString .= "<param name='movie' value='player.swf'>";
$sAttachmentString .= "<param name='allowfullscreen' value='true'>";
$sAttachmentString .= "<param name='allowscriptaccess' value='always'>";
$sAttachmentString .= "<param name='wmode' value='transparent'>";
$sAttachmentString .= "<param name='flashvars' value='file=".$mp3->guid."'>";
$sAttachmentString .= "<embed ";
$sAttachmentString .= "id='single".$mp3->ID."' ";
$sAttachmentString .= "name='single".$mp3->ID."' ";
$sAttachmentString .= "src='".get_bloginfo('template_directory')."/jw/player.swf' ";
$sAttachmentString .= "width='470' ";
$sAttachmentString .= "height='24' ";
$sAttachmentString .= "bgcolor='#ffffff' ";
$sAttachmentString .= "allowscriptaccess='always' ";
$sAttachmentString .= "allowfullscreen='true' ";
$sAttachmentString .= "flashvars='file=".$mp3->guid."' ";
$sAttachmentString .= "/>";
$sAttachmentString .= "</object>";
$sAttachmentString .= "<a href='".$mp3->guid."'>Download</a>";
$sAttachmentString .= "</li>";
endforeach;
$sAttachmentString .= "</ul>";
endif;
$sAttachmentString .= "</div>";
if($echo){
echo $sAttachmentString;
}
return $sAttachmentString;
}
add_shortcode('attachment icons', 'get_attachment_icons');
Always Show Folders in Windows Explorer
Are You sick of clicking on the “Folders” button to see the folder tree everytime you open Windows Explorer? Here are the simple steps to make that folder tree show by default.
- Click Start > Control Panel > Folder Options
- Click the File Types tab.
- Page down until you locate the icon that looks like a folder in the “Extensions” column.
- It will have the word “(NONE)” after the icon and the “File Types” column will show Folder. Not “File Folder”, but just “Folder”. Select that entry and click the Advanced button. From that window you can set the default action to “explore” and click “OK”. Click “OK” again to close out of the Folder Options.
Now you will see the split view everytime you open Windows Explorer.
Show Empty Table Cells with CSS in Internet Explorer
When you create a html table and apply a border using CSS, then the empty cells do not have a border. So you pull out your CSS book and find empty-cells:show; and think your problems are solved but empty-cells is unsupported in IE…go figure. But I have found a combination of styles that work. Try this…apply the border-collapse:collapse; and empty-cells: show; to the table level and IE will display borders around empty cells.
Tags: CSS
Firefox and integrated Windows Authenication
If you need Firefox to work with integrated Windows Authentication do this:
- Open Firefox and go to about:config
- In the filter type network.automatic-ntlm-auth.trusted-uris or just scroll down until you find it.
- Double click that line and put in the name of the server you want to use windows auth. Ex: localhost,.tgrayimages.com (multiple sites separated by commas)
- Click OK and restart Firefox
Yipee! Now you can uninstall IE! (just kidding)
Updating ColdFusion MX 7 for 2007 DST Changes
The Energy Policy Act of 2005 officially changed the start and end dates for Daylight Savings Time (DST) in the US this year (2007). DST started at 2:00AM on the 2nd Sunday in March (03/11/2007) and ends the 1st Sunday in November (11/04/2007). These dates will affect all versions of ColdFusion (5.0-MX 7).
I admit I’m a little late applying this patch but oh well. Here are the steps I took to update CFMX7.
Download the Java 2 SDK 1.4.2_11. Run the install and place it (to simplify the path) in the root of your C: drive (c:\j2sdk1.4.2_11 for example)
Now you need to update the JVM that shipped with ColdFusion. To do this you need to edit one line in the jvm.config file. The jvm.config is where VM configuration settings are stored and is located in the cf_root\runtime\bin directory for the single server configuration and jrun_root\bin directory for the multiserver configuration of ColdFusion using JRun as the application server. The jvm.config recognizes an argument called “java.home”. The “java.home” argument accepts a value of the path to your JRE. For example:java.home=C:/CFusionMX7/runtime/jre. When you upgrade your JVM, this argument must reflect the path to your new JRE. For example: java.home=C:/j2sdk1.4.2_11/jre.
Restart all your Coldfusion services and download and run the dstDate.cfm script to test that everything works.
The following table displays the results of a properly patchedColdFusion MX configuration:
Today | March 11
(New DST Start) |
Apri1
(Old DST Start) |
October 28
(Old DST End) |
November 4
(New DST End) |
|
---|---|---|---|---|---|
Dates | 03/29/2007
3:00:00 AM EST |
03/11/2007
3:00:00 AM EDT |
04/01/2007
3:00:00 AM EDT |
10/28/2007
3:00:00 AM EDT |
11/04/2007
3:00:00 AM EST |
DST ON | Yes | Yes | Yes | Yes | No |
technorati tags:ColdFusion
Print Monitor is Unknown
Problem:
When installing a networked printer on Windows Vista RTM you recieve a “The Specified Print Monitor is Unknown error”.
Solution:
This is what fixed the problem for me.
1. Enable UAC (Go into the control panel and type UAC in the search bar then follow through the ‘wizard’) – restart your computer when prompted
2. Install the printer
3. Disable UAC
Yipee!!