Saturday, September 15, 2012

Creating Icon for iPhone app in Xcode 4.4

Create a png image with name below resize it to 57x57 using from command prompt (terminal): sips -z 57 57 icon.png Drag and drop to the project by clicking on the target, opening the summary panel, and dragging and dropping to the app icon section. Will test this with other image file names, sizes, and formats, but for now, this works

Sunday, August 21, 2011

Click on Element within a Frame using AHK

The syntax is tricky and threw me off this project for months. I finally have cleared it up, and here it is for posterity:

The syntax for plain javascript, executable from internet explorer DebugBar v5.4.1 is:
document.parentWindow.actualframename.document.getElementByID("actualID").click()

In distinction, the syntax for AHK COM SCRIPTS is:
COM_Invoke(pwb, "document.parentWindow.actualframename.document.getElementByID[actualID].click")

NOTICE (I usually don't shout, but in this case I will make an exception): THE ARGUMENT OF getElementById IN JAVASCRIPT IS ENCLOSED IN PARENTHESES AND QUOTES. THE SAME ARGUMENT IN AHK IS ENCLOSED INSTEAD IN BRACKETS AND NO QUOTES. ALSO THE METHOD IN JAVASCRIPT HAS PARENTHESES AFTER IT click() WHEREAS IN AHK IT DOES NOT click (THE REASON FOR THESE DIFFERENCES IS THE AHK COM_Invoke FUNCTION, WHICH REQUIRES ARGUMENTS CONTAINED IN PARENTHESES AND QUOTES.)

Also it is worth saying what is the quickest way to find the actual frame name (yes it is the name, not the ID) and the actual element ID (yes ID, not the name). Answer: A magnificent AHK script called iWebBrowser2 Learner Build 2.5, by "Tank, Jethrow, and Sinkfaze" of the AHK forum. Just hover over the element until it has a red box around it, and read the answer in the dialog box.

More info can be found at these forum posts: (primer on COM functions, and link to the all-important GetWebBrowser() function the COM functions depend on)
http://www.autohotkey.com/forum/topic51020.html
http://www.autohotkey.com/forum/topic24930.html

Thank you Sean, Tank, Jethrow, and Sinkfaze, whoever you are.

Saturday, January 8, 2011

Transparent Images for FPDF

This post is really to help me remember the layers of FPDF class extensions I am using.
Remember that FPDF is a class defined in the fpdf.php file and contains many useful functions for manipulating pdf files. These functions can be called by the syntax

$pdfobject->function();

class FPDF_TPL extends FPDF
class FPDI extends FPDF_TPL
class AlphaPDF extends FPDI

The AlphaPDF class (alphapdf.php) is a small script courtesy of Martin Hall-May and is found at
http://www.fpdf.de/downloads/addons/74/
It was originally written as an extension of FPDF but I modified it to be an extension of FPDI so that my pdfobject can call functions both for purposes of importing PDF images, and superimposing gif images using the marvelous SetAlpha() function, as described below

// alpha: real value from 0 (transparent) to 1 (opaque)
// bm: blend mode, one of the following:
// Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn,
// HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
function SetAlpha($alpha, $bm='Normal')

Thursday, January 6, 2011

More on using MacBook Pro (Snow Leopard) as a Server

You can actually turn a MBP into a WiFi hot spot with the built-in software. Here's the trick:
System Preferences -> Sharing -> Internet Sharing checkbox -> Share your connection from Ethernet
You see AirPort pop up as an option. Click it and click on Airport Options and VIOLA you can configure your MBP to be a router!
You can create a network name, a password, and select level of encryptation. Remember to activate the Internet Sharing checkbox again at the end to "start" the WiFi hotspot.

This was designed to allow you to pipe your ethernet broadband internet connection wirelessly to other devices in the neighborhood, the great thing is even if you do NOT have the ethernet port connected to anything, it will still broadcast a WiFi signal and you can use the local computer name (name.local:8888) to browse to the MAMP server in the MBP.

Why would anyone want to do this? The answer is sometimes you want to browse to the server on a handheld device, even when you are not connected to a local WiFi hotspot. One way is to leave the server behind, at a hotspot, and browse to it using 3G, using methods described previously. But NOW, even if you have a WiFi ONLY device such as an iPod or iPad that doesn't have 3G, if you bring the server with you, you can still run your server scripts on the handheld.

The only problem being: even with the MBP lid closed? The answer is yup, but you have to run a free software called InsomniaX to keep the MBP running even with the lid closed.

Remember, Airport can only go one way at a time. You gotta turn off Internet Sharing to restore Airport to a receiver (instead of a transmitter) once you use it. Crazy.

Friday, December 31, 2010

PHP Script to send PDF file as attachment (requires FPDF object)

function mail_pdf_as_attachment($pdfobj,$faxnumber) {
$pdfdoc = $pdfobj->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
$to = "destinationaddress@destination.com";
$from = "sourceaddress@source.com";
$subject = $faxnumber;
$message = "See attached pdf file";
$separator = md5(time());
$eol = PHP_EOL;
$filename = "medfax6.pdf";
//headers
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
mail($to, $subject, "", $headers);
}

Dual Formatting of External Hard Drives (PC and MAC)

You can do that?? It turns out, yes.

Plug the drive into a USB port on the mac. Go into Disk Utility (You can find the utility fastest by clicking on the "magnifying glass" shaped icon on the far upper right corner of the screen, which is called Spotlight, and typing Disk Utility.

Then partition the drive, selecting the option to create 2 partitions. This will format the external drive. Select mac formatting for one and MS-DOS FAT for the other. The trick is go go into "Options" after you enter the Partitions tabs and under options select the bottom of the three options, which allows you to create a root directory that will allow the MS-DOS partition. Otherwise, it isn't even an option.

After being done formatting, you will see both partitions on the mac with their assigned names, and if you plug into a PC you will only see the PC partition with its name and letter, like E: as assigned by the PC.

Hosting Content on the World Wide Web on a Laptop

I have a Macbook Pro (MBP) running Snow Leopard. It is connected to the internet through a wireless router. I am running MAMP on it and using it as a server, and I access the server from the iPhone, or the iPad, from WITHIN the LAN (behind the router) via the Wi-Fi connection to that router. Wouldn't it be nice to be able access that same server remotely, from OUTSIDE the LAN, via, say, a 3G connection?

Three steps to doing this:
1. Find out what the IP address is (whatismyip.com)
2. Tell the ROUTER to assign a static IP address to the MBP within the LAN
login to router as admin ->LAN setup->Use Router as DHCP Server->Address Reservation
In my case, I just selected the address it had randomly assigned to make it permanent (192.168.1.18)
You need to know your computer's name and/or mac address to do this, so that you select the correct computer.
3. Then you need to go to port forwarding (still in admin in the ROUTER settings), and assign start port 8888 to forward to end port 8888 on 192.168.1.18.

Finally, step outside the LAN and browse to:
ipaddress:8888/homefolder/index.php
and you are there.

CAUTION: if you do this and leave your server on, your precious MBP is on the world wide web, and can be subject to cyber attack. It helps that the port is not 80, or 8080, which are far more common, but still, take precautions.