Skip to content

Instantly share code, notes, and snippets.

from collections import namedtuple
from types import MethodType
def _init(self, *args, **kwargs):
if not self._typespec:
return
if len(self._fields) != len(self._typespec):
raise TypeError("Incorrect type in constructor")
for field, ts in zip(self._fields, self._typespec):
if ts and not isinstance(getattr(self, field), ts):

This is a note on storing encrypted data in Rails

def get_node(instance)
query_node = Chef::Search::Query.new
query = "name:#{instance}"
if block_given?
query_node.search('node', query) do |node|
yield node
end
else
query_node.search('node', query).first.first
end