Daily Archives

Articles indexed Friday April 6 2012

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

  • How to set permalink of your blog post according to date and title of post?

    - by Amit
    I am having this website http://www.finalyearondesk.com . My blogs post link are set like this.. http://www.finalyearondesk.com/index.php?id=28 . I want it to set like this ... finalyearondesk.com/2011/09/22/how-to-recover-ubuntu-after-it-is-crashed/ . I am using the following function to get these posts... function get_content($id = '') { if($id != ""): $id = mysql_real_escape_string($id); $sql = "SELECT * from blog WHERE id = '$id'"; $return = '<p><a href="http://www.finalyearondesk.com/">Go back to Home page</a></p>'; echo $return; else: $sql = "select * from blog ORDER BY id DESC"; endif; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) != 0): while($row = mysql_fetch_assoc($res)) { echo '<h1><a href="index.php?id=' . $row['id'] . '">' . $row['title'] . '</a></h1>'; echo '<p>' . "By: " . '<font color="orange">' . $row['author'] . '</font>' . ", Posted on: " . $row['date'] . '<p>'; echo '<p>' . $row['body'] . '</p><br />'; } else: echo '<p>We are really very sorry, this page does not exist!</p>'; endif; } Any suggestions how to do this? And can we do this by using .htaccess?

    Read the article

  • Small, fast shopping cart setup

    - by R..
    I'm looking for an open source shopping cart solution that's simple and easy to setup. The requirements are: Quick setup for someone familiar with *nix webservers. Checkout via PayPal (other payment methods not needed). Customers should not have to create an account to make a purchase. At least a minimal level of inventory control. Ability to print/export a list of orders in compact form. Any recommendations for something I should try? Ability to get it up and working quickly is really my priority right now; if it's not ideal, it can be replaced (or, as I'm looking for open source, I can adapt it to fit the requirements better) at a later time. Edit: Really what I'm looking for is simplicity. This will be for a small local business, and the orders will consist of 1-10 items that are being delivered by a driver who needs a simple list of what each customer received when making delivery. Looking like a giant online computer/electronics/etc. store is definitely not a desirable quality. The simpler the interface presented to customers (who are used to purchasing through dumb web forms and paying COD), the better.

    Read the article

  • Constrained/penalized distance function

    - by sigma.z.1980
    Assume a character is located on a n by n grid and has to reach a certain entry on that grid. Its current position is (x1,y1). Also on the same grid is an enemy with coordinates (x2,y2). Each step algorithm randomly generates new candidate locations for the hero (if there are k candidates then there is a kx2 matrix of new potential locations. What I need is some distance objective function to compare the candidates. I'm currently using d1 - c * d2, where d1 is distance to the objective (measure in terms of number of pixels for each axis), d2 is distance to the enemy and c is some coefficient (this is very much like a set-up for Lagrangian). It's not working very well though. I'd be quite keen to learn how what constrained distance function are used for similar cases. Any suggestions are very much appreciated.

    Read the article

  • optimizing graphics for iOS flash game

    - by 1GR3
    Friend of mine and me are working on a flash developed iOS (and later Android) puzzle board game. He's a programmer and I'm a designer/developer so (no surprise) we have a different points of view. anyway, he's method: make small tiles (100x100px) in photoshop join them into the board and then in flash apply effects to the board to avoid repetition (80's not in the good way) my method: precompose the whole board (960x640px+bleed) in photoshop and than mask active and inactive areas in flash what do you think? thank you in advance!

    Read the article

  • Full Width Divs using ScrollTo.js

    - by David Haigh
    This is my first ever post. I am using the ScrollTo jQuery plugin and i have stumbled across a problem... I have 6 rows, each with 6 child divs , I would like each of these child divs to be full width. The plugin works great but I cannot seem to get the child div to be full width (then use ScrollTo to 'slide' to the next div, or to a div on the next row. ) Here is my code: http://jsfiddle.net/RZjrV/ Is it even possible? I have set body - Overflow:hidden to avoid any initial confusion. Thank you all who read this post and even take a minute to think about it. David

    Read the article

  • What should I know about Python to identify comments in different source files?

    - by Can't Tell
    I have a need to identify comments in different kinds of source files in a given directory. ( For example java,XML, JavaScript, bash). I have decided to do this using Python (as an attempt to learn Python). The questions I have are 1) What should I know about python to get this done? ( I have an idea that Regular Expressions will be useful but are there alternatives/other modules that will be useful? Libraries that I can use to get this done?) 2) Is Python a good choice for such a task? Will some other language make this easier to accomplish?

    Read the article

  • Table overflow working in Chrome and IE but not Firefox

    - by Craig
    I am trying to get a layout that always takes up the entire screen, no more, no less. The layout has a header row, a 200px wide left bar (scrollable), and a scrollable content area. This works in Chrome and IE, but in Firefox the scroll bars never show nor work. Any thoughts? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"> <html> <head> <style type="text/css"> * { margin: 0; padding: 0; } html, body { height: 100%; background-color: yellow; overflow: hidden; } #viewTable { width: 100%; height: 100%; background-color: red; } #header { height: 72px; background-color: blue; } #leftcol { vertical-align: top; width: 200px; height: 100%; background-color: green; } #menu { height: 100%; overflow: auto; } #rightcol { vertical-align: top; width: auto; height: 100%; background-color: purple; } #content { height: 100%; overflow: auto; } </style> </head> <body> </body> <table id="viewTable" border="0" cellpadding="0" cellspacing="0"> <tr> <td colspan="2" id="header"> Header </td> </tr> <tr> <td id="leftcol"> <div id="menu"> 0<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 100<br/> </div> </td> <td id="rightcol"> <div id="content"> 0<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 1<br/> 100<br/> </div> </td> </tr> </table> hi </html> I would have preferred to use CSS, but could not find any way to do it. The hi should no show, it is simply there to verify it does not. Thank you!

    Read the article

  • Convert IEnumerable<dynamic> to JsonArray

    - by Burt
    I am selecting an IEnumerable<dynamic> from the database using Rob Conery's Massive framework. The structure comes back in a flat format Poco C#. I need to transform the data and output it to a Json array (format show at bottom). I thought I could do the transform using linq (my unsuccessful effort is shown below): using System.Collections.Generic; using System.Json; using System.Linq; using System.ServiceModel.Web; .... IEnumerable<dynamic> list = _repository.All("", "", 0).ToList(); JsonArray returnValue = from item in list select new JsonObject() { Name = item.Test, Data = new dyamic(){...}... }; Here is the Json I am trying to generate: [ { "id": "1", "title": "Data Title", "data": [ { "column1 name": "the value", "column2 name": "the value", "column3 name": "", "column4 name": "the value" } ] }, { "id": "2", "title": "Data Title", "data": [ { "column1 name": "the value", "column2 name": "the value", "column3 name": "the value", "column4 name": "the value" } ] } ]

    Read the article

  • How do i pass a number from a list as a parameter in scheme?

    - by wyatt
    I need to take a number from a list and convert it to a number so that i can pass it as a parameter. im trying to make a 1-bit adder in scheme. i've written the code for the or gate and the xor gate and also the half adder and now im trying to combine them all to make a full adder. im not sure if im going about it the right way. any input will be appreciated thank you. (define or-gate (lambda (a b) (if (= a 1) 1 (if (= b 1) 1 0)))) (define xor-gate (lambda (a b) (if (= a b) 0 1))) (define ha (lambda (a b) (list (xor-gate a b)(and-gate a b)))) (define fa (lambda (a b cin) (or-gate (cdr(ha cin (car (ha a b))))(cdr(ha a b))))) the issue i get when i run the program is that the half adder (ha) function outputs a list as a value and that makes the values incompatible with my other procedures because they require numbers and not lists. i feel like there is a simple solution but i dont know it.

    Read the article

  • Two "Calendar" entries listed on iPad - can't write to calendar using EventKit

    - by Neal
    My iOS app integrates with the device's calendar. On my iPad when I view the calendar app and tap the Calendars button on the top left to choose which calendars to show I see one entry named "Calendar". In my app when I loop through available calendars per the code below "Calendar" is listed twice. One is CalDAV for the type, the other is Local. I'm unable to create calendar entries in one of them, I believe the "Local" one, not sure why. Why do I see "Calendar" listed twice when I do NOT see it listed twice in the iCal app? public static List<string> Calendars { get { var calendars = new List<string>(); var ekCalendars = EventStore.Calendars; if (ekCalendars != null && ekCalendars.Length > 0) { foreach (EKCalendar cal in ekCalendars) { if (cal.AllowsContentModifications) calendars.Add(cal.Title); } calendars.Sort(); } return calendars; } }

    Read the article

  • Execute a function to affect different template class instances

    - by Samer Afach
    I have a complicated problem, and I need help. I have a base case, class ParamBase { string paramValue; //... } and a bunch of class templates with different template parameters. template <typename T> class Param : public ParamBase { T value; //... } Now, each instance of Param has different template parameter, double, int, string... etc. To make it easier, I have a vector to their base class pointers that contains all the instances that have been created: vector<ParamBase*> allParamsObjects; The question is: How can I run a single function (global or member or anything, your choice), that converts all of those different instances' strings paramValue with different templates arguments and save the conversion result to the appropriate type in Param::value. This has to be run over all objects that are saved in the vector allParamsObjects. So if the template argument of the first Param is double, paramValue has to be converted to double and saved in value; and if the second Param's argument is int, then the paramValue of the second has to be converted to int and saved in value... etc. I feel it's almost impossible... Any help would be highly appreciated :-)

    Read the article

  • Implement Background Music with Pause/Play Icon in JQuery/Javascript

    - by Amnesiac11
    Hello and thank you in advance. I'm quite newto JQuery/Javascript and am unsure how to implement my embedded background music with my pause/play icons. Any help would be greatly appreciated. Thanks in advance! <div id="toggle" class="play" style="width: 314px; height: 311px"></div> <script type="text/javascript"></script> $(document).ready(function() { $('#music').attr("class", "false"); $('#toggle').bind("click", function() { if ($(this).attr("class") == "play") $(this).attr("class", "pause"); else $(this).attr("class", "play"); }); });

    Read the article

  • Algorithm to match natural text in mail

    - by snøreven
    I need to separate natural, coherent text/sentences in emails from lists, signatures, greetings and so on before further processing. example: Hi tom, last monday we did bla bla, lore Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. list item 2 list item 3 list item 3 Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid x ea commodi consequat. Quis aute iure reprehenderit in voluptate velit regards, K. ---line-of-funny-characters-####### example inc. 33 evil street, london mobile: 00 234534/234345 Ideally the algorithm would match only the bold parts. Is there any recommended approach - or are there even existing algorithms for that problem? Should I try approximate regular expressions or more statistical stuff based on number of punctation marks, length and so on?

    Read the article

  • jQuery function unresponsive after changing html

    - by asdgfas sagas
    $(document).ready(function () { $(".tab_content").hide(); //Hide all content $(".tab_content:first").show(); //Show first tab content $(".next").click(function() { $(".tab_content").hide(); //Hide all tab content $('#tab_change').html('<div class="back"></div>'); $("#tab2").show(); return false; }); $(".back").click(function() { $(".tab_content").hide(); //Hide all tab content $('#tab_change').html('<div class="next"></div>'); $("#tab1").show(); return false; }); THe problem is that when next is clicked, the 2nd tab opens. But after the html of #tab_change changed, the back button is responsive. The $(".back").click(function() { doesnt work. HTML is posted for reference. <div class="dialog_content" style="width:780px"> <div id="tab_change" class="left border_right"> <div class="next"></div> </div> <div id="tab1" class="tab_content"> </div> <div id="tab2" class="tab_content"> <div class="right"><?php include("C:/easyphp/www/zabjournal/lib/flexpaper/php/split_document.php"); ?> </div> </div> </div>

    Read the article

  • perl regular expressions substitution/replacement using variables with special characters

    - by user961627
    Okay I've checked previous similar questions and I've been juggling with different variations of quotemeta but something's still not right. I have a line with a word ID and two words - the first is the wrong word, the second is right. And I'm using a regex to replace the wrong word with the right one. $line = "ANN20021015_0104_XML_16_21 A$xAS A$xASA"; @splits = split("\t",$line); $wrong_word = quotemeta $splits[1]; $right_word = quotemeta $splits[2]; print $right_word."\n"; print $wrong_word."\n"; $line =~ s/$wrong_word\t/$right_word\t/g; print $line; What's wrong with what I'm doing? Edit The problem is that I'm unable to retain the complete words - they get chopped off at the special characters. This code works perfectly fine for words without special characters. The output I need for the above example is: ANN20021015_0104_XML_16_21 A$xASA A$xASA But what I get is ANN20021015_0104_XML_16_21 A A Because of the $ character.

    Read the article

  • Simple nested setTimeout() only runs once (JavaScript)

    - by danielfaraday
    For some reason my galleryScroll() function only runs once, even though the function calls itself using setTimeout(). I'm thinking the issue may be related to scope, but I'm not sure: http://jsfiddle.net/CYEBC/2/ $(document).ready(function() { var x = $('#box').offset().left; var y = $('#box').offset().top; galleryScroll(); function galleryScroll() { x = x + 1; y = y + 1; $('#box').offset({ left: x, top: y }); setTimeout('galleryScroll()', 100); } });? The HTML: <html> <head> </head> <body> <div id="box"> </div> </body> </html>

    Read the article

  • Trying to create fields based on a case statement

    - by dido
    I'm having some trouble with the query below. I am trying to determine if the "category" field is A, B or C and then creating a field based on the category. That field would sum up payments field. But I'm running into error saying "incorrect syntax near keyword As". I am creating this in a SQL View. Using SQL Server 2008 SELECT r.id, r.category CASE WHEN r.category = 'A' then SUM(r.payment) As A_payments WHEN r.category = 'B' then SUM(r.payment) As B_payments WHEN r.category = 'C' then SUM(r.payment) As C_payments END FROM r_invoiceTable As r GROUP BY r.id, r.category I have data where all of the above cases should be executed because the data that I have has A,B and C Sample Data- r_invoiceTable Id --- Category ---- Payment 222 A ---- 50 444 A ---- 30 111 B ---- 90 777 C ---- 20 555 C ---- 40 Desired Output A_payments = 80, B_payments = 90, C_payments = 60

    Read the article

  • Using LINQ on observable with GroupBy and Sum aggregate

    - by Mark Oates
    I have the following block of code which works fine; var boughtItemsToday = (from DBControl.MoneySpent bought in BoughtItemDB.BoughtItems select bought); BoughtItems = new ObservableCollection<DBControl.MoneySpent>(boughtItemsToday); It returns data from my MoneySpent table which includes ItemCategory, ItemAmount, ItemDateTime. I want to change it to group by ItemCategory and ItemAmount so I can see where I am spending most of my money, so I created a GroupBy query, and ended up with this; var finalQuery = boughtItemsToday.AsQueryable().GroupBy(category => category.ItemCategory); BoughtItems = new ObservableCollection<DBControl.MoneySpent>(finalQuery); Which gives me 2 errors; Error 1 The best overloaded method match for 'System.Collections.ObjectModel.ObservableCollection.ObservableCollection(System.Collections.Generic.List)' has some invalid arguments Error 2 Argument 1: cannot convert from 'System.Linq.IQueryable' to 'System.Collections.Generic.List' And this is where I'm stuck! How can I use the GroupBy and Sum aggregate function to get a list of my categories and the associated spend in 1 LINQ query?! Any help/suggestions gratefully received. Mark

    Read the article

  • OpenOffice/Libre office xml filter import

    - by marechs
    I'm using OpenOffice to convert documents to pdf/xls; Main system where usually is running Openoffice is Linux; There(in openoffice) is such thing as XML filters; A have package of those filters and usually to import this package I using(from launched openoffice): Tools-XML Filter settings -open package; It's like little converting server, but there is one problem - system needs X server to be running; So is there a way to import this XML filter package to Openoffice(or Libre office) from command line?

    Read the article

  • How to check with PHP does a SQL database already have

    - by Dan Horvat
    I've tried to find the answer to this question but none of the answers fit. I have two databases, one has 15.000.000 entries and I want to extract the necessary data and store it in a much smaller database with around 33.000 entries. Both databases are open at the same time. Or at least they should be. While having the big database open and extracting the entries from it, is it possible to check whether the value already exists in the smaller database? I just need some generic way which checks that.

    Read the article

  • How to stop rendering invisible faces

    - by TheMorfeus
    I am making a voxel-based game, and for needs of it, i am creating a block rendering engine. Point is, that i need to generate lots of cubes. Every time i render more than 16x16x16 chunk of theese blocks, my FPS is dropped down hardly, because it renders all 6 faces of all of theese cubes. THat's 24 576 quads, and i dont want that. So, my question is, How to stop rendering vertices(or quads) that are not visible, and therefore increase performance of my game? Here is class for rendering of a block: public void renderBlock(int posx, int posy, int posz) { try{ //t.bind(); glEnable(GL_CULL_FACE); glCullFace(GL_BACK);// or even GL_FRONT_AND_BACK */); glPushMatrix(); GL11.glTranslatef((2*posx+0.5f),(2*posy+0.5f),(2*posz+0.5f)); // Move Right 1.5 Units And Into The Screen 6.0 GL11.glRotatef(rquad,1.0f,1.0f,1.0f); glBegin(GL_QUADS); // Draw A Quad GL11.glColor3f(0.5f, 0.4f, 0.4f); // Set The Color To Green GL11.glTexCoord2f(0,0); GL11.glVertex3f( 1f, 1f,-1f); // Top Right Of The Quad (Top) GL11.glTexCoord2f(1,0); GL11.glVertex3f(-1f, 1f,-1f); // Top Left Of The Quad (Top) GL11.glTexCoord2f(1,1); GL11.glVertex3f(-1f, 1f, 1f); // Bottom Left Of The Quad (Top) GL11.glTexCoord2f(0,1); GL11.glVertex3f( 1f, 1f, 1f); // Bottom Right Of The Quad (Top) //GL11.glColor3f(1.2f,0.5f,0.9f); // Set The Color To Orange GL11.glTexCoord2f(0,0); GL11.glVertex3f( 1f,-1f, 1f); // Top Right Of The Quad (Bottom) GL11.glTexCoord2f(0,1); GL11.glVertex3f(-1f,-1f, 1f); // Top Left Of The Quad (Bottom) GL11.glTexCoord2f(1,1); GL11.glVertex3f(-1f,-1f,-1f); // Bottom Left Of The Quad (Bottom) GL11.glTexCoord2f(1,0); GL11.glVertex3f( 1f,-1f,-1f); // Bottom Right Of The Quad (Bottom) //GL11.glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red GL11.glTexCoord2f(0,0); GL11.glVertex3f( 1f, 1f, 1f); // Top Right Of The Quad (Front) GL11.glTexCoord2f(1,0); GL11.glVertex3f(-1f, 1f, 1f); // Top Left Of The Quad (Front) GL11.glTexCoord2f(1,1); GL11.glVertex3f(-1f,-1f, 1f); // Bottom Left Of The Quad (Front) GL11.glTexCoord2f(0,1); GL11.glVertex3f( 1f,-1f, 1f); // Bottom Right Of The Quad (Front) //GL11.glColor3f(1f,0.5f,0.0f); // Set The Color To Yellow GL11.glTexCoord2f(0,0); GL11.glVertex3f( 1f,-1f,-1f); // Bottom Left Of The Quad (Back) GL11.glTexCoord2f(1,0); GL11.glVertex3f(-1f,-1f,-1f); // Bottom Right Of The Quad (Back) GL11.glTexCoord2f(1,1); GL11.glVertex3f(-1f, 1f,-1f); // Top Right Of The Quad (Back) GL11.glTexCoord2f(0,1); GL11.glVertex3f( 1f, 1f,-1f); // Top Left Of The Quad (Back) //GL11.glColor3f(0.0f,0.0f,0.3f); // Set The Color To Blue GL11.glTexCoord2f(0,1); GL11.glVertex3f(-1f, 1f, 1f); // Top Right Of The Quad (Left) GL11.glTexCoord2f(1,1); GL11.glVertex3f(-1f, 1f,-1f); // Top Left Of The Quad (Left) GL11.glTexCoord2f(1,0); GL11.glVertex3f(-1f,-1f,-1f); // Bottom Left Of The Quad (Left) GL11.glTexCoord2f(0,0); GL11.glVertex3f(-1f,-1f, 1f); // Bottom Right Of The Quad (Left) //GL11.glColor3f(0.5f,0.0f,0.5f); // Set The Color To Violet GL11.glTexCoord2f(0,0); GL11.glVertex3f( 1f, 1f,-1f); // Top Right Of The Quad (Right) GL11.glTexCoord2f(1,0); GL11.glVertex3f( 1f, 1f, 1f); // Top Left Of The Quad (Right) GL11.glTexCoord2f(1,1); GL11.glVertex3f( 1f,-1f, 1f); // Bottom Left Of The Quad (Right) GL11.glTexCoord2f(0,1); GL11.glVertex3f( 1f,-1f,-1f); // Bottom Right Of The Quad (Right) //rquad+=0.0001f; glEnd(); glPopMatrix(); }catch(NullPointerException t){t.printStackTrace(); System.out.println("rendering block failed");} } Here is code that renders them: private void render() { GL11.glClear(GL11.GL_COLOR_BUFFER_BIT|GL11.GL_DEPTH_BUFFER_BIT); for(int y=0; y<32; y++){ for(int x=0; x<16; x++){ for(int z=0; z<16; z++) { b.renderBlock(x, y, z); } } } }

    Read the article

  • Python: (sampling with replacement): efficient algorithm to extract the set of DISSIMILAR N-tuples from a set

    - by Homunculus Reticulli
    I have a set of items, from which I want to select DISSIMILAR tuples (more on the definition of dissimilar touples later). The set could contain potentially several thousand items, although typically, it would contain only a few hundreds. I am trying to write a generic algorithm that will allow me to select N items to form an N-tuple, from the original set. The new set of selected N-tuples should be DISSIMILAR. A N-tuple A is said to be DISSIMILAR to another N-tuple B if and only if: Every pair (2-tuple) that occurs in A DOES NOT appear in B Note: For this algorithm, A 2-tuple (pair) is considered SIMILAR/IDENTICAL if it contains the same elements, i.e. (x,y) is considered the same as (y,x). This is a (possible variation on the) classic Urn Problem. A trivial (pseudocode) implementation of this algorithm would be something along the lines of def fetch_unique_tuples(original_set, tuple_size): while True: # randomly select [tuple_size] items from the set to create first set # create a key or hash from the N elements and store in a set # store selected N-tuple in a container if end_condition_met: break I don't think this is the most efficient way of doing this - and though I am no algorithm theorist, I suspect that the time for this algorithm to run is NOT O(n) - in fact, its probably more likely to be O(n!). I am wondering if there is a more efficient way of implementing such an algo, and preferably, reducing the time to O(n). Actually, as Mark Byers pointed out there is a second variable m, which is the size of the number of elements being selected. This (i.e. m) will typically be between 2 and 5. Regarding examples, here would be a typical (albeit shortened) example: original_list = ['CAGG', 'CTTC', 'ACCT', 'TGCA', 'CCTG', 'CAAA', 'TGCC', 'ACTT', 'TAAT', 'CTTG', 'CGGC', 'GGCC', 'TCCT', 'ATCC', 'ACAG', 'TGAA', 'TTTG', 'ACAA', 'TGTC', 'TGGA', 'CTGC', 'GCTC', 'AGGA', 'TGCT', 'GCGC', 'GCGG', 'AAAG', 'GCTG', 'GCCG', 'ACCA', 'CTCC', 'CACG', 'CATA', 'GGGA', 'CGAG', 'CCCC', 'GGTG', 'AAGT', 'CCAC', 'AACA', 'AATA', 'CGAC', 'GGAA', 'TACC', 'AGTT', 'GTGG', 'CGCA', 'GGGG', 'GAGA', 'AGCC', 'ACCG', 'CCAT', 'AGAC', 'GGGT', 'CAGC', 'GATG', 'TTCG'] # Select 3-tuples from the original list should produce a list (or set) similar to: [('CAGG', 'CTTC', 'ACCT') ('CAGG', 'TGCA', 'CCTG') ('CAGG', 'CAAA', 'TGCC') ('CAGG', 'ACTT', 'ACCT') ('CAGG', 'CTTG', 'CGGC') .... ('CTTC', 'TGCA', 'CAAA') ] [[Edit]] Actually, in constructing the example output, I have realized that the earlier definition I gave for UNIQUENESS was incorrect. I have updated my definition and have introduced a new metric of DISSIMILARITY instead, as a result of this finding.

    Read the article

  • How can I bind a simple Javascript array to an MVC3 controller action method?

    - by Sergio Tapia
    Here is the javascript code I use to create the array and send it on it's way: <script type="text/javascript" language="javascript"> $(document).ready(function () { $("#update-cart-btn").click(function() { var items = []; $(".item").each(function () { var productKey = $(this).find("input[name='item.ProductId']").val(); var productQuantity = $(this).find("input[type='text']").val(); items[productKey] = productQuantity; }); $.ajax({ type: "POST", url: "@Url.Action("UpdateCart", "Cart")", data: items, success: function () { alert("Successfully updated your cart!"); } }); }); }); </script> The items object is properly constructed with the values I need. What data type must my object be on the backend of my controller? I tried this but the variable remains null and is not bound. [Authorize] [HttpPost] public ActionResult UpdateCart(object[] items) // items remains null. { // Some magic here. return RedirectToAction("Index"); }

    Read the article

  • Get access to a lot of iPhone and iPad Quality Source Codes for only $89

    - by Pixmator
    Hi developers and coming developers! We are happy to release this new concept from Pixmator.com, where you can get access to a lot of iPhone and iPad source codes for only $89. Start making a pro-developed application by these great application examples with is followed with a Source Code, so you can get everything out of it! These applications is present with a fully professionally designed graphic. The engine and the code is as well, as the graphic! It looks awesome. It is awesome. Take a look, it doesn't hurt anyone. Hope you guys like it! It will be available for purchase soon! Check out the link below: Check it out here!

    Read the article

  • Elegance, thy Name is jQuery

    - by SGWellens
    So, I'm browsing though some questions over on the Stack Overflow website and I found a good jQuery question just a few minutes old. Here is a link to it. It was a tough question; I knew that by answering it, I could learn new stuff and reinforce what I already knew: Reading is good, doing is better. Maybe I could help someone in the process too. I cut and pasted the HTML from the question into my Visual Studio IDE and went back to Stack Overflow to reread the question. Dang, someone had already answered it! And it was a great answer. I never even had a chance to start analyzing the issue. Now I know what a one-legged man feels like in an ass-kicking contest. Nevertheless, since the question and answer were so interesting, I decided to dissect them and learn as much as possible. The HTML consisted of some divs separated by h3 headings.  Note the elements are laid out sequentially with no programmatic grouping: <h3 class="heading">Heading 1</h3> <div>Content</div> <div>More content</div> <div>Even more content</div><h3 class="heading">Heading 2</h3> <div>some content</div> <div>some more content</div><h3 class="heading">Heading 3</h3> <div>other content</div></form></body>  The requirement was to wrap a div around each h3 heading and the subsequent divs grouping them into sections. Why? I don't know, I suppose if you screen-scrapped some HTML from another site, you might want to reformat it before displaying it on your own. Anyways… Here is the marvelously, succinct posted answer: $('.heading').each(function(){ $(this).nextUntil('.heading').andSelf().wrapAll('<div class="section">');}); I was familiar with all the parts except for nextUntil and andSelf. But, I'll analyze the whole answer for completeness. I'll do this by rewriting the posted answer in a different style and adding a boat-load of comments: function Test(){ // $Sections is a jQuery object and it will contain three elements var $Sections = $('.heading'); // use each to iterate over each of the three elements $Sections.each(function () { // $this is a jquery object containing the current element // being iterated var $this = $(this); // nextUntil gets the following sibling elements until it reaches // an element with the CSS class 'heading' // andSelf adds in the source element (this) to the collection $this = $this.nextUntil('.heading').andSelf(); // wrap the elements with a div $this.wrapAll('<div class="section" >'); });}  The code here doesn't look nearly as concise and elegant as the original answer. However, unless you and your staff are jQuery masters, during development it really helps to work through algorithms step by step. You can step through this code in the debugger and examine the jQuery objects to make sure one step is working before proceeding on to the next. It's much easier to debug and troubleshoot when each logical coding step is a separate line. Note: You may think the original code runs much faster than this version. However, the time difference is trivial: Not enough to worry about: Less than 1 millisecond (tested in IE and FF). Note: You may want to jam everything into one line because it results in less traffic being sent to the client. That is true. However, most Internet servers now compress HTML and JavaScript by stripping out comments and white space (go to Bing or Google and view the source). This feature should be enabled on your server: Let the server compress your code, you don't need to do it. Free Career Advice: Creating maintainable code is Job One—Maximum Priority—The Prime Directive. If you find yourself suddenly transferred to customer support, it may be that the code you are writing is not as readable as it could be and not as readable as it should be. Moving on… I created a CSS class to see the results: .section{ background-color: yellow; border: 2px solid black; margin: 5px;} Here is the rendered output before:   …and after the jQuery code runs.   Pretty Cool! But, while playing with this code, the logic of nextUntil began to bother me: What happens in the last section? What stops elements from being collected since there are no more elements with the .heading class? The answer is nothing.  In this case it stopped because it was at the end of the page.  But what if there were additional HTML elements? I added an anchor tag and another div to the HTML: <h3 class="heading">Heading 1</h3> <div>Content</div> <div>More content</div> <div>Even more content</div><h3 class="heading">Heading 2</h3> <div>some content</div> <div>some more content</div><h3 class="heading">Heading 3</h3> <div>other content</div><a>this is a link</a><div>unrelated div</div> </form></body> The code as-is will include both the anchor and the unrelated div. This isn't what we want.   My first attempt to correct this used the filter parameter of the nextUntil function: nextUntil('.heading', 'div')  This will only collect div elements. But it merely skipped the anchor tag and it still collected the unrelated div:   The problem is we need a way to tell the nextUntil function when to stop. CSS selectors to the rescue: nextUntil('.heading, a')  This tells nextUntil to stop collecting sibling elements when it gets to an element with a .heading class OR when it gets to an anchor tag. In this case it solved the problem. FYI: The comma operator in a CSS selector allows multiple criteria.   Bingo! One final note, we could have broken the code down even more: We could have replaced the andSelf function here: $this = $this.nextUntil('.heading, a').andSelf(); With this: // get all the following siblings and then add the current item$this = $this.nextUntil('.heading, a');$this.add(this);  But in this case, the andSelf function reads real nice. In my opinion. Here's a link to a jsFiddle if you want to play with it. I hope someone finds this useful Steve Wellens CodeProject

    Read the article

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