Saturday, July 5, 2014

Generating certs for testing PDF signing

Run the following as root:

openssl genrsa -out ca.key 2048
openssl req -new -key ca.key -out ca.csr
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt
openssl pkcs12 -export -in ca.crt -inkey ca.key -name ca -passout pass:password -out ca.pfx

Wednesday, June 18, 2014

Good to know: PostgreSQL records to single JSON string

To convert a set of results to a single JSON string, use:

SELECT
ARRAY_TO_JSON(ARRAY_AGG(ROW_TO_JSON(ROW)))
as DAT FROM (
     [ your query here ]
) ROW;

Tip: In the query, if you specify field names or table.*, you will not get an object hence the JSON will not have your schema sub grouped by object name. i.e.

SELECT
ARRAY_TO_JSON(ARRAY_AGG(ROW_TO_JSON(ROW)))
as DAT FROM (
     SELECT mytable WHERE [ ... ]
) ROW;

 ... is not the same as ...

SELECT
ARRAY_TO_JSON(ARRAY_AGG(ROW_TO_JSON(ROW)))
as DAT FROM (
     SELECT mytable.* WHERE [ ... ]
) ROW;



Kudos: http://hashrocket.com/blog/posts/faster-json-generation-with-postgresql

Tuesday, June 10, 2014

Script to remove jpg files recursively

I am using a webcam which uploads files via FTP. Unfortunately the cam which uploads the files does not clean up old files. It's actually a set of cameras which all write file to their own directory structures. So when I need a script to clean up the old jpg files it needs to run recursively:

 #!/usr/bin/env python  
 import re  
 import os  
 __dir__ = os.path.dirname(os.path.realpath(__file__))  
 def cleanup_recursive(_dir=__dir__):  
   print "Cleaning " + _dir  
   for _item in os.listdir(_dir):  
     _path = _dir + "/" + _item  
     if os.path.isfile(_path) and re.match(".+\.jpg$", _path):  
       os.remove(_path)  
     elif os.path.isdir(_path):  
       cleanup_recursive(_dir)  
 cleanup_recursive()  

Thursday, June 5, 2014

Remove Bitdefender from OSX (App Store version)

Bitdefender for Windows is a highly rated application, but I can tell you from personal experience, on OSX, it's pretty much garbage. Furthermore, the App Store version does not come with an uninstaller the same way the download (from their site) version does. After following their recommended way of removing the app you may want to remove other files also. Remove this folder: ~/Library/Application\ Support/Bitdefender\ Virus\ Scanner And this file: ~/Library/Saved\ Application\ State/com.bitdefender.BitdefenderVirusScanner.savedState The issue that I, and other nay sayers on the App Store, have with BD AV is that it completely locks up your system when running a full scan, essentially making it about as bad as some viruses. I'm using ClamXAV now instead.

Tuesday, June 3, 2014

PostgreSQL:: Find functions containing

Sometimes when you need to find a function which contains specific text in the definition or description, it's handy to have a function that makes that possible.

Here is a function that will allow you to do just that:


 /**  
 DEFINE  
  */  
 CREATE OR REPLACE FUNCTION my_admin_schema.sel_function_containing(_schema_name text, _search_value text)  
  RETURNS TABLE (  
   schema text, sproc_name text, arg_names text, return_type text, description text, definition text  
  ) AS  
  $BODY$  
 BEGIN  
  RETURN QUERY   
   WITH funcs AS (  
     SELECT  
       n.nspname::text AS schema  
      ,proname::text AS sproc_name  
      ,proargnames::text AS arg_names  
      ,t.typname::text AS return_type  
      ,d.description  
      ,pg_get_functiondef(p.oid) as definition  
     FROM pg_proc p  
      JOIN pg_type t on p.prorettype = t.oid  
      JOIN pg_description d on p.oid = d.objoid  
      JOIN pg_namespace n on n.oid = p.pronamespace  
     WHERE n.nspname = _schema_name  
   )  
   SELECT *  
   FROM funcs  
   WHERE funcs.definition ~* _search_value  
     OR funcs.description ~* _search_value  
   ;  
 END; $BODY$ LANGUAGE plpgsql STABLE COST 100  
 ;;  
 /**  
 EXAMPLE USAGE  
  */  
 SELECT * FROM offerpoint_admin1.sel_function_containing('my_app_schema', 'status')  
 ;;  

Thursday, November 21, 2013

iFail


I know iTunes on my MacBook is missing some songs I just purchased on my iPad, so I click the menus .. "Store" -> "Check for available downloads" and it tells me "All purchases have been downloaded..."
Huh!? well, next when I go to the Purchases screen (a list of my purchases) and choose to filter by "Not in My Library" it shows me my available downloads. Am I nuts?? Sure enough, I click "Check for available updates" again and again I am told. "All purchases have been downloaded ..."

They should rename this app to iLie.

Saturday, November 9, 2013

OS X Mountain Lion Server - Profile Manager / Wiki, Start Up Errors

Errors which relate to the issue (separate error on each separate line below):

ProfileManager[1318]: Retry #[n] of database migration...

devicemgrd: Terminating on unhandled exception Rake command failed with 256 at /Applications/Server.app/Contents/ServerRoot/usr/share/devicemgr/webserver/devicemgrd ...

The error occurred while reading settings for the Profile Manager service.

servermgr_wiki: No attempt was made to create Wiki file data store directory

References I used to try to fix the issue from other folks having similar issues:

https://discussions.apple.com/message/23350331#23350331
https://discussions.apple.com/message/19515803#19515803
http://forums.macrumors.com/showthread.php?t=1411450
https://discussions.apple.com/message/23190851#23190851
https://discussions.apple.com/message/20334099#20334099
https://discussions.apple.com/thread/3189397?start=30&tstart=0
http://support.apple.com/kb/ht5139 (this was too drastic in my opinion to even consider)

The real problem:

I used to have my Server Service Data on an external volume mounted at /Volumes/OSXServerData. To keep the Service Data for Profile Manage, the Wiki, and indeed all server services, on another volume other than the startup volume, one simply needs to open Server.app, select the host, click Settings then click the Edit button the same line where it says "Service Data:" and shows which volume the Service Data is currently on. Please refer to this URL for more info: http://support.apple.com/kb/HT4974 -- It is important to note in that page that is says:

"Important: Do not change the name of the service data storage volume after you designate it in Server app."

For one thing, this means that you should not edit this setting, AFTER you have already removed or renamed the volume. Apple requires that you change the Service Data volume BEFORE removing the volume. For one thing, this is so that the functionality in the server app can copy the Service Data from the original location to the new volume you designate. There us a fundamental flaw to Apple's design herein. If the volume (disk) has crapped out you have little choice, but to specify a new volume without "change[ing] the name of the [current] service data storage volume" - that is because your crapped out drive where the service data was, is no longer accessible - obviously.

No worries. I just expect that once I specify a new volume, that Server.app will recreate the default settings in the new location. After all, the new volume does correctly show in the Settings tab after it is set. And indeed it does create the /Library/Server/ folder on the new volume .... and as expected, it is filled with all the goodies one would expect to see there. It gives the perfect appearance that it has successfully configured Server to use the new volume.

Alas, that is a lie. Keep in mind that the volume that crashed was mounted at /Volumes/OSXServerData thusly, the location of the service data used to be /Volumes/OSXServerData/Library/Server/.Upon deeper inspection of the log files, I found the following types of errors:
postgres dataDir /Volumes/OSXServerData/Library/Server/PostgreSQL For Server Services/Data does not exist as directory
.. and ..
Configured wiki FileDataPath /Volumes/OSXServerData/Library/Server/Wiki/FileData does not exist as directory
This basically told me that Server.app failed to reconfigure the volume path when the new Service Data volume was specified.

So what I had to do was search /Library/Server for any files containing the old volume mount point. Invariably they would be either config files, old config files which Server.app deprecated, or log files.
I used mc (Midnight Commander) to locate those files but you can use Finder to whatever you want to. Once I obtained the list of files, I used sudo nano /Library/Server/... and the path to the particular configuration file, to edit the path information which needed to be fixed.

The files you are looking for here end with .conf, .xml or .plist and are typically located in a Config sub directory.
Some examples are:
/Library/Server/Messages/Config/jabberd/router.xml
/Library/Server/Messages/Config/jabberd/sm.xml
/Library/Server/Mail/Config/dovecot/conf.d/10-mail.conf
/Library/Server/Software\ Update/Config/swupd.conf
/Library/Server/Calendar\ and\ Contacts/Config/caldavd.plist
/Library/Server/Mail/Config/dovecot/partition_map.conf
/Library/Server/Wiki/Config/collabd.plist
/Library/Server/Software\ Update/Config/swupd.plist

I simply ignored the files which has ".bak", "unusable" or "previous" in the path because these are obviously deprecated. Then I restarted the host and everything worked again.