Show colors in the IPython Notebook using ipythonblocks.

        Parameters
        ----------
        block_size : int, optional
            Size of displayed blocks.
972627
def show_as_blocks(self, block_size=100):
        
        from ipythonblocks import BlockGrid

        grid = BlockGrid(self.number, 1, block_size=block_size)

        for block, color in zip(grid, self.colors):
            block.rgb = color

        grid.show()
830454
def block_widths(self):
        
        if self._widths_cache is None:
            try:
                # The first column will have the correct lengths. We have an
                # invariant that requires that all blocks be the same width in a
                # column of blocks.
                self._widths_cache = np.array(
                    ray.get([obj.width().oid for obj in self._partitions_cache[0]])
                    if len(self._partitions_cache) > 0
                    else []
                )
            except RayTaskError as e:
                handle_ray_task_error(e)
        return self._widths_cache
503632
def show(cls):
        
        cls.div_el.style.display = "block"
        cls.hide_errors()

        cls.overlay.show()
        cls.overlay.el.bind("click", lambda x: cls.hide())
618294
private void findOptimalNodeOrder(final int block_size) {
		final Node<K, V> leaf = createLeafNode();
		final Node<K, V> internal = createInternalNode();
		// Get Maximal Size
		final int nodeSize = Math.max(leaf.getStructEstimateSize(MIN_B_ORDER),
				internal.getStructEstimateSize(MIN_B_ORDER));
		// Find minimal blockSize
		blockSize = ((nodeSize > block_size) ? roundBlockSize(nodeSize, block_size) : block_size);
		// Find b-order for Leaf Nodes
		b_order_leaf = findOptimalNodeOrder(leaf);
		// Find b-order for Internal Nodes
		b_order_internal = findOptimalNodeOrder(internal);
	}
501058
def render(self, size):
        

        # decode the code
        middle, corner, side, foreColor, backColor = self.decode(self.code)
        size = int(size)
        # make image
        image = Image.new("RGB", (size * 3, size * 3))
        draw = ImageDraw.Draw(image)

        # fill background
        draw.rectangle((0, 0, image.size[0], image.size[1]), fill=0)

        kwds = {
            'draw': draw,
            'size': size,
            'foreColor': foreColor,
            'backColor': backColor}
        # middle patch
        self.drawPatch((1, 1), middle[2], middle[1], middle[0], **kwds)

        # side patch
        kwds['type'] = side[0]
        for i in range(4):
            pos = [(1, 0), (2, 1), (1, 2), (0, 1)][i]
            self.drawPatch(pos, side[2] + 1 + i, side[1], **kwds)

        # corner patch
        kwds['type'] = corner[0]
        for i in range(4):
            pos = [(0, 0), (2, 0), (2, 2), (0, 2)][i]
            self.drawPatch(pos, corner[2] + 1 + i, corner[1], **kwds)

        return image
1136142
def display_bounding_boxes_within_notebook(
    page_num, extractor, blocks, alternatecolors=False, color=Color("blue")
):
    
    elems = extractor.elems[page_num]
    page_width, page_height = int(elems.layout.width), int(elems.layout.height)
    img = pdf_to_img(extractor.pdf_file, page_num, page_width, page_height)
    draw = Drawing()
    draw.fill_color = Color("rgba(0, 0, 0, 0)")
    draw.stroke_color = color
    for block in blocks:
        top, left, bottom, right = block[-4:]
        if alternatecolors:
            draw.stroke_color = Color(
                "rgba({},{},{}, 1)".format(
                    str(np.random.randint(255)),
                    str(np.random.randint(255)),
                    str(np.random.randint(255)),
                )
            )
        draw.rectangle(
            left=float(left), top=float(top), right=float(right), bottom=float(bottom)
        )
        draw(img)
    return img
531149
def add_blocks(self, perc_blocked=30):
        
        self.refresh_stats()
        #print(self.show_grid_stats())
        while (100*(self.tot_blocked-10))/self.tot_pix < perc_blocked - 1:
            self.add_block()
            self.refresh_stats()
584623
private void sortBlocksBySize(Map<String, List<OneBlockInfo>> nodeToBlocks) {
    OneBlockInfoSizeComparator comparator = new OneBlockInfoSizeComparator();
    for (Entry<String, List<OneBlockInfo>> entry : nodeToBlocks.entrySet()) {
      Collections.sort(entry.getValue(), comparator);
    }
  }
863280
def block_lengths(self):
        
        if self._lengths_cache is None:
            # The first column will have the correct lengths. We have an
            # invariant that requires that all blocks be the same length in a
            # row of blocks.
            self._lengths_cache = (
                [obj.length() for obj in self._partitions_cache.T[0]]
                if len(self._partitions_cache.T) > 0
                else []
            )
        return self._lengths_cache
1125628
def fetch_block(block_size=nil)
      block_size ||= @block_size ||= @options.fetch(:block_size) { 1000 }
      @result = @connection.execute("fetch #{block_size} from cursor_#{@cursor}")

      if @iterate == :each_array
        @block = @result.each_row.collect {|row| row }
      else
        @block = @result.collect {|row| row }
      end
    end
1368542
def prettify(blocks)
      docs_blocks, code_blocks = blocks

      # Combine all docs blocks into a single big markdown document with section
      # dividers and run through the Markdown processor. Then split it back out
      # into separate sections
      rendered_html = self.class.renderer.render(docs_blocks.join("\n\n##### DIVIDER\n\n"))
      rendered_html = ' ' if rendered_html == '' # ''.split() won't return anything useful
      docs_html = rendered_html.split(/\n*<h5>DIVIDER<\/h5>\n*/m)

      docs_html.zip(code_blocks)
    end
901757
def block_lengths(self):
        
        if self._lengths_cache is None:
            try:
                # The first column will have the correct lengths. We have an
                # invariant that requires that all blocks be the same length in a
                # row of blocks.
                self._lengths_cache = np.array(
                    ray.get([obj.length().oid for obj in self._partitions_cache.T[0]])
                    if len(self._partitions_cache.T) > 0
                    else []
                )
            except RayTaskError as e:
                handle_ray_task_error(e)
        return self._lengths_cache
1136297
def _writeblocks(cls, blocks, available, cont_size, padding_func):
        """"""

        # write everything except padding
        data = bytearray()
        for block in blocks:
            if isinstance(block, Padding):
                continue
            data += cls._writeblock(block)
        blockssize = len(data)

        # take the padding overhead into account. we always add one
        # to make things simple.
        padding_block = Padding()
        blockssize += len(cls._writeblock(padding_block))

        # finally add a padding block
        info = PaddingInfo(available - blockssize, cont_size)
        padding_block.length = min(info._get_padding(padding_func),
                                   cls._MAX_SIZE)
        data += cls._writeblock(padding_block, is_last=True)

        return data
116678
def _render_template_block_nodelist(nodelist, block_name, context):
    """"""

    # Attempt to find the wanted block in the current template.
    for node in nodelist:
        # If the wanted block was found, return it.
        if isinstance(node, BlockNode):
            # No matter what, add this block to the rendering context.
            context.render_context[BLOCK_CONTEXT_KEY].push(node.name, node)

            # If the name matches, you're all set and we found the block!
            if node.name == block_name:
                return node.render(context)

        # If a node has children, recurse into them. Based on
        # django.template.base.Node.get_nodes_by_type.
        for attr in node.child_nodelists:
            try:
                new_nodelist = getattr(node, attr)
            except AttributeError:
                continue

            # Try to find the block recursively.
            try:
                return _render_template_block_nodelist(new_nodelist, block_name, context)
            except BlockNotFound:
                continue

    # The wanted block_name was not found.
    raise BlockNotFound("block with name '%s' does not exist" % block_name)
738817
def highlightBlock(self, block):
        

        self.highlight_text(block, 0, len(block))
        self.setCurrentBlockState(0)

        state = 1
        for rule in self.rules:
            if re.match("comment\.block\.[\w\.]*start", rule.name):
                format = self.formats.get_format(rule.name) or self.formats.get_format("default")
                if self.highlight_multiline_block(block, rule.pattern,
                                                  foundations.common.get_first_item([item for item in self.rules
                                                                                     if item.name == rule.name.replace(
                                                              "start", "end")]).pattern, state, format):
                    break
                state += 1
379903
def _compute_total_chunks(self, chunk_size):
        # type: (Descriptor, int) -> int
        
        try:
            if self._src_block_list is not None:
                blen = len(self._src_block_list)
                if blen > 0:
                    return blen
                else:
                    return 1
            else:
                return int(math.ceil(self._src_ase.size / chunk_size))
        except ZeroDivisionError:
            return 1
379260
def highlightBlock(self, block):
        

        raise NotImplementedError("{0} | '{1}' must be implemented by '{2}' subclasses!".format(self.__class__.__name__,
                                                                                                self.highlightBlock.__name__,
                                                                                                self.__class__.__name__))