Let's say I have a simple ASP.NET MVC site with two views. The views use the following routes: /Foo and /Foo/Bar.
Now let's say I want to use the URL to specify (just for the sake of example) the background color of the site. I want my routes to be, for instance, /Blue/Foo or /Green/Foo/Bar.
Also, if I call Html.ActionLink from a view, I want the Blue or Green value to propagate. So, e.g., if I call Html.ActionLink("Bar", "Foo") from /Blue/Foo, I want /Blue/Foo/Bar to come back.
How best can I do this?
(Forgive me if I'm missing an existing post. This is hard for me to articulate concisely, so I'm not quite sure what to search for.)
A note - the classes I have are EntityObject classes!
I have the following class:
public class Foo
{
public Bar Bar { get; set; }
}
public class Bar : IDataErrorInfo
{
public string Name { get; set; }
#region IDataErrorInfo Members
string IDataErrorInfo.Error
{
get { return null; }
}
string IDataErrorInfo.this[string columnName]
{
get
{
if (columnName == "Name")
{
return "Hello error!";
}
Console.WriteLine("Validate: " + columnName);
return null;
}
}
#endregion
}
XAML goes as follows:
<StackPanel Orientation="Horizontal" DataContext="{Binding Foo.Bar}">
<TextBox Text="{Binding Path=Name, ValidatesOnDataErrors=true}"/>
</StackPanel>
I put a breakpoint and a Console.Writeline on the validation there - I get no breaks. The validation is not executed. Can anybody just press me against the place where my error lies?
I am trying to do the following:
public class foo<T> where T : bar, new
{
_t = new T();
private T _t;
}
public abstract class bar
{
public abstract void someMethod();
// Some implementation
}
public class baz : bar
{
public overide someMethod(){//Implementation}
}
And I am attempting to use it as follows:
foo<baz> fooObject = new foo<baz>();
And I get an error explaining that 'T' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method. I fully understand why this must be, and also understand that I could pass a pre-initialized object of type 'T' in as a constructor argument to avoid having to 'new' it, but is there any way around this? any way to enforce classes that derive from 'bar' to supply parameterless constructors?
I have a class foo with an enum template parameter and for some reason it links to two versions of the ctor in the cpp file.
enum Enum
{
bar,
baz
};
template <Enum version = bar>
class foo
{
public:
foo();
};
// CPP File
#include "foo.hpp"
foo<bar>::foo() { cout << "bar"; }
foo<baz>::foo() { cout << "baz"; }
I'm using msvc 2008, is this the standard behavior?
Are only type template parameters cannot be linked to cpp files?
info = {'phone_number': '123456', 'personal_detail': {'foo':foo, 'bar':bar}, 'is_active': 1, 'document_detail': {'baz':baz, 'saz':saz}, 'is_admin': 1, 'email': '[email protected]'}
return HttpResponse(simplejson.dumps({'success':'True', 'result':info}), mimetype='application/javascript')
if(data["success"] === "True") {
alert(data[**here I want to display personal_detail and document_details**]);
}
How can I do this?
Hello,
I am trying to write a frequency program that will represent a bar diagram (in console code).
The problem is i have no idea how exactly to caculate this frequency or how do i exactly then give the bars different heights according to there frequency (trough calculation).
The frequency height is capped at 21. (meaning the bars go from 1 to 21, so the max bar height would be for example 21 stars(* as display sign for the bar itself).
A calculation i have so far (although not sure if correct) for frequency:
This array takes the random values generated:
for (int j = 0; j < T.Length; j++)
{
T[j] = (MaxHeight* T[j]) / Ber.GreatestElement(T);
Console.Write("{0,7}", T[j]);
}
This results in values between 0 and 21 -- Based on the values my bars should give a certain height compared to all the other frequency values. (for example 8000 could have 21 in height where 39 could have 1).
To represent this diagram i used 2 for loops to display height and width (keep in mind i only wish to use Using System; to keep it to the "basics").
for (int height= 1; height<= 21; height++)
{
for (int width= 0; width<= 10; width++)
{
if(...??)
{
Console.Write("{0,7}", bar); // string bar= ("*");
}
else
{
Console.Write("{0,7}", empty);
}
}
Console.WriteLine();
}
So so far i have a entire field filled with * and the random values generated along with their frequency value (although i have no idea if the freq value is properly calculated).
I assume i need a if (.....) in the second for but i cannot seem to get further then this.
Thanks in advance!
I want to fetch the id of a one-to-one relationship without loading the entire object. I thought I could do this using lazy loading as follows:
class Foo {
@OneToOne(fetch = FetchType.LAZY, optional = false)
private Bar bar;
}
Foo f = session.get(Foo.class, fooId); // Hibernate fetches Foo
f.getBar(); // Hibernate fetches full Bar object
f.getBar().getId(); // No further fetch, returns id
I want f.getBar() to not trigger another fetch. I want hibernate to give me a proxy object that allows me to call .getId() without actually fetching the Bar object.
What am I doing wrong?
This is just an example, but given the following model:
class Foo(models.model):
bar = models.IntegerField()
def __str__(self):
return str(self.bar)
def __unicode__(self):
return str(self.bar)
And the following QuerySet object:
foobar = Foo.objects.filter(bar__lt=20).distinct()
(meaning, a set of unique Foo models with bar <= 20), how can I generate all possible subsets of foobar? Ideally, I'd like to further limit the subsets so that, for each subset x of foobar, the sum of all f.bar in x (where f is a model of type Foo) is between some maximum and minimum value.
So, for example, given the following instance of foobar:
>> print foobar
[<Foo: 5>, <Foo: 10>, <Foo: 15>]
And min=5, max=25, I'd like to build an object (preferably a QuerySet, but possibly a list) that looks like this:
[[<Foo: 5>], [<Foo: 10>], [<Foo: 15>], [<Foo: 5>, <Foo: 10>],
[<Foo: 5>, <Foo: 15>], [<Foo: 10>, <Foo: 15>]]
I've experimented with itertools but it doesn't seem particularly well-suited to my needs.
I think this could be accomplished with a complex QuerySet but I'm not sure how to start.
What is the syntax for the hash value for a Perl object member subroutine reference in a dispatch table?
use lib Alpha;
my $foo = new Alpha::Foo;
$foo->bar();
my %disp_table = ( bar => ??? );
I want ??? to be the code reference for $foo->bar().
This is a followup question to my previous question.
#include <functional>
int foo(void) {return 2;}
class bar {
public:
int operator() (void) {return 3;};
int something(int a) {return a;};
};
template <class C> auto func(C&& c) -> decltype(c()) { return c(); }
template <class C> int doit(C&& c) { return c();}
template <class C> void func_wrapper(C&& c) { func( std::bind(doit<C>, std::forward<C>(c)) ); }
int main(int argc, char* argv[])
{
// call with a function pointer
func(foo);
func_wrapper(foo); // error
// call with a member function
bar b;
func(b);
func_wrapper(b);
// call with a bind expression
func(std::bind(&bar::something, b, 42));
func_wrapper(std::bind(&bar::something, b, 42)); // error
// call with a lambda expression
func( [](void)->int {return 42;} );
func_wrapper( [](void)->int {return 42;} );
return 0;
}
I'm getting a compile errors deep in the C++ headers:
functional:1137: error: invalid initialization of reference of type ‘int (&)()’ from expression of type ‘int (*)()’
functional:1137: error: conversion from ‘int’ to non-scalar type ‘std::_Bind(bar, int)’ requested
func_wrapper(foo) is supposed to execute func(doit(foo)). In the real code it packages the function for a thread to execute. func would the function executed by the other thread, doit sits in between to check for unhandled exceptions and to clean up. But the additional bind in func_wrapper messes things up...
I have a Perl module and I'd like to be able to pick out the parameters that my my module's user passed in the "use" call. Whichever ones I don't recognize I'd like to pass on. I tried to do this by overriding the "import" method but I'm not having much luck.
EDIT:
To clarify, as it is, I can use my module like this:
use MyModule qw/foo bar/;
which will import the foo and bar methods of MyModule. But I want to be able to say:
use MyModule qw/foo doSpecialStuff bar/;
and look for doSpecialStuff to check if I need to do some special stuff at the beginning of the program, then pass qw/foo bar/ to the Exporter's import
Hey guys,
I'd like to simulate a flag in an xslt script. The idea is for template foo to set a flag (or a counter variable, or anything), so that it can be accessed from template bar. Bar isn't called from foo, but from a common parent template (otherwise I would pass a parameter to it). The structure is like this:
<xsl:template match="bla">
<xsl:apply-templates select="foo"/> <!-- depending on the contents of foo... -->
<xsl:apply-templates select="bar"/> <!-- ... different things should happen in bar -->
</xsl:template>
Any tricks are much appreciated.
typedef struct Pair_s {
char *first;
char *second;
} Pair;
Pair pairs[] = {
{"foo", "bar"}, //this is fine
{"bar", "baz"}
};
typedef struct PairOfPairs_s {
Pair *first;
Pair *second;
} PairOfPairs;
PairOfPairs pops[] = {
{{"foo", "bar"}, {"bar", "baz"}}, //How can i create an equivalent of this NEATLY
{&pairs[0], &pairs[1]} //this is not considered neat (imagine trying to read a list of 30 of these)
};
How can I achieve the above style declaration semantics?
In F#, given the following class:
type Foo() =
member this.Bar<'t> (arg0:string) = ignore()
Why does the following compile:
let f = new Foo()
f.Bar<Int32> "string"
While the following won't compile:
let f = new Foo()
"string" |> f.Bar<Int32> //The compiler returns the error: "Unexpected type application"
Hello,
In some Python unit tests of a program I'm working on we use in-memory zipfiles for end to end tests. In SetUp() we create a simple zip file, but in some tests we want to overwrite some archives. For this we do "zip.writestr(archive_name, zip.read(archive_name) + new_content)". Something like
import zipfile
from StringIO import StringIO
def Foo():
zfile = StringIO()
zip = zipfile.ZipFile(zfile, 'a')
zip.writestr(
"foo",
"foo content")
zip.writestr(
"bar",
"bar content")
zip.writestr(
"foo",
zip.read("foo") +
"some more foo content")
print zip.read("bar")
Foo()
The problem is that this works fine in Python 2.4 and 2.5, but not 2.6. In Python 2.6 this fails on the print line with "BadZipfile: File name in directory "bar" and header "foo" differ."
It seems that it is reading the correct file bar, but that it thinks it should be reading foo instead.
I'm at a loss. What am I doing wrong? Is this not supported? I tried searching the web but could find no mention of similar problems. I read the zipfile documentation, but could not find anything (that I thought was) relevant, especially since I'm calling read() with the filename string.
Any ideas?
Thank you in advance!
Is it possible to create a decorator which can be __init__'d with a set of arguments, then later have methods called with other arguments?
For instance:
from foo import MyDecorator
bar = MyDecorator(debug=True)
@bar.myfunc(a=100)
def spam():
pass
@bar.myotherfunc(x=False)
def eggs():
pass
If this is possible, can you provide a working example?
I know how to specialise a template function, however what I want to do here is specialise a function for all types which have a given method, eg:
template<typename T> void foo(){...}
template<typename T, if_exists(T::bar)>void foo(){...}//always use this one if the method T::bar exists
T::bar in my classes is static and has different return types.
I tried doing this by having an empty base class ("class HasBar{};") for my classes to derive from and using boost::enable_if with boost::is_base_of on my "specialised" version. However the problem then is that for classes that do have bar, the compiler cant resolve which one to use :(.
template<typename T>
typename boost::enable_if<boost::is_base_of(HasBar, T>, void>::type f()
{...}
I know that I could use boost::disable_if on the "normal" version, however I do not control the normal version (its provided by a third party library and its expected for specialisations to be made, I just don't really want to make explicit specialisations for my 20 or so classes), nor do I have that much control over the code using these functions, just the classes implementing T::bar and the function that uses it.
Is there some way to tell the compiler to "always use this version if possible no matter what" without altering the other versions?
I'm a bit confused by the proper frame sizing of a table view to fit within my screen.
Here's my setup of view controllers within view controllers:
UITabBarController
UINavigationController as one of the tab bar viewcontrollers; title bar hidden
ViewController - a container view controller because I need the option to place some controls beneath the UITableView, sometimes (but not in the current scenario)
UITableViewController
Now, my question is what the proper frame dimensions of the UITableview should be. Here's what I've got in the ViewController viewDidLoad method. I used subtracted 49.0 (the size of the tab bar) from 480.0. However, this leaves a black bar at the bottom. 20.0 appears to do it (coincidentally?) the size of the status bar, but I don't understand why that would be. Wouldn't the true pixel dimensions of the tableview be 480-49?
// MessageTableViewController is my subclass of UITableViewController
MessagesTableViewController *vcMessagesTable = [[MessagesTableViewController alloc] init];
CGRect tableViewFrame = CGRectMake(0, 0, 320.0, 480.0 - 49.0);
[[vcMessagesTable view] setFrame:tableViewFrame];
self.tableViewController = vcMessagesTable;
[self addChildViewController:vcMessagesTable];
[[self view] addSubview:vcMessagesTable.view];
Here's how it looks:
I need a regex that will match blahfooblah but not blahfoobarblah
I want it to match only foo and everything around foo, as long as it isn't followed by bar.
I tried using this: foo.*(?<!bar) which is fairly close, but it matches blahfoobarblah. The negative look behind needs to match baranything and not just bar.
The specific language I'm using is Clojure which uses Java regexes under the hood.
First off, the title is very generic because there are just tons of ways of how to possibly solve this. However, I'm looking for a clean and neat way.
Situation:
I have two equal object files foo.o and foo-pi.o, the latter of which is position-independent (compiled with -fPIC). Both depend on foo.h and bar.h.
Problem:
How do I, without code duplication, declare dependency of all foo*.o to bar.h?
Solutions so far:
$(shell bash -c 'echo -ne foo{-pi,}.o'}: bar.h
$(addsuffix .o, $(addprefix fo, o-pi o)): bar.h
The first solution is not portable on systems that don't support bash, the second is a dirty solution since I could not figure out how to use empty strings in addprefix.
Starting from an Html input like this:
<p>
<a href="http://www.foo.com" rel="nofollow">this is foo</a>
<a href="http://www.bar.com" rel="nofollow">this is bar</a>
</p>
is it possible to modify the <a> node values ("this i foo" and "this is bar") adding the suffix "PARSED" to the value without recreating the all link?
The result need to be like this:
<p>
<a href="http://www.foo.com" rel="nofollow">this is foo_PARSED</a>
<a href="http://www.bar.com" rel="nofollow">this is bar_PARSED</a>
</p>
And code should be something like:
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup(html)
for link_tag in soup.findAll('a'):
link_tag.string = link_tag.string + '_PARSED' #This obviously does not work
I have factory that looks something like the following snippet. Foo is a wrapper class for Bar and in most cases (but not all), there is a 1:1 mapping. As a rule, Bar cannot know anything about Foo, yet Foo takes an instance of Bar. Is there a better/cleaner approach to doing this?
public Foo Make( Bar obj )
{
if( obj is Bar1 )
return new Foo1( obj as Bar1 );
if( obj is Bar2 )
return new Foo2( obj as Bar2 );
if( obj is Bar3 )
return new Foo3( obj as Bar3 );
if( obj is Bar4 )
return new Foo3( obj as Bar4 ); // same wrapper as Bar3
throw new ArgumentException();
}
At first glance, this question might look like a duplicate (maybe it is), but I haven't seen one exactly like it. Here is one that is close, but not quite:
http://stackoverflow.com/questions/242097/factory-based-on-typeof-or-is-a
Hypothetical situation that I'm struggling to get my head past.
HoldsFooBar.h:
#include "foo.h"
#include "bar.h"
class HoldsFooBar{
foo F;
bar B;
};
foo.h:
//includes?
class foo{
HoldsFooBar *H;
void Baz();
};
bar.h:
//includes?
class bar{
HoldsFooBar *H;
void Qux();
};
I'm trying to get F to get a hold of B. In all other languages I've worked with, I would be able to H->B.Qux();, but I'm totally lost in C++. At the includes lines in foo.h and bar.h, it seems like my options are to forward-declare class HoldsFooBar; but then I can only access H, and F and B cannot see each other. Likewise, I can #include "HoldsFooBar.h" but because of my include guards, something ends up not getting linked properly, so the program doesn't run.
Is what I'm trying to do even possible? Thank you very much! Any help would be appreciated!
I don't understand from jQuery documentation how "$.when" method works. I'm am new in jQuery, so sorry if my question is too simple.
I am trying to do something like this:
var tableProgress;
tableProgress = "<table id='table-progress'><tr><td></td></tr></table>"
$.when(
$("#send-one").html('done. ' + tableProgress)
).done( function() {
$('#table-progress').dataTable();
} );
It does not work, I think it's because .dataTable() pluggin can't find the table so I am trying to use jQuery $.when.
What I need is: use .datatable pluggin in a table that is inserted in
$("#send-one").html('done. ' + tableProgress)
but, using .datatable() directly may not be synchronous to the insertion.
I also tryied:
$("#send-one").html('done. ' + tableProgress);
$('#table-progress').dataTable();
Could you please help me?