blocks

Ruby blocks/Java closures in C

I've been trying to understand how Ruby blocks work, and to do that I've been trying to implement them in C (^_^). One easy way to implement closures is to pass a void* to the enclosing stack to the closure/function but Ruby blocks also seem to handle returns and break statements from the scope that uses the block. loop do break i if...

mmap() vs. reading blocks

I'm working on a program that will be processing files that could potentially be 100GB or more in size. The files contain sets of variable length records. I've got a first implementation up and running and am now looking towards improving performance, particularly at doing I/O more efficiently since the input file gets scanned many times...

MS SQL Concurrency problem, excess Locks

In my enviroment i have a database on ms sql 2000 that is being hit by hundreads of users at any time. Also the are lots of intense reports using reporting services 2005 hitting the same database. The problem we are getting is when there are lots of reports runnig at the same time and people using the database concurrent with the reports...

How do I test Rails block helpers with rSpec

In my views I use a helper that takes arbitrary HTML as a block: <% some_block_helper do %> Some arbitrary HTML and ERB variables here. More HTML here. <% end %> My helper does a bunch of things to the passed block of HTML before rendering it back to the view (Markdown and other formatting). I would like to know what are the clean...

Ruby - Passing Blocks To Methods

I'm trying to do Ruby password input with the Highline gem and since I have the user input the password twice, I'd like to eliminate the duplication on the blocks I'm passing in. For example, a simple version of what I'm doing right now is: new_pass = ask("Enter your new password: ") { |prompt| prompt.echo = false } verify_pass = ask("E...

Detecting if youtube is blocked by company / ISP

We have Youtube videos on a site and want to detect if it is likely that they will not be able to view them due to (mostly likely) company policy or otherwise. We have two sites: 1) Flex / Flash 2) HTML I think with Flex I can attempt to download http://youtube.com/crossdomain.xml and if it is valid XML assume the site is available B...

What is the difference or value of these block coding styles in Ruby?

Which style is preferred? Is there a good reason for one vs. the other? Thanks in advance! 1) cmds.each do |cmd| end 2) cmds.each { |cmd| } Example code: cmds = [ "create", "update", "list", "help" ] # Block style one # cmds.each do |cmd| puts "loop1, cmd: #{cmd}" end # Block style two # cmds.each { |cmd| puts "loop2, c...

don't display 'user login' block

I do not want the user login block to be displayed for users who are not admin. I only want it to be displayed for the admin user (sitadmin, uid:1, in my case) and users who are not logged in (uid:0) In the configure page (/admin/build/block/configure/user/0) for the block, under page specific settings, I have selected "Show if the foll...

When do you use code blocks?

When do you use code blocks in C/C++/C#, etc.? I know the theoretical reason behind them, but when do you use them in real programs? EDIT: I have just realised that I use them in switch statements, where variables would otherwise be in the same scope (grr for things like i): switch (x) { case "abc": { /* code */ } break; } etc (Just ...

Are there any significant differences between blocks in Ruby vs Groovy?

I've gotten used to blocks in Ruby and would like to use them in Java. Groovy seems to offer a similar feature but I don't know enough about Groovy to understand whether there are any significant differences in syntax and functionality. Is a Ruby block equivalent to a Groovy block? ...

Magento core function working in remote system displaying error in another system.

In catalog.xml file of frontend template folder I had blocks defined for tabs to display product tags,additional information etc.in this way: additional Additional Information catalog/product_view_attributes catalog/product/view/attributes.phtml Which was working fine in the remote system,but when i installed it in local magento and tr...

How do I create a reusable block/proc/lamda in Ruby?

I want to create a filter, and be able to apply it to an array or hash. For example: def isodd(i) i % 2 == 1 end The I want to be able to use it like so: x = [1,2,3,4] puts x.select(isodd) x.delete_if(isodd) puts x This seems like it should be straight forward, but I can't figure out what I need to do it get it to work. ...

Suggested resources for learning about blocks in Snow Leopard

Now that there is no NDA, what are some good suggested resources for learning about blocks under Snow Leopard? ...

Magento defining custom CMS page in cms.xml

Hi all! I've added several pages (cms) in my magento admin panel. I know i can attach blocks to a specific page by using {{block..}} within the content field. However, i dont want to define blocks there, but within the cms.xml file. So other store admins are not annoyed by weird codes ({{block..}}) in the backend editor. I've defined ...

Using Objective-C Blocks

Today I was experimenting with Objective-C's blocks so I thought I'd be clever and add to NSArray a few functional-style collection methods that I've seen in other languages: @interface NSArray (FunWithBlocks) - (NSArray *)collect:(id (^)(id obj))block; - (NSArray *)select:(BOOL (^)(id obj))block; - (NSArray *)flattenedArray; @end The...

What's another way of writing this block without using do-end?

How would you write this on the same line or on consecutive lines without do-end? map.resources :magazines do |magazine| magazine.resources :ads end ...

Block question: what exactly does "long long (^blockFun)() = (long long (^)())moreBlockFun" mean and do?

I'm trying to learn and use Blocks effectively. On the web, I've come across this tasty morsel of code: long long (^blockFun)() = (long long (^)())moreBlockFun; it confuses the heck out of me. I think it's trying to create a block that expects a block that returns a long and i think it's doing some casting somewhere too, just for fu...

Is this the right way for a block inside a struct to access a member variable in the same struct?

I'm experimenting with Obj-C blocks and trying to have a struct with two blocks in it where one block is to change what the other block does. this is a really roundabout way to do something simple... and there may be better ways to do it, but the point of the exercise is for me to understand blocks. here's the code , it doesn't work, s...

Ruby: yield block from a block?

Is it possible for a lambda, proc, method or other type of block in ruby, to yield to another block? something like... a = lambda { puts 'in a' yield if block_given? } a.call { puts "in a's block" } this doesn't work... it just produces in a => nil I'm wondering if there is a way to get the block to call a block, though... ...

Sending a code block to a find_all dynamic method

I'm working with some complex queries using the dynamic find_all method and reached to a point where sending a block to that find_all method would really simplify my code. Is there any plugin or work in-progress dealing with this? In simple terms, I'd like to do something like: @products = Product.find_all_by_ids(ids, .....) do |p| ...