block

Is it possible to see the ruby code in a proc?

喜你入骨 提交于 2019-12-09 05:23:02
问题 p = Proc.new{ puts 'ok' } Is is possible to see the ruby code in the proc? inspect returns the memory location: puts p.inspect #<Proc:0x007f9e42980b88@(irb):2> Ruby 1.9.3 回答1: Take a look at the sourcify gem: proc { x + y }.to_source # >> "proc { (x + y) }" 回答2: Do you mean the original source code or its bytecode representation ? For the former you may use standard Proc's method source_location p.source_location => ["test.rb", 21] and read the appropriate lines of code. For the latter it may

When do you use scope without a statement in C#?

霸气de小男生 提交于 2019-12-09 03:29:26
问题 Just recently I found out you can do this in C#: { // google string url = "#"; if ( value > 5 ) url = "http://google.com"; menu.Add( new MenuItem(url) ); } { // cheese string url = "#"; // url has to be redefined again, // so it can't accidently leak into the new menu item if ( value > 45 ) url = "http://cheese.com"; menu.Add( new MenuItem(url) ); } instead of i.e.: string url = "#"; // google if ( value > 5 ) url = "http://google.com"; menu.Add( new MenuItem(url) ); // cheese url = "#"; //

Cancel GCD async task when navigating back

和自甴很熟 提交于 2019-12-09 01:02:19
问题 I have a relatively long running task (5-10 secs) in a view controller in my iOS app. It is running async in the background by GCD. The user has the ability to make UI operations during this task, so he also has the ability to press back button to navigate to the previous view. My code is pretty straightforward: dispatch_queue_t queue = dispatch_queue_create("com.x.y.z", NULL); dispatch_async(queue, ^{ TestObject* test = [self getTestObject]; dispatch_async(dispatch_get_main_queue(), ^{ test

Why do we need blocks, function literals, closures in programming languages?

半腔热情 提交于 2019-12-08 22:14:28
I program in Objective-C, I know a bit of Scala, Python and Javascript. While I'm comfortable with blocks in Obj-C, I would like to know what specific problem do they solve that I couldn't with the earlier versions of the language. Also - are blocks, closures, function literals, named functions, anonymous functions - one and the same thing? If you can answer with some code examples that would be great. First of all, in order to answer the question in the title: Why do we need blocks, function literals, closures in programming languages? Answer #1: we don't. Brainfuck is Turing-complete without

glassPane is not blocking input

半城伤御伤魂 提交于 2019-12-08 22:14:22
问题 I've build a small GUI game in java and at some point I'm using a glassPane to temporarily block all mouseinput. I've used the glassPane before without any problems but this time it won't block the mouseinput. So I can still press a button that resides on the contentPane while the glassPane is enabled, I'm sure it's enabled because I can see the stuff I paint on it. Here is a short piece of runnable code that's shows the problem: import java.awt.Color; import java.awt.Dimension; import java

Eigen library: return a matrix block in a function as lvalue

ぐ巨炮叔叔 提交于 2019-12-08 21:52:43
问题 I am trying to return a block of a matrix as an lvalue of a function. Let's say my function looks like this: Block<Derived> getBlock(MatrixXd & m, int i, int j, int row, int column) { return m.block(i,j,row,column); } As it turns out, it seems that C++ compiler understands that block() operator gives only temporary value and so returning it as an lvalue is prohibited by the compiler. However, in Eigen documentation there is some example that we can use Eigen as an lvalue (http://eigen

.htaccess block all ip's, if they are blocked redirect to a page

冷暖自知 提交于 2019-12-08 12:00:18
问题 So I am blocking all ip's except the ones on a list, so how can I redirect people to a new site if they're blocked? 回答1: My assumption is that you are blocking ip's using allow/deny. I do not believe that you are able to specify a redirect rule to work on the denied ip's as you have told the server to reject their connections outright. Instead you are going to want to use the RewriteEngine to do a redirect. In case you are unfamiliar with the syntax I have provided the following example which

How to parse block data from a text file into an 2D array in Python?

寵の児 提交于 2019-12-08 11:54:16
问题 I am trying to parse a text file with the following structure: latitude 5.0000 number_of_data_values 9 0.1 0.2 0.3 0.4 1.1 1.2 1.3 1.4 8.1 latitude 4.3000 number_of_data_values 9 0.1 0.2 0.3 0.4 1.1 1.2 1.3 1.4 8.1 latitude 4.0000 number_of_data_values 9 0.1 0.2 0.3 0.4 1.1 1.2 1.3 1.4 8.1 ... Every different latitude number is a different array line. number_of_data_values is the number of colomns (consistent thorough the file). For this example I would like to read the file and output a 3 by

Magento Layered Navigation block. Move to center

旧巷老猫 提交于 2019-12-08 09:56:36
问题 In category.xml I'm changing the reference name in: <reference name="left"> <block type="catalog/layer_view" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml"/> </reference> To content which I assumed would place the layered nav into the center. However, it still stays on the left. In fact, even I changed left to right , and it still doesn't move from the left sidebar. What am I doing wrong here? 回答1: I managed to fix this (for anyone else who encounters this problem) by

block <a> inside inline <li> behaviour

允我心安 提交于 2019-12-08 09:41:53
问题 The following HTML / CSS result strikes me as odd and unexpected and I'm really looking for the logic behind the way this is parsed. Suppose: #nav { list-style-type-none } #nav li { display: inline; } /* make the LI's stack horizontally */ #nav li a { display: block; padding: 5px; } /* display as block to add padding */ <ul id="nav"> <li><a href="#">Home</a> </li> <li><a href="#">About us</a> </li> </ul> This results in the <li> 's stacking vertically (like block elements) because of the <a>