Search Results

Search found 9 results on 1 pages for 'captncraig'.

Page 1/1 | 1 

  • Hexagonal Grid Coordinates To Pixel Coordinates

    - by CaptnCraig
    I am working with a hexagonal grid. I have chosen to use this coordinate system because it is quite elegant. This question talks about generating the coordinates themselves, and is quite useful. My issue now is in converting these coordinates to and from actual pixel coordinates. I am looking for a simple way to find the center of a hexagon with coordinates x,y,z. Assume (0,0) in pixel coordinates is at (0,0,0) in hex coords, and that each hexagon has an edge of length s. It seems to me like x,y, and z should each move my coordinate a certain distance along an axis, but they are interrelated in an odd way I can't quite wrap my head around it. Bonus points if you can go the other direction and convert any (x,y) point in pixel coordinates to the hex that point belongs in.

    Read the article

  • Making Ninject Interceptors work with async methods

    - by captncraig
    I am starting to work with ninject interceptors to wrap some of my async code with various behaviors and am having some trouble getting everything working. Here is an interceptor I am working with: public class MyInterceptor : IInterceptor { public async void Intercept(IInvocation invocation) { try { invocation.Proceed(); //check that method indeed returns Task await (Task) invocation.ReturnValue; RecordSuccess(); } catch (Exception) { RecordError(); invocation.ReturnValue = _defaultValue; throw; } } This appears to run properly in most normal cases. I am not sure if this will do what I expect. Although it appears to return control flow to the caller asynchronously, I am still a bit worried about the possibility that the proxy is unintentionally blocking a thread or something. That aside, I cannot get the exception handling working. For this test case: [Test] public void ExceptionThrown() { try { var interceptor = new MyInterceptor(DefaultValue); var invocation = new Mock<IInvocation>(); invocation.Setup(x => x.Proceed()).Throws<InvalidOperationException>(); interceptor.Intercept(invocation.Object); } catch (Exception e) { } } I can see in the interceptor that the catch block is hit, but the catch block in my test is never hit from the rethrow. I am more confused because there is no proxy or anything here, just pretty simple mocks and objects. I also tried something like Task.Run(() => interceptor.Intercept(invocation.Object)).Wait(); in my test, and still no change. The test passes happily, but the nUnit output does have the exception message. I imagine I am messing something up, and I don't quite understand what is going on as much as I think I do. Is there a better way to intercept an async method? What am I doing wrong with regards to exception handling?

    Read the article

  • Select Box not filling properly in rails

    - by CaptnCraig
    I am creating a select box for a form using this in _form.html.erb <%= f.select(:category_id,options_for_select(@cats)) %> @cats is an array created in my controller like this: @cats = [] categories.each do |c| @cats.push([c.full_name,c.id]) end The select box is properly filled, and the selected foreign key is even properly saved to the database. The problem is, when I come back in my edit action, the select box is moved back to the first item in the list, not the one corresponding to category_id. Reading the documentation it seems like this should just magically work. How do I get it to select the proper value?

    Read the article

  • Saving multiple objects in a single call in rails

    - by CaptnCraig
    I have a method in rails that is doing something like this: a = Foo.new("bar") a.save b = Foo.new("baz") b.save ... x = Foo.new("123", :parent_id => a.id) x.save ... z = Foo.new("zxy", :parent_id => b.id) z.save The problem is this takes longer and longer the more entities I add. I suspect this is because it has to hit the database for every record. Since they are nested, I know I can't save the children before the parents are saved, but I would like to save all of the parents at once, and then all of the children. It would be nice to do something like: a = Foo.new("bar") b = Foo.new("baz") ... saveall(a,b,...) x = Foo.new("123", :parent_id => a.id) ... z = Foo.new("zxy", :parent_id => b.id) saveall(x,...,z) That would do it all in only two database hits. Is there an easy way to do this in rails, or am I stuck doing it one at a time?

    Read the article

  • Output to console while preserving user input in ruby

    - by CaptnCraig
    I have a ruby script that is simultaneously and asynchronously receiving and displaying messages from a server, and allowing user input on the console. When a message is received, it is currently being written in the middle of what the user is typing. The input itself isn't garbled, but it looks horrible. Ideally, it would save the users current input, output the message, and then restore the input on the next line. I've done this in c by intercepting every key stroke, but all I remember is that it was a major hassle. I'm fairly new to ruby, so I'm not sure if there is a good way to do this, or how to do it. Example: User is typing >abcde, and message hello comes in, and user types fgh after. The console would now show: >abcdehellofgh and user can continue typing at the end. I would like it to show: hello >abcdefgh

    Read the article

  • Multiple children in single form in rails

    - by CaptnCraig
    I have a model that has an arbitrary number of children entities. For simplicity lets call the entities Orders and Items. I would like to have a create Orders form where I input the order information, as well as add as many items as I want. If I click the "Add another item" button, a new set of form elements will be added to input the new data, amounts, etc.. I could hack this out in pure javascript, but I'm pretty sure there has to be a more magical, railsish way to do it, maybe with a partial view or something. I'm just a little too new to rails to know what it is. What is the best way to dynamically add the new form elements, and then to access them in the create controller?

    Read the article

  • Getting all types from an assembly derived from a base class

    - by CaptnCraig
    I am trying to examine the contents of an assembly and find all classes in it that are directly or indirectly derived from Windows.Forms.UserControl. I am doing this: Assembly dll = Assembly.LoadFrom(filename); var types = dll.GetTypes().Where(x => x.BaseType == typeof(UserControl)); But it is giving an empty list because none of the classes directly extend UserControl. I don't know enough about reflection to do it quickly, and I'd rather not write a recursive function if I don't have to.

    Read the article

  • Initialize generic object from a System.Type

    - by CaptnCraig
    I need to create a generic type, but I do not know the type at compile time. I would like to do this: Type t = typeof(whatever); var list = new List<t> this won't compile, because t is not a valid type. But it does know all about a valid type. Is there a way to dynamically create the generic list from a System.Type like this? I may need reflection, and that's ok, I am just a bit lost here.

    Read the article

  • Mutually exclusive regular expressions

    - by CaptnCraig
    If I have a list of regular expressions, is there an easy way to determine that no two of them will both return a match for the same string? That is, the list is valid if and only if for all strings a maximum of one item in the list will match the entire string. It seems like this will be very hard (maybe impossible?) to prove definitively, but I can't seem to find any work on the subject. The reason I ask is that I am working on a tokenizer that accepts regexes, and I would like to ensure only one token at a time can match the head of the input.

    Read the article

1