<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Georgehotelling's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Tue, 19 Aug 2008 18:28:21 GMT</pubDate>
    <description>DZone Snippets: Georgehotelling's Code Snippets</description>
    <item>
      <title>Get the inverse of a hex color in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/582</link>
      <description>This method will return the inverse of a hex color, which is useful if you want to make sure that your text will show up on a colored background.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;def invert_color(color)&lt;br /&gt;  color.gsub!(/^#/, '')&lt;br /&gt;  sprintf("%X", color.hex ^ 0xFFFFFF)&lt;br /&gt;end&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;invert_color('#c0c0c0') #=&gt; "3F3F3F"&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Limitations:&lt;br /&gt;&lt;br /&gt;Doesn't handle named colors or 3 digit colors (i.e. #FFF == #FFFFFF)&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Wed, 17 Aug 2005 23:32:43 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/582</guid>
      <author>georgehotelling (George Hotelling)</author>
    </item>
    <item>
      <title>Check that a user has permission on all parents in Zope</title>
      <link>http://snippets.dzone.com/posts/show/484</link>
      <description>If you need to be sure that a user can view an object, you need to check the View permission not only on the object but also all of its parents.  To do this, I slightly modified the script at http://zopelabs.com/cookbook/1018022911 so that it uses the context object and specified the View permission.&lt;br /&gt;&lt;br /&gt;Create a Python script in your acquisition path (I used portal_skins/custom) named can_view and paste in this code:&lt;br /&gt;&lt;code&gt;permission = "View"&lt;br /&gt;try:&lt;br /&gt;  object=context&lt;br /&gt;  if not object.acquiredRolesAreUsedBy( permission ):&lt;br /&gt;    for p in object.rolesOfPermission( permission ):&lt;br /&gt;      if p['selected']:&lt;br /&gt;        if p['name'] in user.getRoles():&lt;br /&gt;          return 1&lt;br /&gt;  else:&lt;br /&gt;   return 1&lt;br /&gt;except:&lt;br /&gt;    pass&lt;br /&gt;return 0&lt;br /&gt;&lt;/code&gt;Then you can check the permission in TAL like this:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;div tal:condition="some_object/can_view"&gt;&lt;br /&gt;  ...&lt;br /&gt;&lt;/div&gt;</description>
      <pubDate>Tue, 19 Jul 2005 22:41:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/484</guid>
      <author>georgehotelling (George Hotelling)</author>
    </item>
  </channel>
</rss>
