Search Results

Search found 3280 results on 132 pages for 'michael van cleave'.

Page 37/132 | < Previous Page | 33 34 35 36 37 38 39 40 41 42 43 44  | Next Page >

  • How can Swing dialogs even work?

    - by Bart van Heukelom
    If you open a dialog in Swing, for example a JFileChooser, it goes somewhat like this pseudocode: swing event thread { create dialog add listener to dialog close event { returnValue = somethingFromDialog } show dialog (wait until it is closed) return returnValue } My question is: how can this possibly work? As you can see the thread waits to return until the dialog is closed. This means the Swing event thread is blocked. Yet, one can interact with the dialog, which AFAIK requires this thread to run. So how does that work?

    Read the article

  • Problem with between join for sqlalchemy orm relation.

    - by Gary van der Merwe
    I'm trying to create a relation that has a between join. Here is a shortish example of what I'm trying to do: #!/usr/bin/env python import sqlalchemy as sa from sqlalchemy import orm from sqlalchemy.engine.base import Engine from sqlalchemy.ext.declarative import declarative_base metadata = sa.MetaData() Base = declarative_base(metadata=metadata) engine = sa.create_engine('sqlite:///:memory:') class Network(Base): __tablename__ = "network" id = sa.Column(sa.Integer, primary_key=True) ip_net_addr_db = sa.Column('ip_net_addr', sa.Integer, index=True) ip_broadcast_addr_db = sa.Column('ip_broadcast_addr', sa.Integer, index=True) # This can be determined from the net address and the net mask, but we store # it in the db so that we can join with the address table. ip_net_mask_len = sa.Column(sa.SmallInteger) class Address(Base): __tablename__ = "address" ip_addr_db = sa.Column('ip_addr', sa.Integer, primary_key=True, index=True, unique=True) Network.addresses = orm.relation(Address, primaryjoin=Address.ip_addr_db.between( Network.ip_net_addr_db, Network.ip_broadcast_addr_db), foreign_keys=[Address.ip_addr_db]) metadata.create_all(engine) Session = orm.sessionmaker(bind=engine) Network() I you run this, you get this error: ArgumentError: Could not determine relation direction for primaryjoin condition 'address.ip_addr BETWEEN network.ip_net_addr AND network.ip_broadcast_addr', on relation Network.addresses. Do the columns in 'foreign_keys' represent only the 'foreign' columns in this join condition ? The answer to that question is Yes, but I cant figure out how to tell it that

    Read the article

  • getting base64 content string of an image from a mimepart in Java

    - by Bas van den Broek
    Hello, I am trying to get the base64 content of a MimePart in a MimeMultiPart, but I'm struggling with the Javamail package. I simply want the base64 encoded String of a certain inline image, there doesn't seem to be an easy way to do this though. I wrote a method that will take the mime content (as a string) and an image name as a parameter, and searches for the part that contains the base64 content of that image name, and in the end returns this base64 string (as well as the content type but that is irrelevant for this question) Here is the relevant code: private static String[] getBase64Content(String imageName, String mimeString) throws MessagingException, IOException { System.out.println("image name: " + imageName + "\n\n"); System.out.println("mime string: " + mimeString); String[] base64Content = new String[2]; base64Content[0] = ""; base64Content[1] = "image/jpeg"; //some default value DataSource source = new ByteArrayDataSource(new ByteArrayInputStream(mimeString.getBytes()), "multipart/mixed"); MimeMultipart mp = new MimeMultipart(source); for (int i = 0; i < mp.getCount(); i++) { MimePart part = (MimePart) mp.getBodyPart(i); String disposition = part.getDisposition(); if (disposition != null && disposition.equals(Part.INLINE)) { if (part.getContentID() != null && part.getContentID().indexOf(imageName) > -1) //check if this is the right part { if (part.getContent() instanceof BASE64DecoderStream) { BASE64DecoderStream base64DecoderStream = (BASE64DecoderStream) part.getContent(); StringWriter writer = new StringWriter(); IOUtils.copy(base64DecoderStream, writer); String base64decodedString = writer.toString(); byte[] encodedMimeByteArray = Base64.encodeBase64(base64decodedString.getBytes()); String encodedMimeString = new String(encodedMimeByteArray); System.out.println("encoded mime string: " + encodedMimeString); base64Content[0] = encodedMimeString; base64Content[1] = getContentTypeString(part); } } } } return base64Content; } I cannot paste all of the output as the post would be too long, but this is some of it: image name: [email protected] This is a part of the mimeString input, it does find this (correct) part with the image name: --_004_225726A14AF9134CB538EE7BD44373A04D9E3F3940menexch2007ex_ Content-Type: image/gif; name="image001.gif" Content-Description: image001.gif Content-Disposition: inline; filename="image001.gif"; size=1070; creation-date="Fri, 02 Apr 2010 16:19:43 GMT"; modification-date="Fri, 02 Apr 2010 16:19:43 GMT" Content-ID: <[email protected]> Content-Transfer-Encoding: base64 R0lGODlhEAAQAPcAABxuHJzSlDymHGy2XHTKbITCdNTu1FyqTHTCXJTKhLTarCSKHEy2JHy6bJza lITKfFzCPEyWPHS+XHzCbJzSjFS+NLTirBx6HHzKdOz27GzCZJTOjCyWHKzWpHy2ZJTGhHS+VLzi (more base64 string here that I'm not going to paste) But when it finally prints the encoded mime string, this is a different string than I was expecting: encoded mime string: R0lGODlhEAAQAO+/vQAAHG4c77+90pQ877+9HGzvv71cdO+/vWzvv73vv71077+977+977+9XO+/vUx077+9XO+/vcqE77+92qwk77+9HEzvv70kfO+/vWzvv73alO+ Clearly different from the one that has its output in the part above. I'm not even sure what I'm looking at here, but when I try to load this as an image in a html page, it won't work. This is fairly frustrating for me, since all I want is a piece of the text that I'm already printing, but I'd rather not have to search through the mime string myself for the correct part, introducing all kinds of bugs.So I'd really prefer to use the Javamail library but could use some help on how to actually get that correct mime string.

    Read the article

  • Weird generics compile error.

    - by Jouke van der Maas
    I have two classes, a base class and a child class. In the base class i define a generic virtual method: protected virtual Bar Foo<T() where T : Bar {} Then in my child class i try to do this: protected override BarChild Foo() // BarChild inherits Bar { return base.Bar<T as BarChild() } Visual studio gives this weird error: The type 'T' cannot be used as type parameter 'T' in the generic type or method 'Foo()'. There is no boxing conversion or type parameter conversion from 'T' to 'Bar'. Repeating the where clause on the child's override also gives an error: Constraints for override and explicit interface implementation methods are inherited from the base method, so they cannot be specified directly So what am i doing wrong here?

    Read the article

  • PList Chicken/Egg Scenario

    - by David van Dugteren
    Hi, I want to read/write to cache.plist If I want to read an existing premade plist file stored in the resources folder I can go: path = [[NSBundle mainBundle] bundlePath]; NSString *finalPath = [path stringByAppendingPathWithComponent@"cache.plist"]; NSMutableDictionary *root = ... But then I wish to read it from the iPhone. Can't, the Resources folder is only readable. So I need to use: NSDocumentDirectory, NSUserDomain,YES So how can I have my plist file preinstalled to the Document Directory location? Thus meaning I don't have to mess around with untidy code copying the plist file over at startup. (Unless that's the only way).

    Read the article

  • Fast or asynchronous AS3 JPEG encoding

    - by Bart van Heukelom
    I'm currently using the JPGEncoder from the AS3 core lib to encode a bitmap to JPEG var enc:JPGEncoder = new JPGEncoder(90); var jpg:ByteArray = enc.encode(bitmap); Because the bitmap is rather large (3000 x 2000) the encoding takes a long while (about 20 seconds), causing the application to seemingly freeze while encoding. To solve this, I need either: An asynchronous encoder so I can keep updating the screen (with a progress bar or something) while encoding An alternative encoder which is simply faster Is either possible?

    Read the article

  • Is a red-black tree my ideal data structure?

    - by Hugo van der Sanden
    I have a collection of items (big rationals) that I'll be processing. In each case, processing will consist of removing the smallest item in the collection, doing some work, and then adding 0-2 new items (which will always be larger than the removed item). The collection will be initialised with one item, and work will continue until it is empty. I'm not sure what size the collection is likely to reach, but I'd expect in the range 1M-100M items. I will not need to locate any item other than the smallest. I'm currently planning to use a red-black tree, possibly tweaked to keep a pointer to the smallest item. However I've never used one before, and I'm unsure whether my pattern of use fits its characteristics well. 1) Is there a danger the pattern of deletion from the left + random insertion will affect performance, eg by requiring a significantly higher number of rotations than random deletion would? Or will delete and insert operations still be O(log n) with this pattern of use? 2) Would some other data structure give me better performance, either because of the deletion pattern or taking advantage of the fact I only ever need to find the smallest item? Update: glad I asked, the binary heap is clearly a better solution for this case, and as promised turned out to be very easy to implement. Hugo

    Read the article

  • How to expose a Delphi set type via Soap

    - by Wouter van Nifterick
    I'm currently creating soap wrappers for some Delphi functions so that we can easily use them from PHP, C# and Delphi. I wonder what's the best way to expose sets. type TCountry = (countryUnknown,countryNL,countryD,countryB,countryS,countryFIN,countryF,countryE,countryP,countryPl,countryL); TCountrySet = set of TCountry; function GetValidCountrySet(const LicensePlate:string; const PossibleCountriesSet:TCountrySet):TCountrySet; I'm currently wrapping it like this for the soap server: type TCountryArray = array of TCountry; function TVehicleInfo.GetValidCountrySet(const LicensePlate:string; const PossibleCountriesSet:TCountryArray):TCountryArray; It works, but I need to write a lot of useless and ugly code to convert sets--arrays and arrays--sets. Is there an easier, more elegant, or more generic way to do this?

    Read the article

  • Access generic type parameter at runtime?

    - by Bart van Heukelom
    Event dispatcher interface public interface EventDispatcher { <T> EventListener<T> addEventListener(EventListener<T> l); <T> void removeEventListener(EventListener<T> l); } Implementation public class DefaultEventDispatcher implements EventDispatcher { @SuppressWarnings("unchecked") private Map<Class, Set<EventListener>> listeners = new HashMap<Class, Set<EventListener>>(); public void addSupportedEvent(Class eventType) { listeners.put(eventType, new HashSet<EventListener>()); } @Override public <T> EventListener<T> addEventListener(EventListener<T> l) { Set<EventListener> lsts = listeners.get(T); // ****** error: cannot resolve T if (lsts == null) throw new RuntimeException("Unsupported event type"); if (!lsts.add(l)) throw new RuntimeException("Listener already added"); return l; } @Override public <T> void removeEventListener(EventListener<T> l) { Set<EventListener> lsts = listeners.get(T); // ************* same error if (lsts == null) throw new RuntimeException("Unsupported event type"); if (!lsts.remove(l)) throw new RuntimeException("Listener is not here"); } } Usage EventListener<ShapeAddEvent> l = addEventListener(new EventListener<ShapeAddEvent>() { @Override public void onEvent(ShapeAddEvent event) { // TODO Auto-generated method stub } }); removeEventListener(l); I've marked two errors with a comment above (in the implementation). Is there any way to get runtime access to this information?

    Read the article

  • .Net SvcUtil: attributes must be optional

    - by Michel van Engelen
    Hi, I'm trying to generate C# code classes with SvcUtil.exe instead of Xsd.exe. The latter is giving me some problems. Command line: SvcUtil.exe myschema.xsd /dconly /ser:XmlSerializer Several SvcUtil problems are described and solved here: http://blog.shutupandcode.net/?p=761 One problem I can't solve is this one: Error: Type 'DatafieldDescription' in namespace '' cannot be imported. Attributes must be optional and from namespace 'http://schemas.microsoft.com/2003/10/Seri alization/'. Either change the schema so that the types can map to data contract types or use ImportXmlType or use a different serializer. ' I changed <xs:attribute name="Order" use="required"> to <xs:attribute name="Order" use="optional"> and <xs:attribute name="Order"> But the error remains. Is it possible to use attributes, or do I have to delete them all (in that case, this excercition is over)?

    Read the article

  • Why do C# automatic properties not support default values like VB 2010?

    - by Rob van Groenewoud
    Looking at the new VB 2010 features, I stumbled upon support for Auto-Implemented Properties. Since I'm working with C#, this seemed quite familiar, but I noticed that VB did add a feature I would love to have in C#: setting a arbitrary default value for the auto-implemented property: I really like the clean usage of auto-properties in C#. This would save us the effort of introducing a backing field and hooking it up to the property everytime we simply need a default value, thereby cluttering up the code unnecessarily. I was wondering why this wasn't introduced in C# as well? What could be the rationale for not doing this? Is a syntax discussion going on, or are there technical limitations to implementing this?

    Read the article

  • PHP autoloader: ignoring non-existing include

    - by Bart van Heukelom
    I have a problem with my autoloader: public function loadClass($className) { $file = str_replace(array('_', '\\'), '/', $className) . '.php'; include_once $file; } As you can see, it's quite simple. I just deduce the filename of the class and try to include it. I have a problem though; I get an exception when trying to load a non-existing class (because I have an error handler which throws exceptions). This is inconvenient, because it's also fired when you use class_exists() on a non-existing class. You don't want an exception there, just a "false" returned. I fixed this earlier by putting an @ before the include (supressing all errors). The big drawback with this, though, is that any parser/compiler errors (that are fatal) in this include won't show up (not even in the logs), resulting in a hard to find bug. What would be the best way to solve both problems at once? The easiest way would be to include something like this in the autoloader (pseudocode): foreach (path in the include_path) { if (is_readable(the path + the class name)) readable = true; } if (!readable) return; But I worry about the performance there. Would it hurt a lot? (Solved) Made it like this: public function loadClass($className) { $file = str_replace(array('_', '\\'), '/', $className) . '.php'; $paths = explode(PATH_SEPARATOR, get_include_path()); foreach ($paths as $path) { if (is_readable($path . '/' . $file)) { include_once $file; return; } } }

    Read the article

  • Returning a JSON view in combination with a boolean

    - by Rody van Sambeek
    What i would like to accomplish is that a partiel view contains a form. This form is posted using JQuery $.post. After a successfull post javascript picks up the result and uses JQuery's html() method to fill a container with the result. However now I don't want to return the Partial View, but a JSON object containing that partial view and some other object (Success - bool in this case). I tried it with the following code: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(int id, Item item) { if (ModelState.IsValid) { try { // ... return Json(new { Success = true, PartialView = PartialView("Edit", item) }); } catch(Exception ex) { // ... } } return Json(new { Success = false, PartialView = PartialView("Edit", item) }); } However I don't get the HTML in this JSON object and can't use html() to show the result. I tried using this method to render the partial as Html and send that. However this fails on the RenderControl(tw) method with a: The method or operation is not implemented.

    Read the article

  • Entity Framework v4 examples and tutorials of conceptual model mapping

    - by Rody van Sambeek
    In an application I'm writing I have a fairly complicated Database model. I'd like to use EF4 to map this to a whole lot nicer conceptual model. However all the tutorials I've read are with samples of 2 or 3 tables which all map 1 on 1 to the conceptual model. I'd like to learn how to correctly map the database model to a different conceptual model using VS 2010. However I can't find any good tutorials or (preferabally) instruction video's. Somebody got any tips, links or even books?

    Read the article

  • Generic object to object mapping with parametrized constructor

    - by Rody van Sambeek
    I have a data access layer which returns an IDataRecord. I have a WCF service that serves DataContracts (dto's). These DataContracts are initiated by a parametrized constructor containing the IDataRecord as follows: [DataContract] public class DataContractItem { [DataMember] public int ID; [DataMember] public string Title; public DataContractItem(IDataRecord record) { this.ID = Convert.ToInt32(record["ID"]); this.Title = record["title"].ToString(); } } Unfortanately I can't change the DAL, so I'm obliged to work with the IDataRecord as input. But in generat this works very well. The mappings are pretty simple most of the time, sometimes they are a bit more complex, but no rocket science. However, now I'd like to be able to use generics to instantiate the different DataContracts to simplify the WCF service methods. I want to be able to do something like: public T DoSomething<T>(IDataRecord record) { ... return new T(record); } So I'd tried to following solutions: Use a generic typed interface with a constructor. doesn't work: ofcourse we can't define a constructor in an interface Use a static method to instantiate the DataContract and create a typed interface containing this static method. doesn't work: ofcourse we can't define a static method in an interface Use a generic typed interface containing the new() constraint doesn't work: new() constraint cannot contain a parameter (the IDataRecord) Using a factory object to perform the mapping based on the DataContract Type. does work, but: not very clean, because I now have a switch statement with all mappings in one file. I can't find a real clean solution for this. Can somebody shed a light on this for me? The project is too small for any complex mapping techniques and too large for a "switch-based" factory implementation.

    Read the article

  • Why does my token return NULL and how can I fix it?(c++)

    - by Van
    I've created a program to get a string input from a user and parse it into tokens and move a robot according to the input. The program is supposed to recognize these inputs(where x is an integer): "forward x" "back x" "turn left x" "turn right x" and "stop". The program does what it's supposed to for all commands except for "stop". When I type "stop" the program prints out "whats happening?" because I've written a line which states: if(token == NULL) { cout << "whats happening?" << endl; } Why does token get NULL, and how can I fix this so it will read "stop" properly? here is the code: bool stopper = 0; void Navigator::manualDrive() { VideoStream video(&myRobot, 0);//allows user to see what robot sees video.startStream(); const int bufSize = 42; char uinput[bufSize]; char delim[] = " "; char *token; while(stopper == 0) { cout << "Enter your directions below: " << endl; cin.getline(uinput,bufSize); Navigator::parseInstruction(uinput); } } /* parseInstruction(char *c) -- parses cstring instructions received * and moves robot accordingly */ void Navigator::parseInstruction(char * uinput) { char delim[] = " "; char *token; // cout << "Enter your directions below: " << endl; // cin.getline (uinput, bufSize); token=strtok(uinput, delim); if(token == NULL) { cout << "whats happening?" << endl; } if(strcmp("forward", token) == 0) { int inches; token = strtok(NULL, delim); inches = atoi (token); double value = fabs(0.0735 * fabs(inches) - 0.0550); myRobot.forward(1, value); } else if(strcmp("back",token) == 0) { int inches; token = strtok(NULL, delim); inches = atoi (token); double value = fabs(0.0735 * fabs(inches) - 0.0550); myRobot.backward(1/*speed*/, value/*time*/); } else if(strcmp("turn",token) == 0) { int degrees; token = strtok(NULL, delim); if(strcmp("left",token) == 0) { token = strtok(uinput, delim); degrees = atoi (token); double value = fabs(0.00467 * degrees - 0.04); myRobot.turnLeft(1/*speed*/, value/*time*/); } else if(strcmp("right",token) == 0) { token = strtok(uinput, delim); degrees = atoi (token); double value = fabs(0.00467 * degrees - 0.04); myRobot.turnRight(1/*speed*/, value/*time*/); } } else if(strcmp("stop",token) == 0) { stopper = 1; } else { std::cerr << "Unknown command '" << token << "'\n"; } } /* autoDrive() -- reads in file from ifstream, parses * and moves robot according to instructions in file */ void Navigator::autoDrive(string filename) { const int bufSize = 42; char fLine[bufSize]; ifstream infile; infile.open("autodrive.txt", fstream::in); while (!infile.eof()) { infile.getline(fLine, bufSize); Navigator::parseInstruction(fLine); } infile.close(); } I need this to break out of the while loop and end manualDrive because in my driver program the next function called is autoDrive.

    Read the article

  • Why can't I share a variable between two content sections in an ASP.NET MVC View?

    - by Dave Van den Eynde
    I have an ASP.NET MVC View with the typical TitleContent and MainContent, with a fairly complicated title that I want to calculate once and then share between these two content sections, like so: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <% var complicatedTitle = string.Format("{0} - {1}", Model.FirstThing, Model.SecondThing); %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> <%: complicatedTitle %> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2><%: complicatedTitle %></h2> </asp:Content> This, however, doesn't work, as the resulting error message would say that only Content controls are allowed directly in a content page that contains Content controls. The calculation definately belongs in the view. How do you solve this problem?

    Read the article

  • Nested asynchronous calls do not seem to execute as expected

    - by Kristof Van Landschoot
    While trying out jQuery, I have a question that is probably a newbie mistake, but I cannot seem to find the solution. This is the code: $.get("index.html", function() { var i = 0; for (; i < 3; i++) { var lDiv = document.createElement('div'); lDiv.id = 'body-' + i; document.getElementById('body').appendChild(lDiv); $.get('index.html', function(data) { lDiv.innerHTML = "<p>Hello World " + i + "</p>"; }); } }); The output seems to be <div id='body-0'></div> <div id='body-1'></div> <div id='body-2'> <p>Hello World 3</p> </div> I expected the lDiv.innerHTML= code to be executed for each i, but apparently it is only executed for the last i? What am I overlooking?

    Read the article

  • Track pageviews in Google Analytics on partial url of Grails application

    - by Pieter van Gent
    For my Grails application I want to set up Google Analytics to track only "partial" url's. I 'll explain: a typical Grails url consists of the following parts: domain + application-name + controller + action + id e.g. www.mydomain.com/myapp/controller/action/12345 As far as I understand for Google Analytics the page to be tracked is identified by the entire url. For my purpose I'm not interested in the id part of the url: I want to know which actions have been performed, but I need not know for which id the action was executed. And of course I would like a generic solution, because I have multiple controllers and multiple actions... Maybe some kind of filter stating "I want to track pages 3 levels deep (/myapp/controller/action)" would do? Or a filter stating "exclude everything from url after the last /"? Any help would be much appreciated. Kind regards, Pieter

    Read the article

  • Generate an ID via COM interop

    - by Erik van Brakel
    At the moment, we've got an unmaintanable ball of code which offers an interface to a third party application. The third party application has a COM assembly which MUST be used to create new entries. This process involves two steps: generate a new object (basically an ID), and update that object with new field values. Because COM interop is so slow, we only use that to generate the ID (and related objects) in the database. The actual update is done using a regular SQL query. What I am trying to figure out if it's possible to use NHibernate to do some of the heavy lifting for us, without bypassing the COM assembly. Here's the code for saving something to the database as I envision it: using(var s = sessionFactory.OpenSession()) using(var t = s.BeginTransaction()) { MyEntity entity = new MyEntity(); s.Save(entity); t.Commit(); } Regular NH code I'd say. Now, this is where it gets tricky. I think I have to supply my own implementation of NHibernate.Id.IIdentifierGenerator which calls the COM assembly in the Generate method. That's not a problem. What IS a problem is that the COM assembly requires initialisation, which does take a bit of time. It also doesn't like multiple instances in the same process, for some reason. What I would like to know is if there's a way to properly access an external service in the generator code. I'm free to use any technique I want, so if it involves something like an IoC container that's no problem. The thing I am looking for is where exactly to hook-up my code so I can access the things I need in my generator, without having to resort to using singletons or other nasty stuff.

    Read the article

  • How to 'do' ByVal in C#

    - by Jouke van der Maas
    As I understand it, C# passes parameters into methods by reference. In vb.net, you can specify this with ByVal and ByRef. The default is ByVal. Is this for compatibility with vb6, or is it just random? Also, how can I specify what to use in C#? I kind of like the idea of passing parameters by value.

    Read the article

< Previous Page | 33 34 35 36 37 38 39 40 41 42 43 44  | Next Page >