blocks

Which libraries do you need to link against for a clang program using blocks.

I've discovered (below) that I need to use -fblocks when compiling code which uses blocks. What library do I need to link against to let the linker resolve _NSConcreteStackBlock? (On Ubuntu 9.10 AMD64.) Thanks, Chris. chris@chris-desktop:~$ clang ctest.c ctest.c:3:25: error: blocks support disabled - compile with -fblocks or pick ...

How to require a block in Ruby?

Is there any built in way to require that a block be passed to a Ruby method? I realize I can just raise an exception if block_given? is false, but is there some nicer way to do it? ...

Process an array in a function, with external formatting

I want to pass an array to a function and iterate through it in this function. But I would like to be able to change the way the single entries are displayed. Suppose I have an array of complicated objects: $items = array($one, $two, $three); Right now I do: $entries = array(); foreach($items as $item) { $entries[] = create_li($...

Understanding CUDA grid dimensions, block dimensions and threads organization (simple explanation)

How threads are organized to be executed by a GPU? ...

How do CLang 'blocks' work?

http://clang.llvm.org/docs/BlockLanguageSpec.txt Looks really cool. However, I don't understand it. I don't see examples it. I don't see examples of ideas hard to express in C++ as is, but trivial to express in blocks. Can anyone enlighten me on this? Thanks! ...

Detect block size for quota in Linux

The limit placed on disk quota in Linux is counted in blocks. However, I found no reliable way to determine the block size. Tutorials I found refer to block size as 512 bytes, and sometimes as 1024 bytes. I got confused reading a post on LinuxForum.org for what a block size really means. So I tried to find that meaning in the context of...

Is it a good idea to define a variable in a local block for a case of a switch statement?

I have a rather long switch-case statement. Some of the cases are really short and trivial. A few are longer and need some variables that are never used anywhere else, like this: switch (action) { case kSimpleAction: // Do something simple break; case kComplexAction: { int specialVariable = 5; // ...

Copying blocks (ie: copying them to instance variables) in Objective-C

I'm trying to understand blocks. I get how to use them normally, when passed directly to a method. I'm interested now in taking a block, storing it (say) in an instance variable and calling it later. The blocks programming guide makes it sound like I can do this, by using Block_copy / retain to copy the block away, but when I try to run...

What is the performance difference between blocks and callbacks?

One of the things that block objects, introduced in Snow Leopard, are good for is situations that would previously have been handled with callbacks. The syntax is much cleaner for passing context around. However, I haven't seen any information on the performance implications of using blocks in this manner. What, if any, performance pi...

How to simplify ruby block with one argument?

Somewhere i saw a way to simplify ruby blocks with one argument, it basically omitted vertical bars and argument declaration, because it was somehow inlined. I cannot find it anymore or remember any names t osearch for. Can you help? ...

Timeseries transformations in Ruby, Yahoo! Pipes-style

I'm trying to build a system for programmatically filtering timeseries data and wonder if this problem has been solved, or at least hacked at, before. It seems that it's a perfect opportunity to do some Ruby block magic, given the scope and passing abilities; however, I'm still a bit short of fully grokking how to take advantage of block...

Add Table to FlowDocument In Code Behind

Hi, I have tried this..... _doc = new FlowDocument(); Table t = new Table(); for (int i = 0; i < 7; i++) { t.Columns.Add(new TableColumn()); } TableRow row = new TableRow(); row.Background = Brushes.Silver; row.FontSize = 40; row.FontWeight = FontWeights.Bold; row.Cells.Add(new TableCell(new Paragraph(new Run("I span 7 columns")...

How can I create multiple different blocks in one module in Drupal 6?

I'm using hook_block to create a block with the name of the custom module I'm creating. I'm not being able to create a block without using myModuleName_block. Do I need to do different modules for every different block I want to create? ...

Rails render partial with block

I'm trying to re-use an html component that i've written that provides panel styling. Something like: <div class="v-panel"> <div class="v-panel-tr"></div> <h3>Some Title</h3> <div class="v-panel-c"> .. content goes here </div> <div class="v-panel-b"><div class="v-panel-br"></div><div class="v-panel-bl"></div...

Drupal - assign menu to block based on node type

I want to assign a specific menu in left sidebar block, based on the node type of the page currently being displayed. I think it should look something like this, but I am stuck. function my_module_nodeapi(&$node, $op) { switch ($op) { case 'view': if ($node->type == "large_reptiles") { //menu_set_active_menu_...

How much overhead does a msg_send call incur?

I'm attempting to piece together and run a list of tasks put together by a user. These task lists can be hundreds or thousand of items long. From what I know, the easiest and most obvious way would be to build an array and then iterate through them: NSArray *arrayOfTasks = .... init and fill with thousands of tasks for (id *eachTask ...

Understanding Ruby Enumerable#map (with more complex blocks)

Let's say I have a function def odd_or_even n if n%2 == 0 return :even else return :odd end end And I had a simple enumerable array simple = [1,2,3,4,5] And I ran it through map, with my function, using a do-end block: simple.map do |n| odd_or_even(n) end # => [:odd,:even,:odd,:even,:odd] How could I do this with...

Creating classes for nested blocks in Ruby

Hi! I want to reformat some helpers in my Rails views. I want to archieve a syntax similar to: <%= box :option => 'value' do |b| b.header "Header of box #1" %> Content of Box#1 <% end %> The b.header call is optional. How would I structure my code to allow this? I guess it's something similar to fields_for in Rails. Tha...

How to "break" out of dispatch_apply()?

Is there a way to simulate a break statement in a dispatch_apply() block? E.g., every Cocoa API I've seen dealing with enumerating blocks has a "stop" parameter: [array enumerateObjectsUsingBlock:^(id obj, NSUInteger i, BOOL *stop) { if ([obj isNotVeryNice]) { *stop = YES; // No more enumerating! } else { NSLog(...

referencing self within a block IPhone SDK

I'm trying to implament a callback mechanism where I pass in a block to the init of a class, and after some work that class calls me back. The block gets called and most everything works, except when I call anything on "self" within the block. I get Program received signal: “EXC_BAD_ACCESS”. unless I comment out any reference to self...