blocks

Blocks to Fixed document/Fixed Page

Can any one help me to add Blocks(System.Windows.Documents.Block/ Section / BlockUIContainer) to the Fixed Document. Thanking for your attention, regards, kuman ...

Am I understanding Drupal regions and views correctly?

We're building a very content rich site in Drupal. It's my first time working with it. There are a variety of sections to this site, each with a different layout. I plan on determining the page.tpl.php via the phptemplate_preprocess_page() method. My question is how best to specify where in a given page to put different chunks of second...

Ruby 1.8 vs 1.9 - destructive reject! operator

Why does this work the way it does? I thought it had something to do with pass-by-reference/value, but that's not the case. Does it have something to do with the new block scopes? def strip_ids(array) array.each{ |row| row.reject! {|k, v| k =~ /_id/ } } end class Foo attr_accessor :array def initialize @array = [] @array...

printing a ruby block

I have a method that takes a block. Obviously I don't know what is going to be passed in and for bizarre reasons that I won't go into here I want to print the contents of the block. Is there a way to do this? ...

Why enclose blocks of C code in curly braces?

I am looking at some C code, and have noticed it is full of these curly braces surrounding blocks of code without any sort of control structure. Take a look-see: //do some stuff . . . fprintf(stderr, "%.2f sec\n", (float)(clock() - t) / CLOCKS_PER_SEC); { //a block! why not? char *tmp_argv[3]; tmp_argv[0] = argv[0]; tmp_arg...

how to write a block that returns a string in ruby

A function takes a string as argument, example fn("string"). i want to pass in different values depending on three of more condiitons, and one approach which is slightly unreadable is: fn(check_1 ? "yes" : check_2 ? "no" : "maybe") i want to replace the argument with a block that returns a string. i am hoping i can do something like: ...

Creating an IMP from an Objective-C block

The IMP type in Objective-C represents a function pointer, as far I as understand. Is there any way to make an IMP from a block pointer? Thanks for your ideas. UPDATE: Thanks, @bbum, for your great solution. I haven't modified my code to use it yet, but everyone can see the fruits of my labors here: A new metaclass for Objective-C. ...

PowerShell: passing blocks as parameters to functions

I will explain my question on an example. Let's have following code in C#: void A(Action block) { B(() => { Console.WriteLine(2); block(); }); } void B(Action block) { Console.WriteLine(1); block(); } void Main() { A(() => { Console.WriteLine(3); }); } The output of this code is: 1 2 3 Now, I want to write this code...

PowerShell: an elegant way to create closures

Keith Hill explained me that blocks in PowerShell are not closures and that to create closures from blocks I have to call method .GetNewClosure(). Is there any elegant way to create closures from blocks? (e.g. create a wrapping function, an alias?, ...) Example: { block } ${ closure } # ??? ...

Erubis block helper throwing error with concat

I have a couple of block helpers, here's a simple example of what I'm doing: def wrap_foo foo, &block data = capture(&block) content = " <div class=\"foo\" id=\"#{foo}\"> #{data} </div>" concat( content ) end I'm just trying out erubis and it's giving me the following error: You have a nil object when...

Can I use a block when defining a Scala anonymous function?

Let's say I have this method: def myMethod(value:File,x: (a:File) => Unit) = { // some processing here // more processing x(value) } I know I can call this as: myMethod(new File("c:/"),(x:File) => println(x)) Is there a way I could call it using braces? Something like: myMethod(new File("c:/"),{ (x:File) => if(x.toSt...

Writing an around_each filter in ruby for every method within a block.

I need a method that takes a block, and performs something similar to an around_each filter for every method within the block. For instance: def method_that_takes_block (@threads ||= Array.new) << Thread.new {yield if block.given?} end method_that_takes_a_block do method_one method_two method_three end In this instance I wou...

How to make block local variables the default in ruby 1.9 ?

Hi, Ruby 1.9 gives the ability to define variables that are just local to a block and do not close over variables of the same name in an outer scope: x = 10 proc { |;x| x = 20 }.call x #=> 10 I would like to have this behaviour as default for some blocks i define - without having to use the |;x, y, z| syntax (note the semicolon)....

Need a Standard Library Reference for Ruby

I need a good reference for how to use standard Libraries in Ruby. What confuses me about current libraries is that they don't describe or give examples like say Java's. Yet this is where examples are much more needed (in Ruby), because I am not familiar with how the called method will yield! So I am left with having to look at the sourc...

Custom Modal Window with Block Completion Handler

Hey Guys! I'm stuck! I am trying to create a custom modal dialog. I would like it to perform similarly to the NSSavePanel using a block as a completion handler. I've copied only the important snippets I think are needed. @implementation ModalWindowController - (void)makeKeyAndOrderFront:(id)sender modalToWindow...

Keeping named_scope Extensions DRY

In Rails, you can add a block after a named_scope for additional, context-sensitive methods like so: class User < ActiveRecord::Base named_scope :inactive, :conditions => {:active => false} do def activate each { |i| i.update_attribute(:active, true) } end end end In this example, the activate method is being defined...

Only show a view on a certain content type in Drupal

Hi, i have build an "About the Author" views block in Drupal. This is linked at the user_id of the creater of the current node, which works great. However, i now would like to know how to limit the view to certain content types. I do not want it to show on a story, only on blogs. I tried to do it with Arguments but i haven't had any lu...

Rewrite simple ruby function to use a block

I dont know the correct terminology for what i am asking I tried to google it and couldnt ind anything for the same reason I am writing a ruby library, and i want to rewite the functions so they work as below as i prefer it for readability (inside a block?) at the moment i have a function that does this @dwg = Dwg.new("test.dwg") @dwg...

Drupal: Content in blocks from node_reference fields?

After only a few weeks of working with Drupal I've come up with a recurring problem, which I don't really have an optimal solution to, so I'm hoping that someone here might be able to give some best practice pointers. What I have is a region inside my node.tpl.php, which is populated with blocks that display content from two different C...

Fun with Lambdas

Not having them used them all that much I'm not quite sure all that lambdas/blocks can be used for (other than map/collect/do/lightweight local function syntax). If some people could post some interesting but somewhat understandable examples (with explanation). preferred languages for examples: python, smalltalk, haskell ...