Here is a bit of Cocoa code, take what you want and enjoy!
Current Contents:
CSVEdit is my first attempt to produce a Cocoa application that I could actually
use. It is a "Comma Separated Values" text file editor. It can be started by:
Spirolateral is a simple program that draws pretty patterns. The algorithm is fairly
simple, take one step, turn some fixed angle, take two steps in the new direction turn...
repeat this x times and then repeat the whole process from where you ended up y times. I
recommend that you start with an initial length of 10, the turning angle should be given
in degrees, all of the input values should be integers. Under the edit menu there are items
that will allow you to set the background color and the pen color.
BiggerSQL v1.3.9 is yet another Postgresql database utility. It allows the user to browse
Postgresql databases, execute sequences of SQL statements and define and execute PL/pgsql
functions. The results of queries can be saved in a variety of formats for use in other
programs. Feedback/fixes/suggestions welcome.
Feb 14, 2008 It has been several years since 1.3.8 was released. This newer version is a Universal build that should run on Tiger and Leopard systems. The embedded postgresql documentation has been updated to Postgresql 8.3.
Aliases are now (hopefully) properly resolved. The user can drag an alias onto the editor window and the actual file will be opened. An alias can also be dragged onto the Application icon and the original file will be opened. If an alias file or folder is dropped into the Scripts folder the actual files will be loaded when selected from the Script menu.
The history file is now capped at 50 entries and is remembered across invocations of the application. There is a new menu item "Clear Statement History mm (nn)" in the Edit menu that will clear the history list. The number in the parenthesis is the number of items in the history list. The other number is a pointer into the list for the previous/next menu items. Note clearly that selecting this menu item will clear the entire list.
Column titles are now centered. I attempt to right justify all numeric data in the displayed tables.
This release features an interface to the psql client. When BiggerSQL starts it searches for psql in ~/Library, /usr/local/bin, /usr/local/pgsql/bin in that order. If you have psql located in another location you can put a symbolic link into your personal Library directory.
There is a new menu item "Send To Psql" in the File menu. If there is a nonempty selection and psql was found then the menu item will be "active". Choosing this menu item will send the selected text to psql for processing. The status and error infomation will generally be shown in the status window and the results will be displayed in the editor window. No timing information will be shown in this case. The way this works is that when the menu item is picked, a new process is generated that executes the selection and returns the results to the program. The command is more or less displayed in the status window and will look like:
Launched: /usr/local/bin/psql -U <user> -d <database> -c <selection>
Note that this is a "one shot" action, the command executes, returns the results and then terminates. Each command should be thought of a single independent session. You need to read the man page documentation for psql for the limitations of this interface.
Notice that there is no password present in the launch command. If your Postgresql system uses passwords you will need to set up a ".pgpass" file in your home directory. See the Postgresql documentation for the format for this file.
You can have sql statements or "meta" commands in the selection, but not both. The editor window has been reconfigured so that instead of wrapping at the margin a horizontal scroll bar will appear and you can scroll all the way to the end of the table.
The main reason for this interface was to gain access the to the cool features of psql. Using this interface BiggerSQL can now easily deal with large objects, use the \copy command, retrieve PL/pgSQL function definitions and much more.
Meta commands, psql commands starting with a' \ ' , are now recognized on the fly in the edit window, so if you enter the command \d+ <yourView> and execute the command as a sql command ( see above for the various ways to do this). The meta command will be diverted directly to psql and the results will appear in the edit window.
In this case the timing information will show but is not relevant. The psql command executes independently of BiggerSQL and the output is written to the window as it becomes available. It is probably the case that if you had several metacommands operating at the same time the output could be interleaved in the editor window.
Fixed the login failure message to specify the reason for the failure.
BiggerSQL now notes the completion of a psql task and displays the final command status in the status window. In addition the psql pid is displayed in each message and the lapsed time in milliseconds for the task is displayed in the task termination message. Note that if the user were to enter the "\c" connect meta command, the status window will show a request for a password. Since there is no way to send a password the process must be killed. This can be accomplished by entering the shell command "kill pid" as a meta command ie \! kill <pid of the process>.
As noted earlier, a sql command can be processed by psql. It is interesting to see the overhead that passing information back and forth adds. I have a query that takes about 34 seconds when executed in the "normal" fashion. When passed to psql the time increases to about 54 seconds.
The main window title now shows some connection information.
The login window now has a "port" entry in case someone is not running on the standard postgresql port.
The most notable feature of this release is support for images and large objects embedded in the database.
The standard "Window" menu has been added to help manage the extra windows introduced in this version.
A new contextual menu has been added. If the user <control>-clicks on the display grid, a contextual menu will be displayed. The menu items that are currently available are "Show As Text", "Show As Bytea Text". "Show As Image", "View Oid As Text Object", and "View Oid As Image Object".
Each of the menu items act on the contents of the table at the location of the <command>-click.
The Show As Text action will display the contents of the specified field in a separate (scrollable) text window. Very large fields can easily be viewed in this window.
The Show As Bytea Text passes the contents of the selected field through PQunescapeBytea to replace strings that had been escaped when copied from the bytea field ( ie \012 is replaced by the newline character.
The Show As Image action will interpret the field as an image ( most of the common formats as supported) and display the image in a separate window. The Copy command in the Edit menu can be used to place a copy of the image on the clipboard. It is assumed that images are stored (unescaped) in bytea fields. Note that the fields will show in the grid as an escaped string. This string can easily be three times larger than the original file. SQL like "select * from myFavorite1000Pictures" will lead to unnecessary grief and pain.
The View Oid As Text Object will display the contents of the large object represented by the oid in a scrollable text window.
The View Oid As Image Object will display the contents of the large object represented by the oid in a scrollable image window. Again the image can be copied to the clipboard.
It is the users responsibility to choose the appropriate option from the contextual menu. (I have tried the "wrong" choices and have noticed no ill effects.)
Note that there are two new windows, one for displaying text and another for displaying images. The windows are reused as appropriate and closing the window only hides the window.
As noted earlier, storing images as bytea fields can slow the program down very quickly. Having a row element in the display grid with multi megabyte sizes is not very practical. To ease the pain a bit, there is a new menu item in the File menu "Suppress Long Fields".
When this item is checked, fields in the display grid will show <LoNg FiElD:nnn> when the field length is greater than 200 bytes. The number after the colon is the actual length of the field. The actual data is still available when the contextual menu is used. The state of this item is saved across invocations of BiggerSQL
Be aware that libpq is used to retrieve any selections from the database, so that the entire selection is stored in memory. If you have a large photo database make your selections with an eye toward how big the entire selection will be.
The imageView and textView windows have a small contextual menu. <control>-clicking on either of the windows will bring up a "Save As Text..." or "Save As Tiff..." menu. The user can then save the contents of the window.
This version uses a newer version of Andreas Mayer's Shell Wrapper. A message is now posted when starting if psql is found.
BiggerSQL is now multimedia aware. The contextual menu obtained by control clicking the results grid now has two new menu items.
1) View Oid as QuickTime Asset 2) View Bytea as QuickTime AssetThe "View Oid as QuickTime Asset" menu expects that you have a oid of a large object that contains a multimedia file that QuickTime can understand. QuickTime can interpret well over 100 different types of mutlimedia, but it needs a little help. A dialog will appear asking for a hint for the contents of the large object. The hint consists of naming a file extension that typically would be used if the data were stored in a file. So you might respond with:
.mp3 if the media was the representation of an mp3 file or .mov if the media was a QuickTime movie .jpg if the media was a jpg picture.Since QuickTime assets can be very large, when the Quicktime window is closed, the resources associated with the window are released. In any case the user has to be careful about memory usage.
By default, a NSMovieView scales the object to fill the view. Thanks to Douglas Welton, I have been able to scale the content proportionally. This might be useful for view large pictures.
Note that since the asset is scaled that a black bar will probably appear of the top or right side of the Quicktime window due to the mismatch of the proportions.
The "View Bytea as QuickTime Asset" menu item works in an identical fashion except the cursor needs to be over a bytea item when the contextual menu is invoked.
I have added an experimental item to the File menu "Start A Copy Of BiggerSQL". The menu item does start a copy of BiggerSQL. Be careful how this is used, Both copies share the same preferences and of course a copy will cause twice as much memory to be used.
I fixed a problem where output from psql commands would dramatically slow down as the size of the output grew.
BiggerSQL now offers a File menu item "Do Live Scrolling of Psql Output". If checked, output from commands sent to psql will be displayed as received from the command. If not checked then the display will not scroll until the command has completed. For commands that generate large amounts of output suppressing the scrolling can cut the time to command completion by up to 75 percent.
There are two new items in the contextual popup menu that will also invoke the web browser. "View Bytea Field as HTML" and "View Text Field as HTML". Invoking either of these menu items when the cursor is over the appropriate field will bring the browser forward and attempt to display the contents of the field in the browser.
I have been using this feature to view html based email stored in one of my postgresql databases.
I have also used the embedded browser to interact with a database via cgi's without having to start a full blown browser.
There is also another new item in the contextual menu "Save Bytea Field..." . Choosing this item will allow the user to extract a bytea field into a user named file.
One caveat: This version was built against Version 8.0.0 Beta 3 of the Postgresql system. I did not have to make any changes in the source to accommodate this change. I do not think this should cause a problem...One early tester has found no problems on a version 7.4 database.
dailyWakeup version 1, released March 21 2004,is a command line program that will
allow the user to queue a wakeup request to their Macintosh. I use the program to wake
up my Mac a couple of minutes before each cron job is scheduled to run. My crontabs are set to fire at
1:15am daily, 4:30am weekly on Saturday and at 5:30am on the first of every month. The first
time dailyWakeup is run it queues a wakeup call for 1:12:30 the next morning. Then I created
a file, /etc/daily.local. The contents of this file are executed by the cron daemon at 1:15.
The contents currently look like this
/usr/bin/mail -s Crontab jerry <<DOC Cron ran at `date` `/usr/local/bin/dailyWakeup` DOCWhen this script is executed by cron, it sends mail to me and queues another wakeup for the next morning. When dailyWakeup runs it also checks to see if it is Saturday or the first of the month and will queue wakeup requests for the later cron jobs. If you are not familiar with how cron works this might ( in any case ) require you to read the man pages. The dailyWakeup program must be run as root. If you power down your machine and miss a daily cron call you will need to manually run the dailyWakeup program to get back in sync. Hmmm, looks like a system startup script for dailyWakeup needs to be written...
Startup script for dailyWakeup. This is a system startup script for dailyWake up.
Suggested use:
ShowPMQueue version 1.0 released March 21, 2004 is a program that lets a suitably
privileged user manipulate the Power Manager Event Queue. The program lists all oll of
the scheduled events in the queue. When an event is clicked the "delete" button will
activate and a suitably privileged user can delete the event. There is also an "schedule"
button that will bring up a dialog that a suitably privileged user can use to specify
the time, an identification string, and an event type ( wake, sleep, powerdown, restart and
wakeorrestart) selecting OK will queue the event.
What is a "suitably privileged user"? The program needs root privilege in order to delete
or add an event. Unfortunately, I do not understand the authentication/security mechanisms
built into the operating system. This means that I have to either set the executable to
be owned by root and set the suid bit or drop into the applications folder and directly
execute the actual compiled file as root. No privilege is required to simply view the
queue. I hope some kind soul will show me how to "get root" in a more convenient fashion.
Source code is included.
[time passes...]
PMQueueManager version 1.1a released April 5, 2004. This is a reworked version of
ShowPMQueue that uses the Security Manager to authenticate users prior to adding or
deleting power manager events, ie the user has to supply an administrative username
and password. This application can be moved to any location and will still work. Be sure
to read the ReadMe in the project, it contains important info on building and using the
application. The download contains all of the source code and there is a prebuilt version
of the application in the Build directory of the project.
Changes From Version 1.1
Changes From Version 1.0
keypress.c
( Released April 30, 2004) is a utility
program that will restart the "time to sleep" timer that is set in the "time to go to sleep"
panel of the Energy Saver Preference panel. This is needed because if the mac is
awakened by a "wake" event and not a keypress or mouse click, the machine will fall
back to sleep in a much shorter period of time ( 2~4 minutes! ). I recently received
this clue from a kind person...I am using this by placing the following file:
400.keypress
#!/bin/sh /usr/local/bin/keypressinto /etc/periodic/{daily | weekly | daily} ( and make sure it is executable )
Since the "usual" script starts with 500, the keypress program will run before the standard default actions. My default "go to sleep" time is fifteen minutes. Currently this is enough time to do all of the assigned tasks. If you examine /var/log/system.log you will be able to see if you have enough time allocated to complete your tasks.
ImageBrower-0.96
released Jan 25, 2008 is a Cocoa program that allows the user to browse the images
contained in a user selectable directory. Once a directory is selected, thumbnails
will be constructed. The user can then view (user) scaled versions of each image by
Starting with version 0.95 there will be two prebuilt universal binaries located in the top level of the dmg, one for Leopard and one for Tiger. If you are running Leopard use the leopard version it is much more efficient for building PDFs.
Version 0.95 now supports "Graphic Novels" (aka Comics), they look great in full screen mode.
The complete Readme is here. It can also be found under the help menu.
Changes
Unfortunately the default construction of the PDF document from the image files leads to enormus PDFs. eg a 14 page 'comic' with 8 MB total size would generate a 38MB PDF!
The way to get around this problem is to apply a Quartz filter to the result. The filter provided by ImageBrowser yielded a file size of 1.8MB in the above example.
The default location for Quartz user defined filters is in ~/Library/Filters. When ImageBrowser starts it looks in the users Library/Filter directory and if the Filters directory does not exist or the file "ImageBrowser.qfilter" is not in the Filters directory, ImageBrowser will create the Filters directory, if needed, and place an internal copy of the filter in the Filters directory.
The supplied filter will lighten PDFs and do a jpg compression for all of the jpg images in the PDF.
Leopard (10.5+) makes it easy to apply the filter, the Universal SDK 10.4 tookkit (aka Tiger) does not.
The Universal build has to first write the constructed PDF ( which is more difficult to construct in Tiger) to a temporary file and then apply the filter using the program 'quartzfilter' to do the compression and write the file to the user specified location. Finally the temporary file is deleted. Leopard can do this much more easily :)
A nifty thing about the filter is that it is visable to the "ColorSync Utility" located in the Utilities folder of the Applications folder. Start the utility and click on the Filters icon in the toolbox. After you run ImageBrowser the first time, you should see a Filter named "ImageBrowser".
If you click on the disclosure symbol to the left of the ImageBrowser the to component of the filter will be displayed, "Intermediate Transform" which will lighten the PDF ( I download to an Grayscale Iliad and the PDF rendering looks a bit better to my eye) and "Image Compression". Clicking the disclosure symbol will show how much compression is performed on the images, you can modify either of the two filters ( or add one !) in the program and ImageBrowser will use the modified filter.
ImageBrowser will restore the original filter if you accidently delete it.
Send mail to me (Jerry LeVan) if you have any problems....
Counter courtesy of http://www.digits.com
Last update Feb 14, 2008