Search Results

Search found 3479 results on 140 pages for 'chris w'.

Page 99/140 | < Previous Page | 95 96 97 98 99 100 101 102 103 104 105 106  | Next Page >

  • Validate HAML from ActiveRecord: scope/controller/helpers for link_to etc?

    - by Chris Boyle
    I like HAML. So much, in fact, that in my first Rails app, which is the usual blog/CMS thing, I want to render the body of my Page model using HAML. So here is app/views/pages/_body.html.haml: .entry-content= Haml::Engine.new(body, :format => :html5).render ...and it works (yay, recursion). What I'd like to do is validate the HAML in the body when creating or updating a Page. I can almost do that, but I'm stuck on the scope argument to render. I have this in app/models/page.rb: validates_each :body do |record, attr, value| begin Haml::Engine.new(value, :format => :html5).render(record) rescue Exception => e record.errors.add attr, "line #{(e.respond_to? :line) && e.line || 'unknown'}: #{e.message}" end end You can see I'm passing record, which is a Page, but even that doesn't have a controller, and in particular doesn't have any helpers like link_to, so as soon as a Page uses any of that it's going to fail to validate even when it would actually render just fine. So I guess I need a controller as scope for this, but accessing that from here in the model (where the validator is) is a big MVC no-no, and as such I don't think Rails gives me a way to do it. (I mean, I suppose I could stash a controller in some singleton somewhere or something, but... excuse me while I throw up.) What's the least ugly way to properly validate HAML in an ActiveRecord validator?

    Read the article

  • SL3 Grid RowDefinition Height Problem

    - by Chris
    I have a parent grid that contains multiple row definitions, all of which have their height set to 'auto'. Within the parent grid are individual grids - each individual grid contains a custom content control. When the custom content control loads, the height may increase. What I am noticing is that when the height does increase, the content overlaps with the content in other rows. I have specified the horizontal and vertical alignments - am I missing something? Here is an example: <Grid x:Name="LayoutRoot"> <Grid x:Name="ParentGrid>"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid Grid.Row="0"> <CustomContentControl/> </Grid> <Grid Grid.Row="1"> <CustomContentControl/> </Grid> <Grid Grid.Row="2"> <CustomContentControl/> </Grid> </Grid> </Grid>

    Read the article

  • How can I execute an ANTLR parser action for each item in a rule that can match more than one item?

    - by Chris Farmer
    I am trying to write an ANTLR parser rule that matches a list of things, and I want to write a parser action that can deal with each item in the list independently. Some example input for these rules is: $(A1 A2 A3) I'd like this to result in an evaluator that contains a list of three MyIdentEvaluator objects -- one for each of A1, A2, and A3. Here's a snippet of my grammar: my_list returns [IEvaluator e] : { $e = new MyListEvaluator(); } '$' LPAREN op=my_ident+ { /* want to do something here for each 'my_ident'. */ /* the following seems to see only the 'A3' my_ident */ $e.Add($op.e); } RPAREN ; my_ident returns [IEvaluator e] : IDENT { $e = new MyIdentEvaluator($IDENT.text); } ; I think my_ident is defined correctly, because I can see the three MyIdentEvaluators getting created as expected for my input string, but only the last my_ident ever gets added to the list (A3 in my example input). How can I best treat each of these elements independently, either through a grammar change or a parser action change? It also occurred to me that my vocabulary for these concepts is not what it should be, so if it looks like I'm misusing a term, I probably am. EDIT in response to Wayne's comment: I tried to use op+=my_ident+. In that case, the $op in my action becomes an IList (in C#) that contains Antlr.Runtime.Tree.CommonTree instances. It does give me one entry per matched token in $op, so I see my three matches, but I don't have the MyIdentEvaluator instances that I really want. I was hoping I could then find a rule attribute in the ANTLR docs that might help with this, but nothing seemed to help me get rid of this IList. Result... Based on chollida's answer, I ended up with this which works well: my_list returns [IEvaluator e] : { $e = new MyListEvaluator(); } '$' LPAREN (op=my_ident { $e.Add($op.e); } )+ RPAREN ; The Add method gets called for each match of my_ident.

    Read the article

  • Overloading stream insertion without violating information hiding?

    - by Chris
    I'm using yaml-cpp for a project. I want to overload the << and >> operators for some classes, but I'm having an issue grappling with how to "properly" do this. Take the Note class, for example. It's fairly boring: class Note { public: // constructors Note( void ); ~Note( void ); // public accessor methods void number( const unsigned long& number ) { _number = number; } unsigned long number( void ) const { return _number; } void author( const unsigned long& author ) { _author = author; } unsigned long author( void ) const { return _author; } void subject( const std::string& subject ) { _subject = subject; } std::string subject( void ) const { return _subject; } void body( const std::string& body ) { _body = body; } std::string body( void ) const { return _body; } private: unsigned long _number; unsigned long _author; std::string _subject; std::string _body; }; The << operator is easy sauce. In the .h: YAML::Emitter& operator << ( YAML::Emitter& out, const Note& v ); And in the .cpp: YAML::Emitter& operator << ( YAML::Emitter& out, const Note& v ) { out << v.number() << v.author() << v.subject() << v.body(); return out; } No sweat. Then I go to declare the >> operator. In the .h: void operator >> ( const YAML::Node& node, Note& note ); But in the .cpp I get: void operator >> ( const YAML::Node& node, Note& note ) { node[0] >> ? node[1] >> ? node[2] >> ? node[3] >> ? return; } If I write things like node[0] >> v._number; then I would need to change the CV-qualifier to make all of the Note fields public (which defeats everything I was taught (by professors, books, and experience))) about data hiding. I feel like doing node[0] >> temp0; v.number( temp0 ); all over the place is not only tedious, error-prone, and ugly, but rather wasteful (what with the extra copies). Then I got wise: I attempted to move these two operators into the Note class itself, and declare them as friends, but the compiler (GCC 4.4) didn't like that: src/note.h:44: error: ‘YAML::Emitter& Note::operator<<(YAML::Emitter&, const Note&)’ must take exactly one argument src/note.h:45: error: ‘void Note::operator(const YAML::Node&, Note&)’ must take exactly one argument Question: How do I "properly" overload the >> operator for a class Without violating the information hiding principle? Without excessive copying?

    Read the article

  • "Mail merge"-like functionality in Dreamweaver, or in any other web editing tool?

    - by Chris Farmer
    I have inherited several related, low-traffic web sites to manage and edit. These sites are implemented with static html, and they've accrued lots of stray tags and other cruft. I want to try to clean these up and migrate them to some common page template framework to simplify design and data changes and improve overall consistency. The pages will change on the timescale of weeks, and since the current web hosting plan does not support any dynamic server technologies, I was hoping to just use Dreamweaver or some other tool to merge my content data with some templating structure. I'd like to do content updates every several days and then run the content back through my templates, resulting in new static html that I can upload to the host. Do any tools support this kind of poor-man's data-driven web application? Are there better ways to approach this problem, aside from moving to a new hosting plan and using ASP.NET or PHP?

    Read the article

  • DDD: Enum like entities

    - by Chris
    Hi all, I have the following DB model: **Person table** ID | Name | StateId ------------------------------ 1 Joe 1 2 Peter 1 3 John 2 **State table** ID | Desc ------------------------------ 1 Working 2 Vacation and domain model would be (simplified): public class Person { public int Id { get; } public string Name { get; set; } public State State { get; set; } } public class State { private int id; public string Name { get; set; } } The state might be used in the domain logic e.g.: if(person.State == State.Working) // some logic So from my understanding, the State acts like a value object which is used for domain logic checks. But it also needs to be present in the DB model to represent a clean ERM. So state might be extended to: public class State { private int id; public string Name { get; set; } public static State New {get {return new State([hardCodedIdHere?], [hardCodeNameHere?]);}} } But using this approach the name of the state would be hardcoded into the domain. Do you know what I mean? Is there a standard approach for such a thing? From my point of view what I am trying to do is using an object (which is persisted from the ERM design perspective) as a sort of value object within my domain. What do you think? Question update: Probably my question wasn't clear enough. What I need to know is, how I would use an entity (like the State example) that is stored in a database within my domain logic. To avoid things like: if(person.State.Id == State.Working.Id) // some logic or if(person.State.Id == WORKING_ID) // some logic

    Read the article

  • Is "for(;;)" faster than "while (TRUE)"? If not, why do people use it?

    - by Chris Cooper
    for (;;) { //Something to be done repeatedly } I have seen this sort of thing used a lot, but I think it is rather strange... Wouldn't it be much clearer to say while (TRUE), or something along those lines? I'm guessing that (as is the reason for many-a-programmer to resort to cryptic code) this is a tiny margin faster? Why, and is it REALLY worth it? If so, why not just define it this way: #DEFINE while(TRUE) for(;;)

    Read the article

  • Javascript src starts with //?

    - by Chris
    I'm starting to see more and more script references show up like so: <script type="text/javascript" src="//somedomain.com/somescript.js"></script> Note the lack of http: at the beginning of the src attribute. It seems to work fine and avoids the messy requirement of detecting http vs https, but I've never actually seen this uri format referenced anywhere. Where did it come from? Is this behavior documented anywhere? Is it guaranteed to work in any browser?

    Read the article

  • ScaleTransform transforms non-linearly

    - by Chris
    I am using scale transform to allow a user to resize a control. What happens though is that when you start to move the mouse the control jumps to a new size, and then scales oddly. The further you move your mouse from the starting location the larger the increase in size becomes. I expect its the way I calculate the scale to be applied. Here is the code: private void ResizeGrip_MouseDown(object sender, MouseButtonEventArgs e) { ResizeHandle.CaptureMouse(); //Get the initial coordinate cursor location on the window initBtmX = e.GetPosition(this).X; bottomResize = true; } private void ResizeGrip_MouseUp(object sender, MouseButtonEventArgs e) { bottomResize = false; ResizeHandle.ReleaseMouseCapture(); } private void ResizeGrip_MouseMove(object sender, MouseEventArgs e) { if( bottomResize == true) { //Get the new Y coordinate cursor location double newBtmX = e.GetPosition(this).X; //Get the smallest change between the initial and new cursor location double diffX = initBtmX - newBtmX; // Let our rectangle capture the mouse ResizeHandle.CaptureMouse(); double newWidth = e.GetPosition(this).X - diffX; double scaler = newWidth / ResizeContainer.ActualWidth; Console.WriteLine("newWidth: {0}, scalar: {1}", newWidth, scaler); if (scaler < 0.75 || scaler > 3) return; ScaleTransform scale = new ScaleTransform(scaler, scaler); ResizeContainer.LayoutTransform = scale; } }

    Read the article

  • Determining CPU usage in WinCE

    - by Chris
    I want to be able to get the current % CPU usage in a C++ program running under Wince. I found this link that states where the source code is but I cannot find it in my platform builder installation - I expect this is because it isn't the Windows Automotive platform. Does anyone know where I can find this source code or (even better) know how I can get this information directly? i.e. what DLL / function calls to make etc.

    Read the article

  • How do I create and append an image with Javascript/jQuery?

    - by Chris Armstrong
    I'm using the following code to create an image element, load it, then append it to the article on load. $('<img />') .attr('src', 'image.png') //actually imageData[0].url .load(function(){ $('article').append( $(this) ); alert('image added'); }); The alert is firing off ok, but the image doesn't appear, and when I inspect the element it has been added without the closing slash <img src='image.png' > Why is the browser removing the forward slash and how do I stop it?

    Read the article

  • wordpress filters documentation? Trying to understand add_filter()

    - by Chris J. Lee
    I read over the documentation several times and have been having a hard time trying to figure out what is going on with the function. I'm more and more confused after looking at the documentation, looking over the source code as well. add_filter($tag, $hook, $priority, $args); it seems to me the new function extends the parent function. What puzzle's me is what parts of the hook becomes overridden. in some examples in the documentation i see that some variables are replaced with the $args in your new $tag. I almost understood it all here: http://www.andrewnacin.com/2010/05/18/rethinking-template-tags-in-plugins/ but then i couldn't figure out how you pass arguments and which eventually get overriden. thanks in advance.

    Read the article

  • How do you use FastInfoset with JAXWS?

    - by Chris Kessel
    I've got code that looks like it should be correct based on what I can find, but the spewed output doesn't indicate that it's using FastInfoset. My understanding is the Accept should indicate it can accept Fastinfoset and the response would actually use it, meaning it's not text/xml as the response type. Any idea what I'm doing wrong? I've scoured with Google and I'm having a hard time finding much detail on how to use FastInfoset at all. JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.getInInterceptors().add(new LoggingInInterceptor()); factory.getOutInterceptors().add(new LoggingOutInterceptor()); factory.setServiceClass( C360Server.class); factory.setAddress("http://localhost:8501/cxfcontroller/cl_v5"); C360Server client = (C360Server)factory.create(); ((BindingProvider)client).getRequestContext().put( "com.sun.xml.ws.client.ContentNegotiation", "optimistic"); C360Request requestTrans = new C360Request(); ... code to fill in the request ... C360Response response = client.findContacts( requestTrans ); The logging doesn't seem to indicate FastInfoset is even attempted though: INFO: Outbound Message --------------------------- ID: 1 Address: http://localhost:8501/cxfcontroller/cl_v5 Encoding: UTF-8 Content-Type: text/xml Headers: {SOAPAction=[""], Authorization=[Basic cWFfc3VwZXI6cWFfc3VwZXI=], Accept=[*/*]} Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:findContacts>...bunch of xml deleted for brevity...</ns1:findContacts></soap:Body></soap:Envelope> -------------------------------------- May 17, 2010 3:23:45 PM org.apache.cxf.interceptor.LoggingInInterceptor logging INFO: Inbound Message ---------------------------- ID: 1 Response-Code: 200 Encoding: UTF-8 Content-Type: text/xml; charset=utf-8 Headers: {content-type=[text/xml; charset=utf-8], Content-Length=[611], Server=[Jetty(6.1.x)]} Payload: <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><ns1:findContactsResponse>...bunch of xml spew deleted for brevity...</ns1:findContactsResponse></soap:Body></soap:Envelope> -------------------------------------- Any ideas what I'm doing wrong? Even if the server wasn't supporting FastInfoset, I still should see the attempted negotiation in the request, right?

    Read the article

  • What does it mean to do/determine something "programmatically"?

    - by Chris Lutz
    Programmatically. (alt. programmically) I've never used it, but I see it in questions a lot, i.e. "How to programmatically determine [insert task here]". Firefox immediately tells me that neither of these two words are real (at least, it doesn't recognize them). I've also never seen them used anywhere but here. 1) What does it mean to do/determine something "programmatically"? 2) Why do so many people ask how to do/determine something "programmatically"? Isn't it assumed that, if you're asking how to do something on a programming help board, you're asking how to do it "programmatically"? 3) Why is it that I've never seen the word "programmatically" anywhere else?

    Read the article

  • Best way to get free driving instructions

    - by Chris
    Is there a simple way to get driving instructions? Something like: I call "http://someservice/?start=NYC&target=Washington" and then the service returns a XML file containing routing information? Has anybody ever tried to access such a web-based service from a standalone desktop application? Any help would really be appreciated! Update: Thanks for the hints, but unfortunately I can't run JavaScript. Is there still a possibility to receive driving instructions?

    Read the article

  • jQuery drawing and modifying lines and positions

    - by Chris
    I want to allow people to select a feature region on an image using jQuery. This should work similarly to the Facebook tagger except once someone "tags" an area of the image an ellipse should appear with the ability for the user to rotate and scale it. How can I achieve this using jQuery?

    Read the article

  • Java: How to test methods that call System.exit()?

    - by Chris Conway
    I've got a few methods that should call System.exit() on certain inputs. Unfortunately, testing these cases causes JUnit to terminate! Putting the method calls in a new Thread doesn't seem to help, since System.exit() terminates the JVM, not just the current thread. Are there any common patterns for dealing with this? For example, can I subsitute a stub for System.exit()? [EDIT] The class in question is actually a command-line tool which I'm attempting to test inside JUnit. Maybe JUnit is simply not the right tool for the job? Suggestions for complementary regression testing tools are welcome (preferably something that integrates well with JUnit and EclEmma).

    Read the article

  • C# Resources - How to find actual language file in use?

    - by Chris Meek
    I have a number resx files as follows, Resources-es-ES.resx Resources-es.resx Resources.resx (english defaults) They are compiled into an assembly and I use them for localising my web pages by simply referring to Resources.Ok for example. My question is whether there is a way to find out the "rendered culture", e.g. if I come into the site with my CurrentUICulture set to "fr-fr" for example it will fall back to using the English resources and I'm wondering how to get that information to help me with some JavaScript localisation.

    Read the article

  • VS2010 almost always zooms text on scroll

    - by Chris Barr
    You know the neat text zoom feature in VS2010 where you hold down Ctrl and then use your scroll wheel? Well, this seems to happen by default (and without ever pressing Ctrl) to nearly every file I open. Usually I open a file and have to scroll to some lower point, but instead it starts zooming the text! I have found that by tapping the Ctrl key VS then realizes that it should scroll instead of zoom, but it's still very annoying. Any ideas?

    Read the article

  • Heavy use of templates for mobile platforms

    - by Chris P. Bacon
    I've been flicking through the book Modern C++ Design by Andrei Alexandrescu and it seems interesting stuff. However it makes very extensive use of templates and I would like to find out if this should be avoided if using C++ for mobile platform development (Brew MP, WebOS, iOS etc.) due to size considerations. In Symbian OS C++ the standard use of templates is discouraged, the Symbian OS itself uses them but using an idiom known as thin templates where the underlying implementation is done in a C style using void* pointers with a thin template layered on top of this to achieve type safety. The reason they use this idiom as opposed to regular use of templates is specifically to avoid code bloating. So what are opinions (or facts) on the use of templates when developing applications for mobile platforms.

    Read the article

  • UILabels NOT Updating

    - by Chris Calleja Urry
    i have a UITableView that is being populated by core data , now , when i click on a cell , it pushes me to another view where i can edit the data that is in that particular index , when i return , the system either crashes or else doesnt load the changes onto the labels , any ideas ? code below -(void)viewWillAppear:(BOOL)animated { searchCriteria = [[NSMutableString alloc] initWithString:@"clientName"]; NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"clientName" ascending:YES]; NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDescriptors]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Client" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"]; [self.clientTableView reloadData]; [super viewWillAppear:animated]; } and -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } Client * client = [self.fetchedResultsController objectAtIndexPath:indexPath]; clientNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 250.00, 30.0)]; clientNameLabel.tag = 1; clientNameLabel.backgroundColor = [UIColor clearColor]; clientNameLabel.textColor = [UIColor whiteColor]; clientNameLabel.font = [UIFont boldSystemFontOfSize:13]; clientNameLabel.text = client.clientName; [cell.contentView addSubview:clientNameLabel]; clientAccountNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 35.0, 250.00, 30.00)]; clientAccountNumberLabel.tag = 2; clientAccountNumberLabel.textColor = [UIColor whiteColor]; clientAccountNumberLabel.backgroundColor = [UIColor clearColor]; clientAccountNumberLabel.font = [UIFont boldSystemFontOfSize:13]; clientAccountNumberLabel.text = client.clientAccountNumber; [cell.contentView addSubview:clientAccountNumberLabel]; clientTelephoneNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(300.0, 0.0, 250, 30.00)]; clientTelephoneNumberLabel.tag = 3; clientTelephoneNumberLabel.textColor = [UIColor whiteColor]; clientTelephoneNumberLabel.backgroundColor = [UIColor clearColor]; clientTelephoneNumberLabel.font = [UIFont boldSystemFontOfSize:13]; [cell.contentView addSubview:clientTelephoneNumberLabel]; addressLine1Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)]; addressLine1Label.tag = 4; addressLine1Label.textColor = [UIColor whiteColor]; addressLine1Label.backgroundColor = [UIColor clearColor]; addressLine1Label.font = [UIFont boldSystemFontOfSize:13]; addressLine1Label.text = client.addressLine1; [cell.contentView addSubview:addressLine1Label]; addressLine2Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)]; addressLine2Label.tag = 5; addressLine2Label.textColor = [UIColor whiteColor]; addressLine2Label.backgroundColor = [UIColor clearColor]; addressLine2Label.text = client.addressLine2; addressLine2Label.font = [UIFont boldSystemFontOfSize:13]; [cell.contentView addSubview:addressLine2Label]; addressLine3Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)]; addressLine3Label.tag = 6; addressLine3Label.textColor = [UIColor whiteColor]; addressLine3Label.backgroundColor = [UIColor clearColor]; addressLine3Label.font = [UIFont boldSystemFontOfSize:13]; addressLine3Label.text = client.addressLine3; [cell.contentView addSubview:addressLine3Label]; addressLine4Label = [[UILabel alloc] initWithFrame:CGRectMake(315.0, 35.0, 250, 30.00)]; addressLine4Label.tag = 7; addressLine4Label.textColor = [UIColor whiteColor]; addressLine4Label.backgroundColor = [UIColor clearColor]; addressLine4Label.font = [UIFont boldSystemFontOfSize:13]; addressLine4Label.text = client.addressLine4; [cell.contentView addSubview:addressLine4Label]; return cell; } The Crash Logs are as follows : 2012-06-23 17:08:05.541 iSalesForce[11773:15803] no object at index 1 in section at index 0 And some other code you might find useful are : - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [fetchedObjects count]; } - (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 70.0; }

    Read the article

  • using Visual Studio 2008 to test an x64 .NET binary

    - by Chris Gray
    I have an x64 managed C++ class that needs to be tested using Visual Studio 2008. This class links to a x64 unmanaged lib I'm not able to run my my tests because vstesthost.exe (the exe Visual Studio hosts my test) is x86 and not x64. Ideas? the error generated is rror: System.BadImageFormatException: Could not load file or assembly ... or one of its dependencies. An attempt was made to load

    Read the article

< Previous Page | 95 96 97 98 99 100 101 102 103 104 105 106  | Next Page >