Search Results

Search found 31491 results on 1260 pages for 'simple talk'.

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

  • Simple Hash that is always equal between C# and Java

    - by GaiusSensei
    I have a C# WebService and a (Java) Android Application. Is there a SIMPLE hash function that produces the same result between these two languages? The simplest C# hash is a String.GetHashCode(), but I can't replicate it in Java. The simplest Java hash is not simple at all. And I don't know if I can replicate it exactly in C#. In case it's relevant, I'm hashing passwords before sending it across the internet. I'm currently using Encode64, but that's obviously not secure since we can reverse it.

    Read the article

  • A simple log file format

    - by hgulyan
    Hi, I'm not sure if it was asked, but I couldn't find anything like this. My program uses a simple .txt file for log purposes, It just creates/opens a file and appends lines. After some time, I started to log quite a lot of activities, so the file became too large and hardly readable. I know, that it's not write way to do this, but I simply need to have a readable file. So I thought maybe there's a simple file format for log files and a soft to view it or if you'd have any other suggestions on this question? Thanks for help in advance.

    Read the article

  • Why is this simple hello world code segfaulting?

    - by socks
    Excuse the beginner level of this question. I have the following simple code, but it does not seem to run. It gets a segmentation fault. If I replace the pointer with a simple call to the actual variable, it runs fine... I'm not sure why. struct node { int x; struct node *left; struct node *right; }; int main() { struct node *root; root->x = 42; printf("Hello world. %d", root->x); getchar(); return 0; } What is wrong with this code?

    Read the article

  • Parallel.For(): Different results for simple addition

    - by TSS
    I'm just looking in to the new .NET 4.0 features. With that, I'm attempting a simple calculation using Parallel.For and a normal for(x;x;x) loop. However, I'm getting different results about 50% of the time (no code change). long sum = 0; Parallel.For(1, 10000, y => { sum += y; }); Console.WriteLine(sum.ToString()); sum = 0; for (int y = 1; y < 10000; y++) { sum += y; } Console.WriteLine(sum.ToString()); Surely I'm missing something simple or do not completely understand the concept. My guess is that the threads are trying to update "sum" at the same time. If so, is there an obvious way around it?

    Read the article

  • Call to a member function find() on a non-object simpleHTMLDOM PHP

    - by wandersolo
    I am trying to read a link from one page, print the url, go to that page, and read the link on the next page in the same location, print the url, go to that page (and so on...) All I'm doing is reading the url and passing it as an argument to the get_links() method until there are no more links. This is my code but it throws a Fatal error: Call to a member function find() on a non-object. Anyone know what's wrong? <?php $mainPage = 'https://www.bu.edu/link/bin/uiscgi_studentlink.pl/1346752597?ModuleName=univschr.pl&SearchOptionDesc=Class+Subject&SearchOptionCd=C&KeySem=20133&ViewSem=Fall+2012&Subject=&MtgDay=&MtgTime='; get_links($mainPage); function get_links($url) { $data = new simple_html_dom(); $data = file_get_html($url); $nodes = $data->find("input[type=hidden]"); $fURL=$data->find("/html/body/form"); $firstPart = $fURL[0]->action . '<br>'; foreach ($nodes as $node) { $val = $node->value; $name = $node->name; $name . '<br />'; $val . "<br />"; $str1 = $str1. "&" . $name . "=" . $val; } $fixStr1 = str_replace('&College', '?College', $str1); $fixStr2 = str_replace('Fall 2012', 'Fall+2012', $fixStr1); $fixStr3 = str_replace('Class Subject', 'Class+Subject', $fixStr2); $fixStr4 = $firstPart . $fixStr3; echo $nextPageURL = chop($fixStr4); get_links($nextPageURL); } ?>

    Read the article

  • Simple C# CSV Excel export class

    - by Chris
    Thought this might be handy for someone, this is an extremely simple CSV export class that I needed. Features: Extremely simple to use Escapes commas and quotes so excel handles them fine Exports date and datetimes in timezone-proof format Without further ado: using System; using System.Data.SqlTypes; using System.IO; using System.Text; using System.Collections.Generic; /// <summary> /// Simple CSV export /// Example: /// CsvExport myExport = new CsvExport(); /// /// myExport.AddRow(); /// myExport["Region"] = "New York, USA"; /// myExport["Sales"] = 100000; /// myExport["Date Opened"] = new DateTime(2003, 12, 31); /// /// myExport.AddRow(); /// myExport["Region"] = "Sydney \"in\" Australia"; /// myExport["Sales"] = 50000; /// myExport["Date Opened"] = new DateTime(2005, 1, 1, 9, 30, 0); /// /// Then you can do any of the following three output options: /// string myCsv = myExport.Export(); /// myExport.ExportToFile("Somefile.csv"); /// byte[] myCsvData = myExport.ExportToBytes(); /// </summary> public class CsvExport { /// <summary> /// To keep the ordered list of column names /// </summary> List<string> fields = new List<string>(); /// <summary> /// The list of rows /// </summary> List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); /// <summary> /// The current row /// </summary> Dictionary<string, object> currentRow { get { return rows[rows.Count - 1]; } } /// <summary> /// Set a value on this column /// </summary> public object this[string field] { set { // Keep track of the field names, because the dictionary loses the ordering if (!fields.Contains(field)) fields.Add(field); currentRow[field] = value; } } /// <summary> /// Call this before setting any fields on a row /// </summary> public void AddRow() { rows.Add(new Dictionary<string, object>()); } /// <summary> /// Converts a value to how it should output in a csv file /// If it has a comma, it needs surrounding with double quotes /// Eg Sydney, Australia -> "Sydney, Australia" /// Also if it contains any double quotes ("), then they need to be replaced with quad quotes[sic] ("") /// Eg "Dangerous Dan" McGrew -> """Dangerous Dan"" McGrew" /// </summary> string MakeValueCsvFriendly(object value) { if (value == null) return ""; if (value is INullable && ((INullable)value).IsNull) return ""; if (value is DateTime) { if (((DateTime)value).TimeOfDay.TotalSeconds==0) return ((DateTime)value).ToString("yyyy-MM-dd"); return ((DateTime)value).ToString("yyyy-MM-dd HH:mm:ss"); } string output = value.ToString(); if (output.Contains(",") || output.Contains("\"")) output = '"' + output.Replace("\"", "\"\"") + '"'; return output; } /// <summary> /// Output all rows as a CSV returning a string /// </summary> public string Export() { StringBuilder sb = new StringBuilder(); // The header foreach (string field in fields) sb.Append(field).Append(","); sb.AppendLine(); // The rows foreach (Dictionary<string, object> row in rows) { foreach (string field in fields) sb.Append(MakeValueCsvFriendly(row[field])).Append(","); sb.AppendLine(); } return sb.ToString(); } /// <summary> /// Exports to a file /// </summary> public void ExportToFile(string path) { File.WriteAllText(path, Export()); } /// <summary> /// Exports as raw UTF8 bytes /// </summary> public byte[] ExportToBytes() { return Encoding.UTF8.GetBytes(Export()); } }

    Read the article

  • HTML and PHP simple contact form.

    - by user317128
    I tried to make a simple contact form via HTML and PHP but the form doesnt seem to submit. it stays on the HTML page and doesnt post to the php form. would love someone to look over the code, thanks in advanced. simple_form.html cdoe <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Simple Feedback Form</title> </head> <body> <form action="send_simpleform.php" method="post"> <p>Your name<br /> <input name="sender_name" type="text" size="30" /></p> <p>Email<br /> <input name="sender_email" type="text" size="30" /></p> <p>Message<br /> <textarea name="message" cols="30" rows="5"></textarea></p> <input name="submit" type="button" value="Send This Form" /> </form> </body> </html> send_simpleform.php code <? if (($_POST[sender_name] == "") || ($_POST[sender_email] == "") || ($_POST[message] == "") { header("Location: simple_form.php"); exit; } $msg = "Email sent from wwwsite\n"; $msg .= "Sender's Name:\t $_POST[senders_name]\n"; $msg .= "Sender's E-mail:\t $_POST[senders_email]\n"; $msg .= "Sender's Message:\t $_POST[message]\n"; $to = "[email protected]"; $subject = "Website feedback message"; $mailheaders = "From: My web site <www.testwebsite.com>\n"; $mailherders .= "Reply to: $_POST[sender_email]\n"; $mail($to, $subject, $msg, $mailheaders); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Simple Feedback Form Sent</title> </head> <body> <h1>The following email has been sent</h1> <p>Your Name:<br /> <? echo "$_POST[sender_name]"; ?> <p>Your Email Adress:<br /> <? echo "$_POST[sender_email]"; ?> <p>Message:<br /> <? echo "$_POST[message]"; ?> </p> </body> </html>

    Read the article

  • Simple iPhone drawing app with Quartz 2D

    - by Mr guy 4
    I am making a simple iPhone drawing program as a personal side-project. I capture touches event in a subclassed UIView and render the actual stuff to a seperate CGLayer. After each render, I call [self setNeedsLayout] and in the drawRect: method I draw the CGLayer to the screen context. This all works great and performs decently for drawing rectangles. However, I just want a simple "freehand" mode like a lot of other iPhone applications have. The way I thought to do this was to create a CGMutablePath, and simply: CGMutablePathRef path; -(void)touchBegan { path = CGMutablePathCreate(); } -(void)touchMoved { CGPathMoveToPoint(path,NULL,x,y); CGPathAddLineToPoint(path,NULL,x,y); } -(void)drawRect:(CGContextRef)context { CGContextBeginPath(context); CGContextAddPath(context,path); CGContextStrokePath(context); } However, after drawing for more than 1 second, performance degrades miserably. I would just draw each line into the off-screen CGLayer, if it were not for variable opacity! The less-than-100% opacity causes dots to be left on the screen connecting the lines. I have looked at CGContextSetBlendingMode() but alas I cannot find an answer. Can anyone point me in the right direction? Other iPhone apps are able to do this with very good efficiency.

    Read the article

  • Simple list based output instead of style and javascript ridden ASP.net webforms menu

    - by Mike
    Hi All, Is there a way (or component i could use) to output a simple menu. I just need it output as a list, like you would use for a simple superfish menu. I've looked at the menu control and cssadapters (css friendly) which kind of works, except there is a lot of styles and javascript output with the menu which is destroying the look. If I can't find something that outputs a clean list, my next option is to craft some jquery to delete these styles. This is not my preferred option. If you have a better idea, please let me know. Just something that looks like this: <ul> Main Menu <li> hi </li> <li> second menu <ul> <li> <a href="hi.aspx"> in second menu </a></li> <li> <a href="rabbits.aspx"> hi there </a></li> </ul> </li> </ul> Thanks.

    Read the article

  • Android/Java -- Post simple text to Facebook wall?

    - by borg17of20
    Hello all, I'm trying to integrate posting to one's wall from within my app. I already have an area where the user can save his/her username and password (encrypted). I would like my program to recall the saved username and password, pass that to Facebook for authentication, and then allow the app to post simple text (maybe a link too) to the user's wall. That said, I've read everything on the developer pages at Facebook (the api looks completely foreign to me... I've never don't any type of web app development before... just desktop apps), and experimented with the Java libraries here: http://wiki.developers.facebook.com/index.php/User:Java but to be honest, I don't understand any of the various implementations. Some claim to be simple to use, but apparently they are all way above my head. I've even tried messing with the official Facebook Android SDK, but that uses a webview interface, and I can't pass in the username and password for easy authentication. Plus, I'm still clueless as to how to post to the wall even after correct authentication. Please help. Thanks. Oh, btw I already have a Facebook API key and Application ID.

    Read the article

  • catching a deadlock in a simple odd-even sending

    - by user562264
    I'm trying to solve a simple problem with MPI, my implementation is MPICH2 and my code is in fortran. I have used the blocking send and receive, the idea is so simple but when I run it it crashes!!! I have absolutely no idea what is wrong? can anyone make quote on this issue please? there is a piece of the code: integer,parameter::IM=100,JM=100 REAL,ALLOCATABLE ::T(:,:),TF(:,:) CALL MPI_COMM_RANK(MPI_COMM_WORLD,RNK,IERR) CALL MPI_COMM_SIZE(MPI_COMM_WORLD,SIZ,IERR) prv = rnk-1 nxt = rnk+1 LIM = INT(IM/SIZ) IF (rnk==0) THEN ALLOCATE(TF(IM,JM)) prv = MPI_PROC_NULL ELSEIF(rnk==siz-1) THEN NXT = MPI_PROC_NULL LIM = LIM+MOD(IM,SIZ) END IF IF (MOD(RNK,2)==0) THEN CALL MPI_SEND(T(2,:),JM+2,MPI_REAL,PRV,10,MPI_COMM_WORLD,IERR) CALL MPI_RECV(T(1,:),JM+2,MPI_REAL,PRV,20,MPI_COMM_WORLD,STAT,IERR) ELSE CALL MPI_RECV(T(LIM+2,:),JM+2,MPI_REAL,NXT,10,MPI_COMM_WORLD,STAT,IERR) CALL MPI_SEND(T(LIM+1,:),JM+2,MPI_REAL,NXT,20,MPI_COMM_WORLD,IERR) END IF as I understood even processes are not receiving anything while the odd ones finish sending successfully, in some cases when I added some print to observe what is going on I saw that the variable NXT is changing during the sending procedure!!! for example all the odd process was sending message to process 0 not their next one!

    Read the article

  • Endless problems with a very simple python subprocess.Popen task

    - by Thomas
    I'd like python to send around a half-million integers in the range 0-255 each to an executable written in C++. This executable will then respond with a few thousand integers. Each on one line. This seems like it should be very simple to do with subprocess but i've had endless troubles. Right now im testing with code: // main() u32 num; std::cin >> num; u8* data = new u8[num]; for (u32 i = 0; i < num; ++i) std::cin >> data[i]; // test output / spit it back out for (u32 i = 0; i < num; ++i) std::cout << data[i] << std::endl; return 0; Building an array of strings ("data"), each like "255\n", in python and then using: output = proc.communicate("".join(data))[0] ...doesn't work (says stdin is closed, maybe too much at one time). Neither has using proc.stdin and proc.stdout worked. This should be so very simple, but I'm getting constant exceptions, and/or no output data returned to me. My Popen is currently: proc = Popen('aux/test_cpp_program', stdin=PIPE, stdout=PIPE, bufsize=1) Advise me before I pull my hair out. ;)

    Read the article

  • Programming Technique: How to create a simple card game

    - by Shyam
    Hi, As I am learning the Ruby language, I am getting closer to actual programming. So I was thinking of creating a simple card game. My question isn't Ruby orientated, but I do know want to learn how to solve this problem with a genuine OOP approach. In my card game I want to have four players. Using a standard deck with 52 cards, no jokers/wildcards. In the game I won't use the Ace as a dual card, it is always the highest card. So, the programming problems I wonder about are the following: How can I sort/randomize the deck of cards? There are four types, each having 13 values. Eventually there can be only unique values, so picking random values could generate duplicates. How can I implement a simple AI? As there are tons of card games, someone would have figured this part out already, so references would be great. I am a truly Ruby nuby, and my goal here is to learn to solve problems, so pseudo code would be great, just to understand how to solve the problem programmatically. I apologize for my grammar and writing style if it's unclear, for it is not my native language. Also pointers to sites where such challenges are explained, would be a great resource! Thank you for your comments, answers and feedback!

    Read the article

  • Simple way to repeat a String in java

    - by e5
    I'm looking for a simple commons method or operator that allows me to repeat some String n times. I know I could write this using a for loop, but I wish to avoid for loops whenever necessary and a simple direct method should exist somewhere. String str = "abc"; String repeated = str.repeat(3); repeated.equals("abcabcabc"); Related to: repeat string javascript Create NSString by repeating another string a given number of times Edited I try to avoid for loops when they are not completely necessary because: They add to the number of lines of code even if they are tucked away in another function. Someone reading my code has to figure out what I am doing in that for loop. Even if it is commented and has meaningful variables names, they still have to make sure it is not doing anything "clever". Programmers love to put clever things in for loops, even if I write it to "only do what it is intended to do", that does not preclude someone coming along and adding some additional clever "fix". They are very often easy to get wrong. For loops that involving indexes tend to generate off by one bugs. For loops often reuse the same variables, increasing the chance of really hard to find scoping bugs. For loops increase the number of places a bug hunter has to look.

    Read the article

  • Simple Enterprise Library console application refuses to compile

    - by Vadim
    I just downloaded and installed Microsoft Enterprise Library 5.0. I fired up VS 2010 to play with EL 5 and created a very simple console application. However, it would not compile. I got the following error: The type or namespace name 'Data' does not exist in the namespace 'Microsoft.Practices.EnterpriseLibrary' (are you missing an assembly reference?) I added Microsoft.Practices.EnterpriseLibrary.Common, Microsoft.Practices.EnterpriseLibrary.Data, and Microsoft.Practices.Unity references to my project. Here's the simple code that refuses to compile. using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Unity; using Microsoft.Practices.EnterpriseLibrary.Data; using Microsoft.Practices.Unity; namespace EntLib { class Program { static void Main(string[] args) { IUnityContainer container = new UnityContainer(); container.AddNewExtension<EnterpriseLibraryCoreExtension>(); var defaultDatabase = container.Resolve<Database>(); } } } The error above complains about line #2 : using Microsoft.Practices.EnterpriseLibrary.Data; Someone probably will point out to a stupid mistake by me, but at the moment I fail to see it. I tried to remove and add again Microsoft.Practices.EnterpriseLibrary.Data to refences but it didn't help.

    Read the article

  • Simple multilingual CMS?

    - by Christoffer
    Hi, I have been searching for a while now for a dead simple CMS with multi-language support. The ideal candidate is very lean and offers the possibility to set up different languages for different domains. It's OK if the language support is provided by a plugin/extension. For example I want example.com to point to English and example.fr should be French. With different URI-mappings for SEO. It can be developed in either of PHP, Ruby or Python and has to be open source. Any tips? Thank you EDIT / MORE DETAILS What I want is a CMS that is as simple to use and grasp for a client as Radiant is, but with tabs on each resource that can translate articles to different languages. Languages have to be able to use multiple domains, one for each language. I want to easily use the same article for more than one language as well as have articles (e.g. blog posts or news stories) that are only connected to one language. The CMS should be very light in core functionality (like Radiant, unlike Drupal/Joomla) but be easily extendable with plugins.

    Read the article

  • Algorithm(s) for rearranging simple symbolic algebraic expressions

    - by Gabe Johnson
    Hi, I would like to know if there is a straightforward algorithm for rearranging simple symbolic algebraic expressions. Ideally I would like to be able to rewrite any such expression with one variable alone on the left hand side. For example, given the input: m = (x + y) / 2 ... I would like to be able to ask about x in terms of m and y, or y in terms of x and m, and get these: x = 2*m - y y = 2*m - x Of course we've all done this algorithm on paper for years. But I was wondering if there was a name for it. It seems simple enough but if somebody has already cataloged the various "gotchas" it would make life easier. For my purposes I won't need it to handle quadratics. (And yes, CAS systems do this, and yes I know I could just use them as a library. I would like to avoid such a dependency in my application. I really would just like to know if there are named algorithms for approaching this problem.)

    Read the article

  • Simple jQuery code contains a syntax error that I can't find

    - by inkedmn
    I've got this (remarkably) simple JavaScript function that is called when a user clicks a "Cancel" link: function hideNewUserPanel(){ $('#create_user_panel').slideUp('slow'); $('.right_interior_panel').slideDown('slow'); } And the code to add the handler: $(function(){ $('#cancel_create_user_btn').live('click', function(){ hideNewUserPanel(); } }); Functionally, everything works as expected. Trouble is, when I click the "Cancel" link, Firebug shows an error in the console: uncaught exception: Syntax error, unrecognized expression: # I've stepped through the code several times and the error appears at some point before the call to hideNewUserPanel(). At the risk of sounding like one of "those programmers" (the kind that claim to have found a bug in GCC and assume their own code is perfect), the exception is being thrown from somewhere within jQuery proper, so I assume the issue is in there. I'm using jQuery 1.3.2 (this is a legacy project using many jQuery plugins that will break if we update to 1.4.x). Is there anything obviously wrong with my code that I'm simply not seeing? This code is, frankly, very simple and I don't really see what the issue could be. Thanks!

    Read the article

  • Integrating Magento with a simple static website.

    - by ExtraLean
    Magento is an awesomely powerful ecommerce platform. That said, it is also very complex, and I'd like to know if there is a relatively simple way to utilize Magento as our mISV site's backend to fulfill orders without actually "using" Magento's framework to build the site, run the site, etc. In other words, I don't want to use the built-in CMS, etc. since we have a static website already built. I'd just like our Buy Now buttons to utilize the checkout stuff, and would like to be able to use the back-end part to keep track of orders etc. I was able to accomplish this "fairly" easily with osCommerce, but Magento is proving to be a little more difficult to wrap my head around since I've only started looking at it for a few days now. I found another person asking this same exact question on the Magento wiki (along with several others in the forum), and none of them ever receive a reply for some reason. I noticed that there are may Magento experts on Stack Overflow, so I thought I'd give it a go here. This is an example of one question asked by someone on their wiki, and it captures the essence of what I'm trying to accomplish: Hi, as far as I understand, all shopping cart/eCommerce solutions I see are full featured PHP driven web sites. This means that all the pages the user interacts with, are server generated, and thus, the experience, is tied to the magento framework/workflow. I’d like to integrate bits and pieces of eCommerce/shopping cart in my existing website. Effectively, I’d like to have: 1) on a product information page, a “buy now/add to cart” button that adds to a cart 2) on every page, a view cart/checkout option 3) on a checkout page, with additional content already in place, having the magento “checkout” block integrated in the page (and not the entire page generated from Magento). Have any of you done this with Magento? This is for a simple one-product website so any advice you could share would be highly appreciated.

    Read the article

  • Looking for a very simple file-based CMS

    - by nfm
    I'm building a site for a friend for free, and am trying to work out a good way for her to be able to easily make updates. I haven't used any CMSs before. I was browsing the web today looking at some, and they all seem way too complicated for what I'm after. Basically, all I want is a really simple CMS that pulls together HTML snippets in particular subdirectories, and wraps them in header/footer HTML and inserts them into a template page in the appropriate section. I'm imagining a site layout something like this: / /index.php /blog_template.php /news_template.php /blog/ /blog/header.php /blog/footer.php /blog/my-first-blog.html /blog/blogs-rule.html /blog/... Say index.php contains div#blog. PHP would wrap each /blog/*.html file in /blog/header.php and blog/footer.php, and insert them into the div#blog as div#blog([0-9]*). I haven't been able to find anything this basic, and am one step away from throwing something together myself, but I'm a bit short on time at the moment and figured I'd post here first. Has anyone come across something like this? I don't want any DB, extensions, user accounts, installation, config, updates... just a simple file based solution. Thanks :) Forgot to mention - needs to be FOSS and run on Linux!

    Read the article

  • VB.NET trying simple captcha

    - by Pride Grimm
    I'm trying to write a simple captcha program in vb.net. I'm just wanting to make an image from random numbers and display it, check the answer, and then proceed. I'm pretty new to vb.net, so I found some code to generate the information. I will cite the owner when I find it again (http://www.knowlegezone.com/80/article/Technology/Software/Asp-Net/Simple-ASP-NET-CAPTCHA-Tutorial) This is in the onload() of default2.aspx Public Sub returnNumer() Dim num1 As New Random Dim num2 As New Random Dim numQ1 As Integer Dim numQ2 As Integer Dim QString As String numQ1 = num1.Next(10, 15) numQ2 = num2.Next(17, 31) QString = numQ1.ToString + " + " + numQ2.ToString + " = " Session("answer") = numQ1 + numQ2 Dim bitmap As New Bitmap(85, 35) Dim Grfx As Graphics = Graphics.FromImage(bitmap) Dim font As New Font("Arial", 18, FontStyle.Bold, GraphicsUnit.Pixel) Dim Rect As New Rectangle(0, 0, 100, 50) Grfx.FillRectangle(Brushes.Brown, Rect) Grfx.DrawRectangle(Pens.PeachPuff, Rect) ' Border Grfx.DrawString(QString, font, Brushes.Azure, 0, 0) Response.ContentType = "Image/jpeg" bitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg) bitmap.Dispose() Grfx.Dispose() End Sub So I put this in a separate page, like this This all works find and dandy, but when I get the answer from the session like this Dim literal As String = Convert.ToString(Session("answer")) It's always one behind. So if The images adds to 32, the answer in session isn't 32. But after a refresh (and a new image) the session("answer") will be 32. Is there a way to refresh the session on page 1, after the default2.aspx loads? Is there a better way to do this? I though about trying to run the code all on one page, and trying to set the src of and image to returnNumber(), but I need a bit of help on that one.

    Read the article

  • Unit testing, mocking - simple case: Service - Repository

    - by rafek
    Consider a following chunk of service: public class ProductService : IProductService { private IProductRepository _productRepository; // Some initlization stuff public Product GetProduct(int id) { try { return _productRepository.GetProduct(id); } catch (Exception e) { // log, wrap then throw } } } Let's consider a simple unit test: [Test] public void GetProduct_return_the_same_product_as_getProduct_on_productRepository() { var product = EntityGenerator.Product(); _productRepositoryMock.Setup(pr => pr.GetProduct(product.Id)).Returns(product); Product returnedProduct = _productService.GetProduct(product.Id); Assert.AreEqual(product, returnedProduct); _productRepositoryMock.VerifyAll(); } At first it seems that this test is ok. But let's change our service method a little bit: public Product GetProduct(int id) { try { var product = _productRepository.GetProduct(id); product.Owner = "totallyDifferentOwner"; return product; } catch (Exception e) { // log, wrap then throw } } How to rewrite a given test that it'd pass with the first service method and fail with a second one? How do you handle this kind of simple scenarios? HINT: A given test is bad coz product and returnedProduct is actually the same reference.

    Read the article

  • MFC/CCriticalSection: Simple lock situation hangs

    - by raph.amiard
    I have to program a simple threaded program with MFC/C++ for a uni assignment. I have a simple scenario in wich i have a worked thread which executes a function along the lines of : UINT createSchedules(LPVOID param) { genProgThreadVal* v = (genProgThreadVal*) param; // v->searcherLock is of type CcriticalSection* while(1) { if(v->searcherLock->Lock()) { //do the stuff, access shared object , exit clause etc.. v->searcherLock->Unlock(); } } PostMessage(v->hwnd, WM_USER_THREAD_FINISHED , 0,0); delete v; return 0; } In my main UI class, i have a CListControl that i want to be able to access the shared object (of type std::List). Hence the locking stuff. So this CList has an handler function looking like this : void Ccreationprogramme::OnLvnItemchangedList5(NMHDR *pNMHDR, LRESULT *pResult) { LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); if((pNMLV->uChanged & LVIF_STATE) && (pNMLV->uNewState & LVNI_SELECTED)) { searcherLock.Lock(); // do the stuff on shared object searcherLock.Unlock(); // do some more stuff } *pResult = 0; } The searcherLock in both function is the same object. The worker thread function is passed a pointer to the CCriticalSection object, which is a member of my dialog class. Everything works but, as soon as i do click on my list, and so triggers the handler function, the whole program hangs indefinitely.I tried using a Cmutex. I tried using a CSingleLock wrapping over the critical section object, and none of this has worked. What am i missing ?

    Read the article

  • Strange behaviour of NSScanner on simple whitespace removal

    - by Michael Waterfall
    I'm trying to replace all multiple whitespace in some text with a single space. This should be a very simple task, however for some reason it's returning a different result than expected. I've read the docs on the NSScanner and it seems like it's not working properly! NSScanner *scanner = [[NSScanner alloc] initWithString:@"This is a test of NSScanner !"]; NSMutableString *result = [[NSMutableString alloc] init]; NSString *temp; NSCharacterSet *whitespace = [NSCharacterSet whitespaceCharacterSet]; while (![scanner isAtEnd]) { // Scan upto and stop before any whitespace [scanner scanUpToCharactersFromSet:whitespace intoString:&temp]; // Add all non whotespace characters to string [result appendString:temp]; // Scan past all whitespace and replace with a single space if ([scanner scanCharactersFromSet:whitespace intoString:NULL]) { [result appendString:@" "]; } } But for some reason the result is @"ThisisatestofNSScanner!" instead of @"This is a test of NSScanner !". If you read through the comments and what each line should achieve it seems simple enough!? scanUpToCharactersFromSet should stop the scanner just as it encounters whitespace. scanCharactersFromSet should then progress the scanner past the whitespace up to the non-whitespace characters. And then the loop continues to the end. What am I missing or not understanding?

    Read the article

  • Compiling simple gtk+ application

    - by sterh
    Hello, I try to compile simple gtk+ application in Anjuta IDE. Application is a simple window: # include <gtk/gtk.h> int main( int argc, char *argv[]) { GtkWidget *label; GtkWidget *window; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "??????????, ???!"); label = gtk_label_new("??????????, ???!"); gtk_container_add(GTK_CONTAINER(window), label); gtk_widget_show_all(window); g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_main(); return 0; } In make file i have: GTK_CFLAGS = -D_REENTRANT -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/directfb -I/usr/include/libpng12 -I/usr/include/pixman-1 GTK_LIBS = -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 But i see error, when i try to compile project: gtk/gtk.h - No such file or directory Thank you.

    Read the article

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