Finding magic numbers using NDepend - ndepend

Does anyone know how I could find magic numbers in the source code using the CQL queries in NDepend? This is the same problem as this question, but I don't want to use regex if possible.
So I want to find all statements like
Int32 someValue = 23;
Double anotherValue = 1;
but not
for (int i = 0; i < array.length; i++)

I confirm, currently NDepend and CQLinq cannot help with that.
I would advise you do a small app using Mono.Cecil, and search for magic numbers and strings.
You'll see, Mono.Cecil API rocks!

It's a nice idea but I'm pretty certain you can't do it as there is no way to query inititialisation values in CQL.

Related

GAMS: retrieve information from solution

GAMS: I think I have a pretty simple question, however I'm stuck and was wondering if someone could help here.
A simplified version of my model looks like this:
set(i,t) ;
parameter price
D;
variable p(i,t)
e(i,t);
equations
Equation1
obj.. C=sum((i,t), p(i,t)*price);
Model file /all/ ;
Solve file minimizing C using MIP ;
Display C.l;
p(i,t) and e(i,t) are related:
Equation1 .. e(i,t)=e=e(i,t-1)+p(i,t)*D
Now I want to retrieve information from the solution: lets say I want to know at what t e(i,t) has a certain value for example --> e(i,t)= x(i) or otherwise formulated e(i,t=TD)=x(i) find TD, where x(i) thus is depending on i. Does anyone know how I can write this in to my GAMs model? To be clear I do not want to change anything about my solution and the model I have runs; I just want to retrieve this information from the solution given.
So far I tried a couple of thing and nothing worked. I think that this must be simple, can anyone help? Thank you!
Try something like this:
set i /i1*i10/
t /t1*t10/;
variable e(i,t);
*some random dummy "solution"
e.l(i,t) = uniformInt(1,10);
set find5(i,t) 'find all combinations of i and t for which e.l=5';
find5(i,t)$(e.l(i,t)=5) = yes;
display e.l,find5;
Hope that helps,
Lutz

Foursquare venue's category photos issue

i am having trouble about json part of venues, in this picture i am trying to take the prefix and suffix, i am putting size between them but my problem is when i try to put them together the link of prefix + size + suffix comes like this -> i am taking prefix and suffix in seperate NSMutableArray's but when i try to join them together it's not working. and here is my way to join them.
where am i doing this wrong?
Are you sure that your objects in the imagePrefix and imageSuffix arrays are actually strings? Because judging from your logs it looks as if you're trying to concatenate two arrays and a string. If you let us know what is actually in those arrays you might get more helpful answers. You must be doing some conversion/manipulation from the original JSON, as in the API they get returned as dictionary items not arrays.
On a unrelated note, consider using fast enumeration (for id item in array) rather than writing out the for statement as you've done. Generally speaking it's also much better to post your code as text using markdown syntax rather than images: makes it much harder to copy/paste your code into an answer.
so thanks to "Matthias Bauch" i figured it out and here is my answer for my own question :)
for (int e = 0; e<=[imagePrefix count]-1; e++) {
NSLog(#"%#b_32%#", [[imagePrefix objectAtIndex:e] objectAtIndex:0], [[imageSuffix objectAtIndex:e] objectAtIndex:0]);
}
Thanks guys!

How do I Benchmark RESTful Service with Variable Parameters?

I'm currently working on benchmarking a RESTful service I've made, and part of that is making sure it runs in a reasonable amount of times for a large array of parameters. For example, let's say I have RESTful API of the form some_site.com/item?item_id=y. In that case to be sure my service is working as fast as I'd like it to work, I'd want to try out many values for y one by one, preferably coming from some text file. I can't figure out any way of doing this in ab or httperf. I'm open to using a different benchmarking program if I have, but would prefer something simple and light. What I want to do seems like something pretty standard, so I'm guessing there must already be a program that let's me do it, but an hour or so of googling hasn't gotten me an answer. Ideas?
Answer: Jmeter (which is apparently awesome). This faq explains how to do it. Hopefully this helps someone else, as it took me like a day of searching to figure this out.
I have just had some good experience with using JavaScript (via BSF/Rhino) in JMeter.
I have put one thread group in my test plan and stick a 'Simple Controller' with two elements under it - 'HTTP Request' sampler and 'BSF PreProcessor'.
Set BSF language to 'javascript' and either type the code into the text box or point it to a file (use full path or relative to CWD of JMeter process).
/* Since `Math.random()` gives us float, we use `java.util.Random()`
* see: http://docs.oracle.com/javase/7/docs/api/java/util/Random.html */
var Random = new Packages.java.util.Random();
var min = 10-1;
var max = 2;
var maxLines = (min)+Random.nextInt(max-min);
var s = '';
for (var d = 0; d <= maxLines; d++) {
s += d.toString()+','+Random.nextInt(1000).toString()+'\n';
}
// s => '0,312\n1,104\n2,608\n'
vars.put('PAYLOAD', s);
Now I can refer to ${PAYLOAD} in the HTTP request!
You can generate JSON, but you will need to upgrade jakarta-jmeter-2.5.1/lib/js-1.6R5.jar with the newest version of Rhino to get JSON.stringify and JSON.parse. That worked perfectly for me also, though I thought I'd put a simple example here.
You can use BSF pre-processor for URL params as well, just set another variable with vars.put('X', 'some value') and pass it as ${X} in the request parameter.
This blog post helped quite a bit, by the way.

Make Lucene index a value and store another

I want Lucene.NET to store a value while indexing a modified, stripped-down version of the stored value. e.g. Consider the value:
this_example-has some/weird (chars) 100%
I want it stored right like that (so that I can retrieve exactly that for showing in the results list), but I want lucene to index it as:
this example has some weird chars 100
(you see, like a "sanitized" version of the original value) for a simplified search.
I figure this would be the job of an analyzer, but I don't want to mess with rolling my own. Ideally, the solution should remove everything that is not a letter, a number or quotes, replacing the removed chars by a white-space before indexing.
Any suggestions on how to implement that?
This is because I am indexing products for an e-commerce search, and some have realy creepy names. I think this would improve search assertiveness.
Thanks in advance.
If you don't want a custom analyzer, try storing the value as a separate non-indexed field, and use a simple regex to generate the sanitized version.
var input = "this_example-has some/weird (chars) 100%";
var output = Regex.Replace(input, #"[\W_]+", " ");
You mention that you need another Analyzer for some searching functionality. Dont forget the PerFieldAnalyzerWrapper which will allow you to use different analyzers within the same document.
public static void Main() {
var wrapper = new PerFieldAnalyzerWrapper(defaultAnalyzer: new StandardAnalyzer(Version.LUCENE_29));
wrapper.AddAnalyzer(fieldName: "id", analyzer: new KeywordAnalyzer());
IndexWriter writer = null; // TODO: Retrieve these.
Document document = null;
writer.AddDocument(document, analyzer: wrapper);
}
You are correct that this is the work of the analyzer. And I'd start by using a tool like luke to see what the standard analyzer does with your term before getting into what to use -- it tends to do a good job stripping noise characters and words.

#result_list = grep { test($_) } #unfiltered_list in other languages?

One of the features I love in Perl is the LISP-inspired (?) ability to filter content out of a list of things with the simple syntax
#result_list = grep { test($_) } #unfiltered_list;
where test function will be applied to all the items of #unfiltered_list to produce the #result_list.
Is that a feature that exists in other languages as well ? (PHP? Python?) Otherwise, how could I easily hint non-Perlers (students) about what I mean through such code ?
SOLUTION: filter in most languages, as seen on wikipedia. Thanks for the tip, dudes.
In python there is the filter function:
result_list = filter(test,unfiltered_list)
In C++0x you can do this using std::copy_if with a back_inserter iterator. Lambda functions make this even easier too.