Search Results

Search found 2654 results on 107 pages for 'c sharp newbie'.

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

  • How can I merge two lists and sort them working in 'linear' time?

    - by Sergio Tapia
    I have this, and it works: # E. Given two lists sorted in increasing order, create and return a merged # list of all the elements in sorted order. You may modify the passed in lists. # Ideally, the solution should work in "linear" time, making a single # pass of both lists. def linear_merge(list1, list2): finalList = [] for item in list1: finalList.append(item) for item in list2: finalList.append(item) finalList.sort() return finalList # +++your code here+++ return But, I'd really like to learn this stuff well. :) What does 'linear' time mean?

    Read the article

  • Can someone tell me why I'm seg faulting in this simple C program?

    - by user299648
    I keep on getting seg faulted, and for the life of me I dont why. The file I'm scanning is just 18 strings in 18 lines. I thinks the problem is the way I'm mallocing the double pointer called picks, but I dont know exactly why. I'm am only trying to scanf strings that are less than 15 chars long, so I don't see the problem. Can someone please help. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LENGTH 100 int main( int argc,char *argv[] ) { char* string = malloc( sizeof(char) ); char** picks = malloc(15*sizeof(char)); FILE* pick_file = fopen( argv[l], "r" ); int num_picks; for( num_picks=0 ; fgets( string, MAX_LENGTH, pick_file ) != NULL ; num_picks++ ) { printf("pick a/an %s ", string ); scanf( "%s", picks+num_picks ); } int x; for(x=0; x<num_picks;x++) printf("s\n", picks+x); }

    Read the article

  • Can some tell me why I am seg faulting in this simple C program?

    - by user299648
    I keep on getting seg faulted after I end my first for loop, and for the life of me I don't why. The file I'm scanning is just 18 strings in 18 lines. I thinks the problem is the way I'm mallocing the double pointer called picks, but I don't know exactly why. I'm am only trying to scanf strings that are less than 15 chars long, so I don't see the problem. Can someone please help. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LENGTH 100 int main( int argc,char *argv[] ) { char* string = malloc( 15*sizeof(char) ); char** picks = malloc(15*sizeof(char*)); FILE* pick_file = fopen( argv[l], "r" ); int num_picks; for( num_picks=0 ; fgets( string, MAX_LENGTH, pick_file ) != NULL ; num_picks++ ) { scanf( "%s", picks+num_picks ); } //this is where i seg fault int x; for(x=0; x<num_picks;x++) printf("s\n", picks+x); }

    Read the article

  • Cocoa : How do I catch drag operations initiated from an IKBrowserView?

    - by bucketmouse
    So I've got an IKBrowserView all wired up and happily dragging my custom datatype (provided lazily via PasteboardItem) from one window to another, but now I'm interested in detecting when the user drops some data onto the trashcan. Cocoa's documentation says to check the return type of the drag operation itself, but how exactly do I do this with an IKBrowserView? Once I call imageBrowser:writeItemsAtIndexes:toPasteboard: I don't seem to get any notifications other than the request for the pasteboard contents, which doesn't provide a pointer to the drag operation that invoked it.

    Read the article

  • run multiple programs in linux

    - by Betamoo
    I am trying to write a .sh file that runs many programs simultaneously I tried this prog1 prog2 But that runs prog1 then waits until prog1 ends and then starts prog2... So how can I run them in parallel? Thanks

    Read the article

  • Java library suggestions for implementing a custom web server

    - by dexter
    I would like to create a web server that will serve/accept json files through REST. The JSON files being served will come from a database query and format the results into JSON. Any suggestions for a good java library. I have tried using Apache HTTPComponents. While maybe I can just create a servlet but I am not really allowed to install a servlet container in the server machine.

    Read the article

  • So, I guess I can't use "&&" in the Python if conditional. Any help?

    - by Sergio Tapia
    Here's my code: # F. front_back # Consider dividing a string into two halves. # If the length is even, the front and back halves are the same length. # If the length is odd, we'll say that the extra char goes in the front half. # e.g. 'abcde', the front half is 'abc', the back half 'de'. # Given 2 strings, a and b, return a string of the form # a-front + b-front + a-back + b-back def front_back(a, b): # +++your code here+++ if len(a) % 2 == 0 && len(b) % 2 == 0: return a[:(len(a)/2)] + b[:(len(b)/2)] + a[(len(a)/2):] + b[(len(b)/2):] else: #todo! Not yet done. :P return I'm getting an error in the IF conditional. What am I doing wrong?

    Read the article

  • How strict should I be in the "do the simplest thing that could possible work" while doing TDD

    - by Support - multilanguage SO
    For TDD you have to Create a test that fail Do the simplest thing that could possible work to pass the test Add more variants of the test and repeat Refactor when a pattern emerge With this approach you're supposing to cover all the cases ( that comes to my mind at least) but I'm wonder if am I being too strict here and if it is possible to "think ahead" some scenarios instead of simple discover them. For instance, I'm processing a file and if it doesn't conform to a certain format I am to throw an InvalidFormatException So my first test was: @Test void testFormat(){ // empty doesn't do anything... processor.validate("empty.txt"); try { processor.validate("invalid.txt"); assert false: "Should have thrown InvalidFormatException"; } catch( InvalidFormatException ife ) { assert "Invalid format".equals( ife.getMessage() ); } } I run it and it fails because it doesn't throw an exception. So the next thing that comes to my mind is: "Do the simplest thing that could possible work", so I : public void validate( String fileName ) throws InvalidFormatException { if(fileName.equals("invalid.txt") { throw new InvalidFormatException("Invalid format"); } } Doh!! ( although the real code is a bit more complicated, I found my self doing something like this several times ) I know that I have to eventually add another file name and other test that would make this approach impractical and that would force me to refactor to something that makes sense ( which if I understood correctly is the point of TDD, to discover the patterns the usage unveils ) but: Q: am I taking too literal the "Do the simplest thing..." stuff?

    Read the article

  • Returning currently displayed index of an array Javascript...

    - by Jeff Kindred
    I have a simple array with x number of items. I am displaying them individually via a link click... I want to update a number that say 1 of 10. when the next one is displayed i want it to display 2 of 10 etc... I have looked all around and my brain is fried right now... I know its simple I just cant get it out. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Page Title</title> <link rel="stylesheet" href="style.css" type="text/css" media="screen" charset="utf-8"/> <script type="text/javascript"> var quotations = new Array() quotations[0]= "1" quotations[1]= "2" quotations[2]= "3" quotations[3]= "4" quotations[4]= "5" quotations[5]= "6" quotations[6]= "7" numQuotes = quotations.length; curQuote = 1; function move( xflip ) { curQuote = curQuote + xflip; if (curQuote > numQuotes) { curQuote = 1 ; } if (curQuote == 0) { curQuote = numQuotes ; } document.getElementById('quotation').innerHTML=quotations[curQuote - 1]; } var curPage = //this is where the current index should go </script> </head> <body> <div id="quotation"> <script type="text/javascript">document.write(quotations[0]);</script> </div> <div> <p><a href="javascript();" onclick="move(-1)">GO back</a> <script type="text/javascript">document.write(curPage + " of " + numQuotes)</script> <a href="javascript();" onclick="move(1)">GO FORTH</a></p> </div> </body> </html>

    Read the article

  • Simplest LINQ in C# troubleshooting.

    - by Jay
    I'm trying to learn a bit of LINQ but I'm having compile issues right off the bat. Is there any specific reason why this won't work? using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace HelloLINQ { class HelloLINQ { public static void Main() { Example1(); } public static void Example1() { var numbers = new int[] { 1, 5, 3, 7, 3, 8, 9, 3, 6, 6, 2 }; var under5 = from n in numbers select n; foreach (var n in under5) { Console.WriteLine(n); } } } } The error is: Could not find an implementation of the query pattern for source type 'int[]'. 'Select' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'?

    Read the article

  • why can't I use "&&" in python to mean 'and'?

    - by Sergio Tapia
    Here's my code: # F. front_back # Consider dividing a string into two halves. # If the length is even, the front and back halves are the same length. # If the length is odd, we'll say that the extra char goes in the front half. # e.g. 'abcde', the front half is 'abc', the back half 'de'. # Given 2 strings, a and b, return a string of the form # a-front + b-front + a-back + b-back def front_back(a, b): # +++your code here+++ if len(a) % 2 == 0 && len(b) % 2 == 0: return a[:(len(a)/2)] + b[:(len(b)/2)] + a[(len(a)/2):] + b[(len(b)/2):] else: #todo! Not yet done. :P return I'm getting an error in the IF conditional. What am I doing wrong?

    Read the article

  • globally get any field value in user table of logged in user

    - by Jugga
    Im making a gaming community and i wanna be able to grab any info of the user on any page without so instead of having much of queries on all pages i made this function. Is it better to do this? Will this slow down the site? /** * ??????? ???????? ?? ????? ??????? authed ?????????????. */ function UserData($f) { global $_SESSION; return mysql_result(mysql_query("SELECT `$f` FROM `users` WHERE `id` = ".intval($_SESSION['id'])), 0, $f); }

    Read the article

  • Followed the official android documentations but still could not use SQLite in app

    - by user366539
    My DBHelper class public class DBHelper extends SQLiteOpenHelper { public DBHelper(Context context) { super(context,"SIMPLE_DB",null,1); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE SIMPLE_TABLE ( " + "ID INTEGER PRIMARY KEY " + "DESC TEXT);"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } Activity class public class SimpleDatabase extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); DBHelper dbHelper = new DBHelper(this); SQLiteDatabase db = dbHelper.getReadableDatabase(); db.execSQL("INSERT INTO SIMPLE_TABLE VALUES (NULL, 'test');"); Cursor cursor = db.rawQuery("SELECT * FROM SIMPLE_TABLE", null); TextView text = (TextView)findViewById(R.id.textbox); text.setText(cursor.getString(0)); } } I figure it crashed (application has stopped unexpectedly!) at SQLiteDatabase db = ... because if I commented the code out from there to the end then it worked fine. But I have no idea whatsoever why it does that. Any help would be appreciated.

    Read the article

  • Creating object in database without showing view to user

    - by samuil
    I have controller with action new, and I want it to create ActiveRecord::Base descendant object, and write it into database (without showing it to user). def new active_order = current_user.orders.find {|o| o.status > 0 } active_order = Order.new if active_order.nil? (...) end Order.new creates local object, but my question is -- how to make Rails to fill it with default values and write to database?

    Read the article

  • “Function” calling inside store procedure

    - by idimba
    Hi, I have a big store procedure, that contains a lot of INSERTs. There're many INSERTS that almost identical - they're different by some parameter(s) (all INSERTs to the same table) Is there a way to create a function/method, to which I'll pass the above parameter(s) and the function/method will generate concrete INSERT's? Thanks

    Read the article

  • So, I guess I can't use "&&" in the Python if conditional. What should I use in this case? Any help?

    - by Sergio Tapia
    Here's my code: # F. front_back # Consider dividing a string into two halves. # If the length is even, the front and back halves are the same length. # If the length is odd, we'll say that the extra char goes in the front half. # e.g. 'abcde', the front half is 'abc', the back half 'de'. # Given 2 strings, a and b, return a string of the form # a-front + b-front + a-back + b-back def front_back(a, b): # +++your code here+++ if len(a) % 2 == 0 && len(b) % 2 == 0: return a[:(len(a)/2)] + b[:(len(b)/2)] + a[(len(a)/2):] + b[(len(b)/2):] else: #todo! Not yet done. :P return I'm getting an error in the IF conditional. What am I doing wrong? Edit: I meant no arrogance here. Someone edited my question title to make it sound douchy. I was genuinely confused about what to use, didn't think 'and' would be a keyword. Please don't downvote as other newbies might be confused about it as well.

    Read the article

  • Regular Expression Newbie

    - by Registered User
    I need to parse strings inputs where the columns are separated by columns and any field that contains a comma in the data is wrapped in quotes (commas separated, quoted text identifiers). For this project I need to remove the quotes and any commas that occur between pairs of quotes. Basically, I need to remove commas and quotes that are contained in fields while preserving the commas that are used to separate the fields. Here's a little code I put together that handles the simple scenario: // Sample input 1: This works and covers 99% of the records that I need to parse. string str1 = "[email protected],2010/03/27 12:2:02,,some_first_name,some_last_name,,\"This Address Works, Suite 200\",Some City,TN,09876-5432,9795551212x123,XYZ"; str1 = Regex.Replace(str1, "\"([^\"^,]*),([^\"^,]*)\"", "$1$2"); Console.WriteLine(str1); // Outputs: [email protected],2010/03/27 12:2:02,,some_first_name,some_last_name,,This Address Works Suite 200,Some City,TN,09876-5432,9795551212x123,XYZ Although this code works for most of my records, it doesn't work when a field contains more than one commas. What I would like to do is modify the code so that it remove each instance of a comma contained within the column no matter how many commas there are in the field. I don't want to hard code only handling 2 commas, or 3 commas, or 25 commas. The code should just remove all the commas in the field. Below is an example of what my code doesn't handle properly. // Sample input 2: This doesn't work since there is more than 1 comma between the quotes. string str2 = "[email protected],2010/03/27 12:2:02,,some_first_name,some_last_name,,\"i,l,k,e, c,o,m,m,a,s, i,n ,m,y, f,i,e,l,d\",Some City,TN,09876-5432,9795551212x123,XYZ"; str2 = Regex.Replace(str2, "\"([^\"^,]*),([^\"^,]*)\"", "$1$2"); Console.WriteLine(str2); // Desired output: [email protected],2010/03/27 12:2:02,,some_first_name,some_last_name,,i like commas in my field,Some City,TN,09876-5432,9795551212x123,XYZ Any help would be appreciated for this Regular Expression newbie.

    Read the article

  • Stupid newbie c++ two-dimensional array problem.

    - by paulson scott
    I've no idea if this is too newbie or generic for stackoverlflow. Apologies if that's the case, I don't intend to waste time. I've just started working through C++ Primer Plus and I've hit a little stump. This is probably super laughable but: for (int year = 0; year < YEARS; year++) { cout << "Year " << year + 1 << ":"; for (int month = 0; month < MONTHS; month++) { absoluteTotal = (yearlyTotal[year][year] += sales[year][month]); } cout << yearlyTotal[year][year] << endl; } cout << "The total number of books sold over a period of " << YEARS << " years is: " << absoluteTotal << endl; I wish to display the total of all 3 years. The rest of the code works fine: input is fine, individual yearly output is fine but I just can't get 3 years added together for one final total. I did have the total working at one point but I didn't have the individual totals working. I messed with it and reversed the situation. I've been messing with it for God knows how long. Any idea guys? Sorry if this isn't the place!

    Read the article

  • Newbie: Render RGB to GTK widget -- howto?

    - by Billy Pilgrim
    Hi All, Big picture: I want to render an RGB image via GTK on a linux box. I'm a frustrated GTK newbie, so please forgive me. I assume that I should create a Drawable_area in which to render the image -- correct? Do I then have to create a graphics context attached to that area? How? my simple app (which doesn't even address the rgb issue yet is this: int main(int argc, char** argv) { GdkGC * gc = NULL; GtkWidget * window = NULL; GtkDrawingArea * dpage = NULL; GtkWidget * page = NULL; gtk_init( &argc, & argv ); window = gtk_window_new( GTK_WINDOW_TOPLEVEL ); page = gtk_drawing_area_new( ); dpage = GTK_DRAWING_AREA( page ); gtk_widget_set_size_request( page, PAGE_WIDTH, PAGE_HEIGHT ); gc = gdk_gc_new( GTK_DRAWABLE( dpage ) ); gtk_widget_show( window ); gtk_main(); return (EXIT_SUCCESS); } my dpage is apparently not a 'drawable' (though it is a drawing area). I am confused as to a) how do I get/create the graphics context which is required in subsequent function calls? b) am I close to a solution, or am I so completely *#&@& wrong that there is no hope c) a baby steps tutorial. (I started with hello world as my base, so I got that far). any and all help appreciated. bp

    Read the article

  • BasicDBObject or QueryBuilder and some newbie questions of Java and mongo

    - by Kevin Xu
    hi I'm a fresh newbie to mongodb Q1 using query=new BasicDBObject(); query.put("i", new BasicDBObject("$gt",13)); and query=new QueryBuilder().put("i").Greaterthan(13).get() is there any difference inside of the system? Q2 I've created a class class findkv extends BasicDBObject{ //is gt gte lt lte public findkv(String fieldname,String op,Object tvalue) { if (op=="") this.put(fieldname,tvalue); else this.put(fieldname, new BasicDBObject(op,tvalue)); } } shall I use it or shall I just use original function? Q3 I've used mongo shell for a few weeks, and was customed to it, and find writing in mongo shell faster and shorter, which side has more advantage, writing in mongo or in java? I shall dump them from mongo to mysql Q4 I've an if (statement==true) return else dowhat; seems can't be compiled I know I can write if (statement!=true) dowhat else return, but can I still write in first style? q5 my eclipse is Eclipse Java EE IDE for Web Developers. Version: Juno Release Build id: 20120614-1722 I'd like to install Perl which I haven't learned yet I choose Install Update http://e-p-i-c.sf.net/updates/testing but it doesn't work, any method to install perl to eclipse manually?

    Read the article

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