2008-11-16

Creating Self Signed certificates on Apache 2.2

openssl genrsa -out mycert.key 1024
openssl req -new -key mycert.key -out mycert.csr
openssl x509 -req -days 365 -in mycert.csr -signkey mycert.key -out mycert.cert

rm mycert.csr



2008-10-10

OS X Tiger / Leopard: Automatically Start Apps at Login

Do you always want chat or mail to start when you boot up or log on? Here is how you can make apps automatically start when you login.


If I am online, I want chat up and running. Here is how to setup a program to automatically launch when you boot up or log into your system.

1. Click System Preferences
2. Click Accounts
3. Select your account
4. Select the Login Items tab
5. Click + and browse to the app you want to start up when you do.

Alternatively, you can just run the app. Then click and hold the app’s icon in the dock, and select Open at Login.

2008-08-11

Dynamically create form elements

var createDOMForm = function () {
// Where the form will be placed into the page
var parentElement = document.getElementById("formGoesInsideThisDiv");
cleanElement(parentElement);

// Create a form
try {
var myForm = document.createElement("
");
} catch (e) {
var myForm = document.createElement("FORM");
myForm.name = "myForm";
}
myForm.method = "post";
myForm.action = "/webdev/creating_response_action";
myForm.id = "myForm";

// Create a radio selection
try {
var radioFieldA = document.createElement("");
var radioFieldB = document.createElement("");
} catch (e) {
var radioFieldA = document.createElement("INPUT");
radioFieldA.name = "myRadio";
radioFieldA.checked = "true";
var radioFieldB = document.createElement("INPUT");
radioFieldB.name = "myRadio";
}
radioFieldA.type = "radio";
radioFieldA.value = "true";
myForm.appendChild(radioFieldA);
myForm.appendChild(document.createTextNode("true"));
myForm.appendChild(document.createElement("BR"));
radioFieldB.type = "radio";
radioFieldB.value = "false";
myForm.appendChild(radioFieldB);
myForm.appendChild(document.createTextNode("false"));
myForm.appendChild(document.createElement("BR"));

// Create a checkbox
try {
var checkbox = document.createElement("");
} catch (e) {
var checkbox = document.createElement("INPUT");
checkbox.name = "myCheckbox";
checkbox.checked = "true";
}
checkbox.type = "checkbox";
myForm.appendChild(checkbox);
myForm.appendChild(document.createTextNode("check?"));

// Create a text field
try {
var textField = document.createElement("");
} catch (e) {
var textField = document.createElement("INPUT");
textField.name = "myTextField";
}
textField.type = "text";
textField.value = "text field";
textField.style.display = "block";
myForm.appendChild(textField);

// Create a textarea
try {
var textArea = document.createElement("");
} catch (e) {
var textArea = document.createElement("TEXTAREA");
textArea.name = "myTextArea";
}
textArea.appendChild(document.createTextNode("text area"));
textArea.style.display = "block";
myForm.appendChild(textArea);

// Create a drop-down list
try {
var dropDown = document.createElement("");
} catch (e) {
var dropDown = document.createElement("SELECT");
dropDown.name = "myDropDown";
}
dropDown.style.display = "block";
for (var i=1; i<11; i++) {
var option = document.createElement("option");
option.value = "myOption" + i;
option.appendChild(document.createTextNode("Option " + i));
dropDown.appendChild(option);
}
dropDown.selectedIndex = 3;
myForm.appendChild(dropDown);

// Create a multi select drop-down list
try {
var dropDownMulti = document.createElement("");
} catch (e) {
var dropDownMulti = document.createElement("SELECT");
dropDownMulti.name = "myDropDownMulti[]"; // The [] addon creates a parameter array
dropDownMulti.size = 4;
dropDownMulti.multiple = "true";
}
dropDownMulti.style.display = "block";
for (var i=1; i<11; i++) {
var option = document.createElement("option");
option.appendChild(document.createTextNode("Option " + i));
option.value = "myOption" + i;
if (i==2 || i==4) {
option.setAttribute("selected","true"); //option.selected = "true"; does not work in Opera (9.25 only?)
}
dropDownMulti.appendChild(option);
}
myForm.appendChild(dropDownMulti);

// Create a button
try {
var newButton = document.createElement("");
} catch (e) {
var newButton = document.createElement("INPUT");
newButton.name = "myButton";
}
newButton.type = "button";
newButton.value = "Send AJAX Request";
newButton.style.display = "block";
newButton.onclick = function() {
getAjaxResponse();
}
myForm.appendChild(newButton);

// Place the form into the page
parentElement.appendChild(myForm);
};

var cleanElement = function (el) {
while (el.firstChild) {
// nothing too fancy or fast here - removing all child elements to clean it out
el.removeChild(el.firstChild);
}
};

var getAjaxResponse = function () { // This function only works with MooTools
new Ajax("/webdev/creating_response_action", {data: $("myForm"), update: $("responseGoesInsideThisDiv"), evalScripts: true}).request();
};

2008-08-04

[PHP] Dying with grace: register_shutdown_function

Scripts tend to die, and that’s not usually nice. We do not want to show the user a fatal error nor a blank page (display errors off) . PHP has a function called register_shutdown_function which lets us set up a function which is called at execution shutdown. What this means is that our function will be executed when our script is done executing / dying and PHP execution is about to shut down. By setting up a variable to false at the start of our script, and setting it to true at the very end of the script we can have our shutdown function check if the script completed successfully or not. If our variable is still false we know that we never made it to the last line of our script, hence it died somewhere. I’ve prepared a very basic sample which shows how you can give the user some proper feedback if a fatal error should arise. You’d want to turn of display of fatal errors for this to look nice.

2008-07-29

Oracle: Escape "@" character

> set define off

> update ... set test="@TEST" ...

2008-07-11

C-test libraries

  • CuTest was the simplest library I saw. It is very small (a single .c and .h file), easy to deploy, and compiles on almost any compiler. The README has more documentation and some sample test code.
  • Check is a much more sophisticated framework. Tests are run in a separate address space, so Check can catch both assertion failures and code errors that cause segmentation faults or other signals. However, the interface is still fairly simple to use. Documentation and tutorial are available here.
  • Some of the others I found were Gnu AutoInit and cUnit but both seemed more convoluted to use and harder to deploy since both require the use of glib (Gnome Library) which essentially means they will only deploy on Linux.

2008-06-19

Oracle: Get table and index DDL the easy way

set pagesize 0
set long 90000
set feedback off
set echo off

spool scott_schema.sql

connect scott/tiger;

SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name)
FROM USER_TABLES u;

SELECT DBMS_METADATA.GET_DDL('INDEX',u.index_name)
FROM USER_INDEXES u;

spool off;