pulsar's blog

Disable the close button for a dojo / dijit.Dialog

  1. dojo.provide("myWidgets.Dialog");
  2.  
  3. dojo.declare
  4. (
  5. "myWidgets.Dialog",
  6. [dijit.Dialog],
  7. {
  8. // summary:
  9. // extended version of the dojo Dialog widget with the option to disable
  10. // the close button and supress the escape key.
  11.  
  12. disableCloseButton: true,
  13.  
  14. /* *********************************************************** postCreate */
  15. postCreate: function()
  16. {
  17. this.inherited(arguments);
  18. this._updateCloseButtonState();
  19. },
  20.  
  21. /* *************************************************************** _onKey */
  22. _onKey: function(evt)
  23. {
  24. if(this.disableCloseButton && evt.charOrCode == dojo.keys.ESCAPE) return;
  25. this.inherited(arguments);
  26. },
  27.  
  28. /* ************************************************ setCloseButtonDisabled*/
  29. setCloseButtonDisabled: function(flag)
  30. {
  31. this.disableCloseButton = flag;
  32. this._updateCloseButtonState();
  33. },
  34.  
  35. /* ********************************************** _updateCloseButtonState */
  36. _updateCloseButtonState: function()
  37. {
  38. dojo.style(this.closeButtonNode,
  39. "display",this.disableCloseButton ? "none" : "block");
  40. }
  41. }
  42. );

MySQL, Large Result Sets and OutOfMemory related Headaches

Just in case you run into OutOfMemory Exceptions while requesting a large data chunk from the MySQL: the JDBC driver will load ALL (yes, ALL) rows before passing it to your fancy, agile and low-footprint routine. Tweaking the fetchSize property of a statement won't do any good either... well, not without some voodoo. So, here is how you can get the JDBC driver to get you a nice and tight StreamingResultSet:

  1. Connection connection = dataSource.getConnection();
  2. Statement st = connection.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY);
  3. st.setFetchSize(Integer.MIN_VALUE); // Inter.MIN_VALUE <- and ONLY this value, 1,5 or 100 won't fix your problem.
  4. ResultSet rs = st.executeQuery("select * from someREALLYHugeTable");

Oh, and you clowns out there saying "this is normal, just bump up the memory settings for your JVM" - are you NUTS!? Or do you just like your applications exploding out of nowhere after being in production for some time?

Using .NET reflection to determine if a Class implements a generic interface.

Reflection and me? Big friends. With all the love and hate a good friendship should have. A few days ago it was all about hate again. I had a bunch of service classes, some of them would implement a generic interface... Let's call it IHasAdorable - so a Service-Implementation could look like this:

  1. public class MarketMerchant : IHasAdorable<CheeseBurger>, IProductSeller
  2. {
  3. // defined in IHasAdorable
  4. CheeseBurger BuyAdorable()
  5. {
  6. return new AdorableCheeseburger();
  7. }
  8.  
  9. // defined in IProductSeller
  10. IProduct Buy(String eanCode)
  11. {
  12. if (eanCode.equals("12345"))
  13. return this.bigStackOfSmellyFishburgers.Pop();
  14. else
  15. throw new IAmSoSorryException("We don't have any of these!");
  16. }
  17. }

Now lets assume we want to browse through ALL market merchants and have a look if they have any adorable products. Let's skip the iteration process and pay attention to the probing of all market merchants in order to buy a adorable product from each of them. First attempt might be to use "is":

  1. IProductSeller merchant;
  2. // iteration goes here
  3. if (merchant is IHasAdorable<object>)
  4. {
  5. // this wont work. We are selling something very special, not just a stupid object!
  6. // Casting to IHasAdorable<> won't even compile.
  7. }

This one would not work either, although it makes sense to me:
  1. typeof(IHasAdorable<object>).IsAssignableFrom(merchant)

It seems we need to know what kind of objects a unknown merchant sells before we can "see" if those are also adorable. So here is how I got it working. Let me know if you do know a better solution:
  1. // `1 means there is 1 Generic parameter
  2. Type adorableInterfaceType = merchant.GetType().GetInterface("IHasAdorable`1");
  3.  
  4. if (adorableInterfaceType != null)
  5. {
  6. // yay, the merchant has adorable products, what whould those be!?
  7. Type adorableProductType = adorableInterfaceType.GetGenericArguments()[0];
  8.  
  9. // here is the magic we need to get the correct IHasAdorable Type
  10. // with "filled in" generic type.
  11. Type genericAdorableInterfaceType =
  12. typeof(IHasAdorable<>).MakeGenericType(adorableProductType);
  13. MethodInfo mi = genericAdorableInterfaceType.GetMethod("BuyAdorable");
  14. myBagOfAdorableProducts.Add(mi.invoke(merchant,null));
  15. }

Bon Appétit

Local IIS Dev-Server + Firefox = slow request response times

If you run into the same issue, disable IPv6 support in Firefox:
about:config -> network.dns.disableIPv6 -> true
Apparently Firefox and Microsoft Internet Information Server do not like to play together nicely on Vista without human intervention.

"Jar-Hell" - or how do I find a Java-Class in a folder full of Jar-Archives

There you go

  1. #!/bin/sh
  2.  
  3. ########################################################################
  4. ## Scans all jar files within a directory (recursively) for a class
  5. ## name
  6. ## Usage: findClass /tmp/ MyFunnyClass
  7. ########################################################################
  8.  
  9. black='\E[30;47m'
  10. red='\E[31;40m\033[1m'
  11. green='\E[32;47m'
  12. yellow='\E[33;40m'
  13. blue='\E[34;40m\033[1m'
  14. magenta='\E[35;47m'
  15. cyan='\E[36;47m'
  16. white='\E[37;47m'
  17. alias Reset="tput sgr0"
  18.  
  19. cecho ()
  20. {
  21. local default_msg=" "
  22. message=${1:-$default_msg} # Defaults to default message.
  23. color=${2:-$black} # Defaults to black, if not specified.
  24. echo -e -n "$color"
  25. echo -n "$message"
  26. Reset # Reset to normal.
  27. return
  28. }
  29.  
  30. clsln()
  31. {
  32. fillLine " ";
  33. }
  34.  
  35. fillLine()
  36. {
  37. let tw=$(tput cols)-1;
  38. for (( c=0 ; c < $tw; c++))
  39. do
  40. echo -n "$1";
  41. done
  42. echo -e -n '\r'
  43. }
  44.  
  45. echo
  46. echo -n Scanning Folder:
  47. cecho "$1" $yellow
  48. echo -n for Class:
  49. cecho "$2" $yellow
  50. echo
  51.  
  52. fillLine "."
  53. echo
  54. for i in $(find $1 -name '*jar');
  55. do
  56. clsln;
  57. echo -n -e "Scanning :";
  58. cecho $i $blue
  59. echo -n -e '\r';
  60.  
  61. out=$(jar vft $i | egrep $2);
  62.  
  63. if [ "$out" ]
  64. then
  65. clsln;
  66. fillLine "*"
  67. echo
  68. echo -n -e 'Possble hit in file:'
  69. cecho $i $blue
  70. echo
  71. echo "$out" $red
  72. echo
  73. fillLine "*"
  74. echo
  75. echo
  76. fi
  77. done;
  78. clsln;
  79. echo;

Missing Locales under Debian?

This drives me crazy! Every time I debootstrap a debian or ubuntu machine the resulting root system will lack properly set up locales. dpkg-reconfigure locales & derivates won't help since the system does not know what locales it should generate - and for some reason it does not show that nice ncurses UI where you were able to pick the locales you would like to have the support for.

So, there goes another blog entry which should act as my personal notepad for future accidents like this:

  1. root@baracus:# cat /usr/share/i18n/SUPPORTED | egrep en_US > /var/lib/locales/supported.d/en
  2. root@baracus:# cat /usr/share/i18n/SUPPORTED | egrep de_DE > /var/lib/locales/supported.d/de
  3. root@baracus:# locale-gen
  4. Generating locales...
  5. de_DE.ISO-8859-1... up-to-date
  6. de_DE.UTF-8... up-to-date
  7. de_DE.ISO-8859-15@euro... up-to-date
  8. en_US.ISO-8859-1... done
  9. en_US.UTF-8... done
  10. Generation complete.

P.S.

You might need to reinstall the locales package afterwards:

  1. sudo apt-get install --reinstall locales
  2. export LANG="de_DE.utf8"
  3. YAY!

Tweet-Feed: soapUI

(Unix) Timestamp to .NET DateTime ?

Well, this is rather a note to myself:

for Javascript new Date().getTime() value (miliseconds, hence / 1000)

  1. new System.DateTime(1970, 1, 1, 0, 0, 0, 0)
  2. .AddSeconds(ajaxRequest.RequestDate / 1000)

One more reason why I love local initializers

  1. public static IDictionary<RequestTypeEnum, RequestGroupEnum>
  2. RequestTypeToGroup= new Dictionary<RequestTypeEnum, RequestGroupEnum>()
  3. {
  4. {RequestTypeEnum.RegisterAccount, RequestGroupEnum.Account},
  5. {RequestTypeEnum.UnregisterAccount, RequestGroupEnum.Account},
  6. {RequestTypeEnum.RegisterInetAccess, RequestGroupEnum.InetAccess},
  7. {RequestTypeEnum.UnregisterInetAccess, RequestGroupEnum.InetAccess},
  8. {RequestTypeEnum.RegisterMailbox, RequestGroupEnum.Mailbox},
  9. {RequestTypeEnum.UnregisterMailbox, RequestGroupEnum.Mailbox},
  10. {RequestTypeEnum.RegisterRLA, RequestGroupEnum.RLA},
  11. {RequestTypeEnum.UnregisterRLA, RequestGroupEnum.RLA}
  12. };

Scheduling encrypted backups with Windows (to unix)

Atomic RouterAtomic RouterThis issue has been puzzling me for some time. I have this Atom based home-brew router sitting on the shelf with a 2TB drive attached to it. So yes, it does also serve as a NAS, Meda-Server etc. All the good stuff. So theoretically it should be also a good place to backup my data to – in case one of the workstation harddrives fails – been there, done that. No IBM drives for me since that incident.

So, where is the catch? Backing up private and sensitive data to that device would be almost insane, this nice piece of hardware is directly connected to the internet and thus exposed to a variety of break in attempts. What if one of these is successful? Riiiite, I would be fu***. Properly.

The solution is very obvious; encrypt your data before you move it onto the server. But how would one do that using a windows client and free software only? There are several ways to achieve that. You could choose to write a batch script, use 7zip or something to compress / password protect that data and copy it over to the other side.

Since I don’t really like batch scripting and prefer doing fancy stunts using bash, I choose cygwin, cron (running as NT service, @see /usr/share/doc/Cygwin/cron-4.1-7.README) and openssl to encrypt that data. So, here is the one-liner doing all the work:

tar cz MyImportantDataDirectory | openssl des3 -salt -pass pass:SECRET | ssh pulsar@router "cat &gt; /mnt/backups/documents-daily.tar.gz.des3"

Go crazy now! Use the week-number to create a series of backups instead of the daily snapshot, remove old backup sets etc. Once you have that script, schedule it using the cron (crontab –e) and watch your sensitive data being backed up automagically. /me likes!

Syndicate content