Daily Archives

Articles indexed Monday May 10 2010

Page 9/113 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Putting a thread to sleep until event X occurs

    - by tipu
    I'm writing to many files in a threaded app and I'm creating one handler per file. I have HandlerFactory class that manages the distribution of these handlers. What I'd like to do is that thread A requests and gets foo.txt's file handle from the HandlerFactory class thread B requests foo.txt's file handler handler class recognizes that this file handle has been checked out handler class puts thread A to sleep thread B closes file handle using a wrapper method from HandlerFactory HandlerFactory notifies sleeping threads thread B wakes and successfully gets foo.txt's file handle This is what I have so far, def get_handler(self, file_path, type): self.lock.acquire() if file_path not in self.handlers: self.handlers[file_path] = open(file_path, type) elif not self.handlers[file_path].closed: time.sleep(1) self.lock.release() return self.handlers[file_path][type] I believe this covers the sleeping and handler retrieval successfully, but I am unsure how to wake up all threads, or even better wake up a specific thread.

    Read the article

  • Code Golf: Code 39 Bar Code

    - by gwell
    The challenge The shortest code by character count to draw an ASCII representation of a Code 39 bar code. Wikipedia article about Code 39: http://en.wikipedia.org/wiki/Code_39 Input The input will be a string of legal characters for Code 39 bar codes. This means 43 characters are valid: 0-9 A-Z (space) and -.$/+%. The * character will not appear in the input as it is used as the start and stop characters. Output Each character encoded in Code 39 bar codes have nine elements, five bars and four spaces. Bars will be represented with # characters, and spaces will be represented with the space character. Three of the nine elements will be wide. The narrow elements will be one character wide, and the wide elements will be three characters wide. A inter-character space of a single space should be added between each character pattern. The pattern should be repeated so that the height of the bar code is eight characters high. The start/stop character * (bWbwBwBwb) would be represented like this: # # ### ### # # # ### ### # # # ### ### # # # ### ### # # # ### ### # # # ### ### # # # ### ### # # # ### ### # ^ ^ ^^ ^ ^ ^ ^^^ | | || | | | ||| narrow bar -+ | || | | | ||| wide space ---+ || | | | ||| narrow bar -----+| | | | ||| narrow space ------+ | | | ||| wide bar --------+ | | ||| narrow space ----------+ | ||| wide bar ------------+ ||| narrow space --------------+|| narrow bar ---------------+| inter-character space ----------------+ The start and stop character * will need to be output at the start and end of the bar code. No quiet space will need to be included before or after the bar code. No check digit will need to be calculated. Full ASCII Code39 encoding is not required, just the standard 43 characters. No text needs to be printed below the ASCII bar code representation to identify the output contents. The character # can be replaced with another character of higher density if wanted. Using the full block character U+2588, would allow the bar code to actually scan when printed. Test cases Input: ABC Output: # # ### ### # ### # # # ### # ### # # ### ### ### # # # # # ### ### # # # ### ### # ### # # # ### # ### # # ### ### ### # # # # # ### ### # # # ### ### # ### # # # ### # ### # # ### ### ### # # # # # ### ### # # # ### ### # ### # # # ### # ### # # ### ### ### # # # # # ### ### # # # ### ### # ### # # # ### # ### # # ### ### ### # # # # # ### ### # # # ### ### # ### # # # ### # ### # # ### ### ### # # # # # ### ### # # # ### ### # ### # # # ### # ### # # ### ### ### # # # # # ### ### # # # ### ### # ### # # # ### # ### # # ### ### ### # # # # # ### ### # Input: 1/3 Output: # # ### ### # ### # # # ### # # # # # ### ### # # # # # ### ### # # # ### ### # ### # # # ### # # # # # ### ### # # # # # ### ### # # # ### ### # ### # # # ### # # # # # ### ### # # # # # ### ### # # # ### ### # ### # # # ### # # # # # ### ### # # # # # ### ### # # # ### ### # ### # # # ### # # # # # ### ### # # # # # ### ### # # # ### ### # ### # # # ### # # # # # ### ### # # # # # ### ### # # # ### ### # ### # # # ### # # # # # ### ### # # # # # ### ### # # # ### ### # ### # # # ### # # # # # ### ### # # # # # ### ### # Input: - $ (minus space dollar) Output: # # ### ### # # # # ### ### # ### # ### # # # # # # # # ### ### # # # ### ### # # # # ### ### # ### # ### # # # # # # # # ### ### # # # ### ### # # # # ### ### # ### # ### # # # # # # # # ### ### # # # ### ### # # # # ### ### # ### # ### # # # # # # # # ### ### # # # ### ### # # # # ### ### # ### # ### # # # # # # # # ### ### # # # ### ### # # # # ### ### # ### # ### # # # # # # # # ### ### # # # ### ### # # # # ### ### # ### # ### # # # # # # # # ### ### # # # ### ### # # # # ### ### # ### # ### # # # # # # # # ### ### # Code count includes input/output (full program).

    Read the article

  • HTTPService resultFormat, how to choose

    - by tag
    HTTPService has a property resultFormat which can be set to any of the following: array e4x flashvars object text xml I looked at the documentation to understand the difference, but still couldn't understand when to use each. I'm looking for the lightest weight of all of them. P.S. I'm consuming output from my own server, so can change the output format as needed to make it compatible with each.

    Read the article

  • Matlab plot inside a loop

    - by Macarse
    I am doing something like this: a = [1:100]; for i=1:100, plot([1:i], a(1:i)); end My issue is that the plot is not shown until the loop is finish. How can I show/update the plot in every iteration?

    Read the article

  • Query to MySQL from c# returns System.Byte[]

    - by karthik
    I am using the below SP to return the value of Generated Insert statement and it works fine when executed in Query browser. When i try to get the value from C#, it give's me "System.Byte[]" as return value. When i try to get the value from MySql query browser, it give's me return value as : 'insert into admindb.accounts values("54321","2","karthik2","karthik2","1");' I guess the problem is with the single quotes of the returned value. Is it so ? DELIMITER $$ DROP PROCEDURE IF EXISTS `admindb`.`InsGen` $$ CREATE DEFINER=`root`@`localhost` PROCEDURE `InsGen`( in_db varchar(20), in_table varchar(20), in_ColumnName varchar(20), in_ColumnValue varchar(20) ) BEGIN declare Whrs varchar(500); declare Sels varchar(500); declare Inserts varchar(2000); declare tablename varchar(20); declare ColName varchar(20); set tablename=in_table; # Comma separated column names - used for Select select group_concat(concat('concat(\'"\',','ifnull(',column_name,','''')',',\'"\')')) INTO @Sels from information_schema.columns where table_schema=in_db and table_name=tablename; # Comma separated column names - used for Group By select group_concat('`',column_name,'`') INTO @Whrs from information_schema.columns where table_schema=in_db and table_name=tablename; #Main Select Statement for fetching comma separated table values set @Inserts=concat("select concat('insert into ", in_db,".",tablename," values(',concat_ws(',',",@Sels,"),');') as MyColumn from ", in_db,".",tablename, " where ", in_ColumnName, " = " , in_ColumnValue, " group by ",@Whrs, ";"); PREPARE Inserts FROM @Inserts; EXECUTE Inserts; END $$ DELIMITER ;

    Read the article

  • Model relationship types in cakePhP

    - by kwokwai
    I have checked out the cookbook web site of cakephp that there are four types Model relationship: http://book.cakephp.org/view/79/Relationship-Types Since the one I am more familiar with is belongsTo, I am not sure when I need to use hasManay and HABTM. What will be the result to my web site if I used a wrong Model relationship type? Please advise.

    Read the article

  • Monitor ssh on non-default port with Nagios

    - by obvio171
    I just deployed Nagios on a Gentoo server and everything is fine except ssh, which it marks as "CRITICAL" because it's refusing connections. But that's because it's running on a port different from the default 22. How do I change it so that it monitors the right port?

    Read the article

  • Kernel NTFS driver vs NTFS-3G

    - by Jack
    A more comprehensive phrased question since I lost access to the other one. I would ask that the other one be deleted, not this one, as it should not have been migrated in the first place. There are currently two NTFS drivers available for Linux. The NTFS driver included in the kernel, and the userspace NTFS-3G driver that makes use of FUSE. By all accounts, NTFS-3G works perfectly. My question then, is if the NTFS filesystem has been successfully reverse engineered, why have the kernel NTFS team not implemented the changes in their driver? At the moment it is still marked as experimental, and there is a good chance it will destroy your data. Note: This has absolutely nothing to do with distributions...

    Read the article

  • How can I force Firefox to select the tab to the right on tab close?

    - by Philip
    I'm using TMP 0.3.8.2 and a host of other extensions on FF 3.6.3 on OSX 10.6. I've tried disabling all other extensions that might interfere with tab settings but it's hard to keep track of everything because I have literally 60 (about 30 are disabled though) that are on and off in various configurations. I'm wondering if there's a way to FORCE Firefox to select the tab to the right on closing a tab, in such a way that it overrides any other setting anywhere else. I realize the prospects for this are dim. Thanks.

    Read the article

  • Free Photoshop Plugin or Software to auto remove backgrounds

    - by Rogue
    I'm looking for a background removal plug-in or software that automates or atleast eases the process of removing backgrounds from pictures / digital photos. I have seen a few like Mask Pro 4, Snap and BackGround Remover all these are paid software. I would like to know if there are any free solutions available before I invest in any of the above plug-ins / software.

    Read the article

  • In python, changing MySQL query based on function variables

    - by ensnare
    I'd like to be able to add a restriction to the query if user_id != None ... for example: "AND user_id = 5" but I am not sure how to add this into the below function? Thank you. def get(id, user_id=None): query = """SELECT * FROM USERS WHERE text LIKE %s AND id = %s """ values = (search_text, id) results = DB.get(query, values) This way I can call: get(5) get(5,103524234) (contains user_id restriction)

    Read the article

  • -moz CSS properties and browser support

    - by twodayslate
    As of right now I believe only Firefox support -moz-border-radius property. I am surprised that twitter uses it. Are any other browsers planning on supporting this or does CSS3 have something like this in the works? edit:// also found -webkit-border-top-left-radius and then the CSS3 version So when is CSS3 coming out?

    Read the article

  • CSS3 selector to find the 2nd div of the same class

    - by mpeters
    I need a CSS selector that can find the 2nd div of 2 that has the same class. I've looked at nth-child() but it's not what I want since I can't see a way to further clarify what class I want. These 2 divs will be siblings in the document if that helps. My HTML looks something like this: <div class="foo">...</div> <div class="bar">...</div> <div class="baz">...</div> <div class="bar">...</div> And I want the 2nd div.bar (or the last div.bar would work too).

    Read the article

  • How to retrieve row count of one-to-many relation while also include original entity?

    - by kaa
    Say I have two entities Foo and Bar where Foo has-many Bar's, class Foo { int ImportantNumber { get; set; } IEnumerable<Bar> Bars { get; set; } } class FooDTO { Foo Foo { get; set; } int BarCount { get; set; } } How can I efficiently sum up the number of Bars per Foo in a DTO using a single query, preferrably only with the Criteria interface. I have tried any number of ways to get the original entity out of a query with ´SetProjection´ but no luck. The current theory is to do something like SELECT Foo.*, BarCounts.counts FROM Foo LEFT JOIN ( SELECT fooId, COUNT(*) as counts FROM Bar GROUP BY fooId ) AS BarCounts ON Foo.id=BarCounts.fooId but with Criterias, and I just can't seem to figure out how.

    Read the article

  • JavaScript frameworks and CSS frameworks: JQuery, YUI, neither, or something else?

    - by Eric Johnson
    I haven't done web development for about 6 years. I'm trying to get back into it and there is a lot of new stuff out there. I've chosen to write my next project with Perl and Catalyst. I keep hearing about various JavaScript and CSS frameworks. I know very little about these frameworks so maybe this question is overly broad and open ended. What are the strengths, weaknesses, and popularity of the various frameworks? Should I be using YUI, JQuery, neither, or something else?

    Read the article

  • Can someone recommend a bells and whistles CSS framework?

    - by Ali A
    I am looking for a bells and whistles CSS framework. I have found a number online that deal with "grids", and some that deal with "typography" and others that deal with "resetting". What I have not found is something that will give my web applications a consistent reusable style or theme. I guess it would have to have a number of predefined elements that do things, for example: div.boxed {...} And then a number of themes or plugins that provide these in a consistent way. Javascript toolkits like ExtJS, YUI, and also GWT have their own skinability, and I guess this is the featureset that I want, but independent of any Javascript library. (Open source would be best, but we don't mind paying) Edit: 5 good answers, but I have seen all those frameworks, and they are not enough of what I am looking for. Perhaps what I am looking for doesn't exist. Or I haven't explained properly. I will give them a good going over and see.

    Read the article

  • Right-Align and Vertical Align label with checkbox/radio button CSS

    - by Jon
    Hi Everyone, I'm very close and have this working in Safari, Firefox and IE8, however IE7 the labels and radio buttons do not align vertically. My HTML is: <div id="master-container"> <fieldset id="test"> <legend>This is a test of my CSS</legend> <ul class="inputlist"> <li> <label for="test1">Test 1</label> <input name="test1" id="test1" type="checkbox" disabled="disabled"/> </li> <li> <label for="test2">Test 2</label> <input name="test2" id="test2" type="checkbox" disabled="disabled"/> </li> </ul> </fieldset> </div> My CSS Is: html{font-family:Arial,Helvetica,sans-serif;} #master-container{width:615px;font-size:12px;} ul.inputlist{list-style-type:none;} ul.inputlist li{width:100%;margin-bottom:5px;} ul.inputlist li label{width:30px; text-align:right; margin-right:7px;float:left;} Any suggestions? Thanks! EDIT: Based on the suggestion to check the rest of my html and css. I updated the code above and now it accurately demonstrates the problem. If I take font-size out of #master-container it lines up but then it is not the proper font-size. I tried to add a font-size to ul.inputlist li input but that didn't help. Any suggestions? Thanks for your help everyone!

    Read the article

  • issue with parsing JSON string

    - by bgosalci
    I have this object which I use as a list of objects: var objList = new Object(); This is then serialized using JSON serialize. If there are no object added or all objects have been removed from the list and the blank objList is serialized, parsing the objList using JSON parser in IE, it will occasionally fail to evaluate the objList as a JavaScript object. This causes the Object doesn't support this property or method error when tying to add an object to the objList: objList['idx']=objData; Does anyone know why does IE occasionally fail to evaluate objList:{} to an object and has someone else come across this issue. The actual JSON string when the objList is '{}' The objList is initialised: objList = g_objList.parseJSON();

    Read the article

  • jquery tools - tabs mouseover - 2nd.

    - by New_user
    I use this tool to show text when moving the mouse over the pix: http://flowplayer.org/tools/demos/tabs/mouseover.htm Does anybody have an idea how to force that the "context" of the second pic is shown when opening the demo-page instead of the context of the first pic (default)? Thanks for any help!

    Read the article

  • Setting a cell's format using Excel 2007 Interop and C#

    - by CVertex
    I'm using the office 2007 interop assemblies to create some excel spreadsheets. There are plenty of questions on here about getting started and MSDN contains heaps of articles, like this one. The API is funky, and sometimes a bit confusing. When I set a value of a cell, is there a way to set it's format? I'd like to mark particular fields as Date's so my customer can run excel macros on them. Also, numbers would be useful. Thanks!

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >