Daily Archives

Articles indexed Wednesday March 17 2010

Page 16/128 | < Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >

  • Elegant Algorithm for Parsing Data Stream Into Record

    - by Matt Long
    I am interfacing with a hardware device that streams data to my app over Wifi. The data is streaming in just fine. The data contains a character header (DATA:) that indicates a new record has begun. The issues is that the data I receive doesn't necessarily fall on the header boundary, so I have to capture the data until what I've captured contains the header. Then, everything that precedes the header goes into the previous record and everything that comes after it goes into a new record. I have this working, but wondered if anyone has done this before and has a good computer-sciencey way to solve the problem. Here's what I do: Convert the NSData of the current read to an NSString Append the NSString to a placeholder string Check placeholder string for the header (DATA:). If the header is not there, just wait for the next read. If the header exists, append whatever precedes it to a previous record placeholder and hand that placeholder off to an array as a complete record that I can further parse into fields. Take whatever shows up after the header and place it in the record placeholder so that it can be appended to in the next read. Repeat steps 3 - 5. Let me know if you see any flaws with this or have a suggestion for a better way. Seems there should be some design pattern for this, but I can't think of one. Thanks.

    Read the article

  • Common "truisms" needing correction the most

    - by Charles Bretana
    In addition to "I never met a man I didn't like", Will Rogers had another great little ditty I've always remembered. It went: "It's not what you don't know that'll hurt you, it's what you do know that ain't so." We all know or subscribe to many IT "truisms" that mostly have a strong basis in fact, in something in our professional careers, something we learned from others, lessons learned the hard way by ourselves, or by others who came before us. Unfortuntely, as these truisms spread throughout the community, the details—why they came about and the caveats that affect when they apply—tend to not spread along with them. We all have a tendency to look for, and latch on to, small "rules" or principles that we can use to avoid doing a complete exhaustive analysis for every decision. But even though they are correct much of the time, when we sometimes misapply them, we pay a penalty that could be avoided by understooding the details behind them. For example, when user-defined functions were first introduced in SQL Server it became "common knowledge" within a year or so that they had extremely bad performance (because it required a re-compilation for each use) and should be avoided. This "trusim" still increases many database developers' aversion to using UDFs, even though Microsoft's introduction of InLine UDFs, which do not suffer from this issue at all, mitigates this issue substantially. In recent years I have run into numerous DBAs who still believe you should "never" use UDFs, because of this. What other common not-so-"trusims" do you know, which many developers believe, that are not quite as universally true as is commonly understood, and which the developer community would benefit from being better educated about? Please include why it was "true" to start off with, and under what circumstances it's not true. Limit responses to issues that are technical, where the "common" application of a "rule or principle" is in fact correct most of the time, or was correct back when it was first elucidated, but—in the edge cases, or because of not understanding the principle thoroughly, because technology has changed since it first spread, or applying the rule today without understanding the details behind the rule—can easily backfire or cause the opposite of the intended effect.

    Read the article

  • How can I match at the beginning of any line, including the first, with a Perl regex?

    - by JoelFan
    According the the Perl documentation on regexes: By default, the "^" character is guaranteed to match only the beginning of the string ... Embedded newlines will not be matched by "^" ... You may, however, wish to treat a string as a multi-line buffer, such that the "^" will match after any newline within the string ... you can do this by using the /m modifier on the pattern match operator. The "after any newline" part means that it will only match at the beginning of the 2nd and subsequent lines. What if I want to match at the beginning of any line (1st, 2nd, etc.)? EDIT: OK, it seems that the file has BOM information (3 chars) at the beginning and that's what's messing me up. Any way to get ^ to match anyway? EDIT: So in the end it works (as long as there's no BOM), but now it seems that the Perl documentation is wrong, since it says "after any newline"

    Read the article

  • Why do I get error, Invalid command 'PythonHandler'?

    - by nbolton
    I'm trying to deploy a Django application, but I've hit a brick wall. On Debian (latest), I've run these commands so far: apt-get install apache2 apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-python python-django I've tried adding the module manually in the Apache 2 config files, but to be honest I'm totally lost. It's totally different to Apache version 1 which I used years ago. Syntax error on line 7 of /etc/apache2/sites-enabled/000-default: Invalid command 'PythonHandler', perhaps misspelled or defined by a module not included in the server configuration I've added the following to my sites-available/default file, between the tags. <Location "/"> SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE hellodjango1.settings PythonDebug Off </Location> Here's what tutorials I've used so far, without much luck: Django | How to use Django with Apache and mod_python | Django Documentation How To Install Django On Debian Etch (Apache2/mod_python)

    Read the article

  • first time setting up ssl, running into a strange problem, tutorials haven't been too helpful

    - by pedalpete
    This is my first time trying to set-up an ssl for one a site, and I'm running it on a server that has 3 other sites already hosted. I'm running apache2.?? and the install came with an ssl.conf page. The ssl.conf has the following settings LoadModule ssl_module modules/mod_ssl.so Listen 443 AddType application/x-x509-ca-cert .crt AddType application/x-pkcs7-crl .crl <VirtualHost *:443> ServerAdmin [email protected] DocumentRoot /var/www/html/securesite ServerName securesite.com ErrorLog logs/securesite-error_log CustomLog logs/securesite-access_log common SSLEngine on SSLCertificateFile /etc/httpd/ssl.crt/securesite.com.crt SSLCertificateKeyFile /etc/httpd/ssl.key/server.key SSLCertificateChainFile /etc/httpd/ssl.crt/gd_bundle.crt </VirtualHost> When I run 'apachectl configtest', I don't get any errors, but running 'apachectl -k restart', I get 'httpd not running, trying to start'. I have two questions 1) Is there an error in the way I'm defining my virtualhost for 443?? the rest of my entries point to <VirtualHost *:80. When I comment out the above entry, apache runs fine. 2) do I need to set-up a redirect from port 80 for secure site? Because most users are going to go to http: or www. , and I need to send them to https: does apache do this automatically? or do i need to create an entry with a redirect?

    Read the article

  • What causes XP to lose the clipboard?

    - by Steve
    A few times lately I've been getting the error "Cannot open clipboard" when trying to paste. Can I get it back without re-booting? I've been using Arsclip for years as a clipboard enhancement. I'm not convinced that causes the problem as it persists even when I close it.

    Read the article

  • Windows XP environment variable editor replacement that handles lines

    - by Codism
    I'm looking for an environment variable editor that handles linebreaks well. I have a monster %PATH% to edit (edited to save side-scrolling): C:\Program Files\Windows Resource Kits\Tools\;C:\Program Files\PC Connectivity Solution\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem; C:\cygwin\bin;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin;C:\WINDOWS \system32\WindowsPowerShell\v1.0\;C:\Utils;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\; C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\; C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\; C:\Program Files\MKVtoolnix;C:\Program Files\Common Files\Roxio Shared\ DLLShared;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE I want the editor to put each path in a line and when I click save & close, for the editor put the lines back in the right format. Is there an editor that can do that?

    Read the article

  • Python KMeans clustering words

    - by sadawd
    Dear Everyone I am interested to perform kmeans clustering on a list of words with the distance measure being Leveshtein. 1) I know there are a lot of frameworks out there, including scipy and orange that has a kmeans implementation. However they all require some sort of vector as the data which doesn't really fit me. 2) I need a good clustering implementation. I looked at python-clustering and realize that it doesn't a) return the sum of all the distance to each centroid, and b) it doesn't have any sort of iteration limit or cut off which ensures the quality of the clustering. python-clustering and the clustering algorithm on daniweb doesn't really work for me. Can someone find me a good lib? Google hasn't been my friend

    Read the article

  • Business entity: private instance VS single instance

    - by taoufik
    Suppose my WinForms application has a business entity Order, the entity is used in multiple views, each view handles a different domain or use-case in the application. As an example, one managing orders, the other one digging into one order and displaying additional data. If I'd use nHibernate (or any other ORM) and use one session/dataContext per view (or per db action), I'd end up getting two different instances for the same Order (let's say orderId = 1). Although functionally the same entity, they are technically two different instances. Yes, I could implement Equals/GetHashcode to make them "seem" the same. Why would you go for a single instance per entity vs private instances per view or per use-case? Having single instances has the advantage of sharing INotifyPropertyChanged events, and sharing additional (non-persistent) data. Having a private instance in each view would give you the flexibility of the undo functionality on a view level. In the example above, I'd allow the user to change order details, and give them the flexibility to not save the change. Here, synchronisation between the view/use-case happens on a data persistence level. What would your argument be?

    Read the article

  • Run both Authorize Filter and Action Filter on unauthenticated ASP.NET MVC request

    - by Bryan Migliorisi
    I have decorated my base controller with a couple of action filters. They work fine. One of those filters sets up the request - does things like set the culture based on the domain, etc. I also have a handful of actions that require authorization using the Authorize attribute. My problem is that when an user attempts to request a page they are not authorized to access, the authorization filter kicks in and redirects them to a page telling them that they cannot vie the page. The issue is that the action filters never run so the culture and other request data is never set. This effectively causes language to be wrong in the view and other data to be missing. I know that authorization filters run first but my question is this: How can I design this such that I can ensure that certain methods are always run before the view is returned, regardless of the authorization. Hope that makes sense.

    Read the article

  • How to append to a log file in powershell?

    - by Mark Allison
    Hi there, I am doing some parallel SQL Server 2005 database restores in powershell. The way I have done it is to use cmd.exe and start so that powershell doesn't wait for it to complete. What I need to do is to pipe the output into a log file with append. If I use Add-Content, then powershell waits, which is not what I want. My code snippet is foreach ($line in $database_list) { <snip> # Create logins sqlcmd.exe -S $instance -E -d master -i $loginsFile -o $logFile # Read commands from a temp file and execute them in parallel with sqlcmd.exe cmd.exe /c start "Restoring $database" /D"$pwd" sqlcmd.exe -S $instance -E -d master -i $tempSQLFile -t 0 -o $logFile [void]$logFiles.Add($logFile) } The problem is that sqlcmd.exe -o overwrites. I've tried doing this to append: cmd.exe /c start "Restoring $database" /D"$pwd" sqlcmd.exe -S $instance -E -d master -i $tempSQLFile -t 0 >> $logFile But it doesn't work because the output stays in the SQLCMD window and doesn't go to the file. Any suggestions? Thanks, Mark.

    Read the article

  • Set predefine form value (webbrowser control)

    - by Khou
    Hi I want to load my windows form: web browser thats using the webbrowser control, It would load a web page, and load my defination and search for elements that has been define, it will then assign the default values and these values can not be changed by the end user. Example If my application finds "FirstName" it would always assign the value "John" If my application finds "LastName" it would always assign the value "Smith" (these values should not be changed by the end user). Here's how to do it in HTML/JAVASCRIPT, but how do i do this in a windows form? HTML <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>page title</title> <script script type="text/javascript" src="demo1.js"></script> </head> <body onload="def(document.someform, 'name', 'my default name value');"> <h2 style="color: #8e9182">test form title</h2> <form name="someform" id="someform_frm" action="#"> <table cellspacing="1"> <tr><td><label for="name">NameX: </label></td><td><input type="text" size="30" maxlength="155" name="name" onchange="def(document.someform, 'name', 'my default name value');"></td></tr> <tr><td><label for="name2">NameY: </label></td><td><input type="text" size="30" maxlength="155" name="name2"></td></tr> <tr><td colspan="2"><input type="button" name="submit" value="Submit" onclick="showFormData(this.form);" ></td></table> </form> </body> </html> JAVASCRIPT function def(oForm, element_name, def_txt) { oForm.elements[element_name].value = def_txt; }

    Read the article

  • Building a regexp to split a string

    - by Kivin
    I'm seeking a solution to splitting a string which contains text in the following format: "abcd efgh 'ijklm no pqrs' tuv" which will produce the following results: ['abcd', 'efgh', 'ijklm no pqrs', 'tuv'] In otherwords, it splits by whitespace unless inside of a single quoted string. I think it could be done with .NET regexps using "Lookaround" operators, particularly balancing operators. I'm not so sure about perl.

    Read the article

  • How to Test Facebook Connect Locally

    - by Haytham
    I use ASP .NET and Facebook Connect APIs. but when I run the app and press Connect button it's return to the Website not to the test local server which is (http://localhost:xxxx/test.aspx) So how I can test Facebook locally (i.e How I can change the callback url) ?

    Read the article

  • Show contents of the windows clipboard

    - by PsiX
    How can I see what the Windows clipboard currently contains without using the paste operation? I don't want the "pasted-to" application to perform any actions on the clipboard (e.g. formatting text, converting). Is there a tool which shows the clipboard's objects and their format (CF_BITMAP, CF_TEXT, etc.) and content (in simple bytes e.g.)?

    Read the article

  • Microsoft Robotics Studio with Wine ? Is it possible ?

    - by Arkapravo
    I am using Ubuntu 9.10 and I am a bit of a robotics enthusiast. I have used KiKS (in MATLAB for simulating Khepera robots), MobotSim (in Windows, simulates a point like robot using a BASIC editor) and Player Stage/Gazebo (with C/C++ on Ubuntu Linux). My question, can MS Robotics Studio be installed in Ubuntu Linux using Wine (I am using 1.1.31) ? Has anyone done it ? Thanks for your reply !

    Read the article

  • How do I scale a UIButton's imageView?

    - by vcLwei
    Hey guys! I create a UIButton instance(named "button") with a image use [UIButton setImage:forState:] function, the button.frame is larger than the image's size. Now I want to scale this button's image smaller. I had tried to change button.imageView.frame, button.imageView.bounds and button.imageView.contentMode, but all seem ineffective. Hopefully someone can help me how to scale a UIButton's imageView.Thanks! my create UIButton instance code: UIButton *button = [[UIButton alloc] init]; [button setImage:image forState:UIControlStateNormal]; my try to scale the image code: button.imageView.contentMode = UIViewContentModeScaleAspectFit; button.imageView.bounds = CGRectMake(0, 0, 70, 70); and: button.imageView.contentMode = UIViewContentModeScaleAspectFit; button.imageView.frame = CGRectMake(0, 0, 70, 70);

    Read the article

  • How does memory management in Java and C# differ?

    - by David Johnstone
    I was reading through 2010 CWE/SANS Top 25 Most Dangerous Programming Errors and one of the entries is for Buffer Copy without Checking Size of Input. It suggests using a language with features to prevent or mitigate this problem, and says: For example, many languages that perform their own memory management, such as Java and Perl, are not subject to buffer overflows. Other languages, such as Ada and C#, typically provide overflow protection, but the protection can be disabled by the programmer. I was not aware that Java and C# differed in any meaningful way with regard to memory management. How is it that Java is not subject to buffer overflows, while C# only protects against overflows? And how is it possible to disable this protection in C#?

    Read the article

  • Are Python properties broken?

    - by jacob
    How can it be that this test case import unittest class PropTest(unittest.TestCase): def test(self): class C(): val = 'initial val' def get_p(self): return self.val def set_p(self, prop): if prop == 'legal val': self.val = prop prop=property(fget=get_p, fset=set_p) c=C() self.assertEqual('initial val', c.prop) c.prop='legal val' self.assertEqual('legal val', c.prop) c.prop='illegal val' self.assertNotEqual('illegal val', c.prop) fails as below? Failure Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py", line 279, in run testMethod() File "/Users/jacob/aau/admissions_proj/admissions/plain_old_unit_tests.py", line 24, in test self.assertNotEqual('illegal val', c.prop) File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py", line 358, in failIfEqual (msg or '%r == %r' % (first, second)) AssertionError: 'illegal val' == 'illegal val'

    Read the article

  • Check Clipboard for Copied texts.

    - by Bibhas
    I want to add an Cut/Copy/Paste ContextMenuStrip in a RichTextBox, but the problem is, I want to enable or disable the Paste button with respect to the current condition of the windows clipboard.. I mean, if any text is copied already, then that button should be Enabled, otherwise disabled. Any idea how I can accomplish that?

    Read the article

< Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >