Textpad Document Classes

Textpad is my preferred text editor. It is super-simple, but has a few advanced features that really make writing source code for various things so much nicer. Besides that it has coloring for various document classes.

Document classes are basically groups file extensions whose properties can be changed for each group. Example: you can completely change the coloring, paragraph options, tab-width and printing properties for HTML files only. Or you could add line numbers to Java script files and leave line numbering out for everything else. Or perhaps the PHP comment is not the same as the html comment (which it isn't! HTML comments look like this: <!-- Stuff --> and PHP comments look like this: // stuff or /* more stuff */.

Since I've been doing a lot of PHP scripting I was growing tired of looking at their comments and having them displayed as regular text (coloring-wise). So I decided to try and figure out how to add // and /* */ to the comments part of the HTML class (which was where the PHP file extension was located). Editing these options was conveniently located in a few preloaded syntax files (html.syn, text.syn, etc). What I found was much much cooler. I found out how to create an entirely -new- document class and was able to apply the php.syn file to it! Now the coloring on all php documents is specialized to that particular programming language!

Below is the process I took to create the PHP Document Class, although this can be applied to any filetype that you may want to open in Textpad:
  1. Make sure all internal files are closed or you will not be able to add a new document class.
  2. Go to Configure/Preferences.
  3. Click the Document Classes listing (top-level).
  4. Click the Add button. If the add and delete buttons are not available, you still have a file open in the current Textpad session.
  5. Type PHP in the empty box that appears at the bottom of the list and Enter.
  6. Click apply. Your new Document Class entry should appear in the rollout of the "Document Classes entry.
  7. The new entry should inherit the properties from the Default Document Class.
  8. Under the Document Classes listing, select the new PHP entry.
  9. Under the "Files in Class PHP" window, click the "New" button and type *.php. Enter to apply. Also add an entry for *.phps.
  10. Rollout this new PHP Document Class entry.
  11. Select the Syntax entry.
  12. Check Enable Syntax Highlighting. This will enable the Syntax definition file pulldown.
  13. Pull down the "Syntax definition file" box. Select "php.syn" and say OK.
  14. Close all Textpad sessions and re-open a php file to see the changes. Verify that /* */ patterns are the comment color and that () {} and [] are the brackets color.
  15. Optional: If you plan on printing your php sources, you may want to include line numbering.
  16. Select the Printing entry.
  17. Check the Options>"Line Numbers" box.
Other options in a Document Class include a lot of dealing with end-of-line behavior. The important one that I noticed in the HTML Document class (which was NOT included in the default) was the top-level option of "Strip trailing spaces from line when saving". One other option that I just now decided to explore was the Tabulation entry. This is just a way of determining how big the tab character should be in number of spaces. If you look at the Java entry (which cannot be deleted), you will see that it has a default tab spacing of 4 characters and an indent size of 4 (contrary to the Default document class which is at 8). Therefore, I decided to copy the Java values into the PHP Document Class.

And in the time it's taken to write this article, I've also added a class for CSS files, since they're not included ANYWHERE!

Anyhow, hopefully this clarifies this type of thing for someone.

Preventing constant reboots on a network

For some weird reason, I found that my router (Netgear WNR3500L) (or my connection) was giving me problems...every so often it my LAN connection would completely reset and require me to reboot the computer, just to get the webserver back online (it would become completely unreachable via No-IP DNS -and- the external IP address..some 5xx connection reset error or something).

Recently I found that the problem was my router. The DHCP server built into it has a set lease time of what my connection says is 24 hours, although it only lasts about 12. I found a workable solution, yet it was rather annoying. I set up my Telnet server to automatically shut down every 12 hours, as well as the client that was accessing it. On top of that, I used Windows Scheduler to run reboot.cmd a minute after the server was shut down, and then used TweakUI to automatically log me back in, plus another command-line script that would autolock the computer after logging in. This way all the applications would be preloaded, but the computer would still be secured.

Got all that?

1. Telnet shutdown
2. Telnet client shutdown
3. Computer shutdown and reboot
4. Autologin (starting all the servers up again)
5. Autolock

DHCP is renewed, the connection is reset, and 100% accessible over the web.

The Telnet server is called PennMUSH, which is a Multi-User RPG engine which uses the common MUSHCode language to program.

For archival purposes, here's the detailed setup:

PennMUSH:
@@
@listen Shutdown Machine = ^-*: @switch [or([strmatch(%0,00)],[strmatch(%0,12)])] = 1,{@wizwall Shutting down.;@dump;@wait 30=@shutdown};@@ * is passed from the clock hourly as timefmt($H) <= The 24-hour hour code.


MUSHClient:
<timers
muclient_version="4.70"
world_file_version="15"
date_saved="2011-04-05 14:32:04"
>
<timer enabled="y" hour="00" minute"1" second="0.00" offset_second="0.00" send_to="12" at_time="y" >
<send>DoCommand Save("")
DoCommand Exit("")</send>

</timer>
<timer enabled="y" hour="12" minute="1" second="0.00" offset_second="0.00" send_to="12"
at_time="y" >
<send>DoCommand Save("")
DoCommand Exit("")</send>
</timer>
</timers>

reboot.cmd:
@echo off
echo Shutting down
shutdown.exe -f -r -t 30


autolock.cmd:
@echo off
echo Locking computer
rundll32.exe user32.dll, LockWorkStation
Scheduled Tasks:
Add one task to run reboot.cmd. Copy the event within the single task and schedule them to run at 12:02 am and 12:02 pm.
Complicated enough? I figured out a MUCH easier solution
Ctrl Panel>Network Connections>Local Area Connection>Internet Protocol (TCP/IP)>IP Address: 192.168.0.2, Subnet: 255.255.255.0, Gateway: 192.168.0.1, DNS: 192.168.0.1

In essence, setting a static IP behind the router turned of the DHCP lease time for this connection.

I had to do a bit of tweaking in the router config, like releasing the reserved IP for both the laptop (which was using 161.0.0.2) and the server computer (which was using 161.0.0.3) and reserve the first to the server computer based on its MAC. This way the router won't try to assign my manually-entered IP address to another computer and cause an IP conflict error (which can happen).

I've now had the server on for a day and a half (turning off all of this automatic shutdown-reboot stuff) and everything has continued to run with success!