Daily Archives

Articles indexed Friday January 14 2011

Page 3/36 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • "for" loop inside another "for" loop

    - by jnkrois
    Hello everybody. I have quick question, and I'm sure some of you guys will be able to point out what I'm doing wrong. Basically, I want to create a table with (calendar), with the months and days of an entire year, and Im using php to do it, my code is doing something weird. What happens is that January is empty and the days for January are being put in february. My code so far is as follows: $months = 12; $monthsOfTheyear = array("Januany","February","March","April","May","June","July","August","September","October","November","December"); $currentMonth = date("n"); $currentYear = date("Y"); $daysOfTheMonth = cal_days_in_month(CAL_GREGORIAN, $currentMonth, $currentYear); for($i = 0; $i < $months; $i++){ echo " <tbody class='month'>"; echo " <tr> <td colspan='".$daysOfTheMonth."'> ".$monthsOfTheyear[$i]." </td> </tr> <tr> "; $daysOfEachMonth = cal_days_in_month(CAL_GREGORIAN, $i, $currentYear); for($d = 1; $d <= $daysOfEachMonth; $d++){ echo " <td> ".$d." </td> "; } echo " </tr> </tbody"; } I'm obviously doing something wrong, but I've been staring at the monitor for about an hour trying to figure it out. I'd appreciate any advice. Thanks

    Read the article

  • Trying to understand strtok

    - by Karthick
    Consider the following snippet that uses strtok to split the string madddy. char* str = (char*) malloc(sizeof("Madddy")); strcpy(str,"Madddy"); char* tmp = strtok(str,"d"); std::cout<<tmp; do { std::cout<<tmp; tmp=strtok(NULL, "dddy"); }while(tmp!=NULL); It works fine, the output is Ma. But by modifying the strtok to the following, tmp=strtok(NULL, "ay"); The output becomes Madd. So how does strtok exactly work? I have this question because I expected strtok to take each and every character that is in the delimiter string to be taken as a delimiter. But in certain cases it is doing that way but in few cases, it is giving unexpected results. Could anyone help me understand this?

    Read the article

  • Please help clarify my regex pattern

    - by Dmitriy Sosunov
    I have the following string: <script>m('02:29:1467301/>Sender1*>some text message?<<02:29:13625N1/>Sender2*>Recipient2: another message??<>A<<02:29:1393100=>User1*|0User2*|%></B><<','');</script> N.B. messages are separated by << I need extract from message the following parts: 1. Time 2. Sender 3. Recipient 4. Text Recipient may being defined or not, this field is optional. I do this by the following pattern: (?<message>(?<time>\d{1,2}:\d{1,2}:[0-9a-z]+)/>(?<messageData>(?<sender>.+?)\*>(.+?)))<< But, I cannot extract recipient separately from the message text. (?<message>(?<time>\d{1,2}:\d{1,2}:[0-9a-z]+)/>(?<messageData>(?<sender>.+?)\*>(((?<recipient>.+?):){0,1}(?<messageText>.+?))))<< Please help correct my pattern.

    Read the article

  • Adding a computed column to an ActiveRecord query

    - by bmwbzz
    Hi, I am running a query using a scope and some conditions. Something like this: conditions[:offset] = (options[:page].to_i - 1) * PAGE_SIZE unless options[:page].blank? conditions[:limit] = options[:limit] ||= PAGE_SIZE scope = Promo.enabled.active results = scope.all conditions I'd like to add a computed column to the query (at the point when I'm now calling scope.all). Something like this: (ACOS(least(1,COS(0.71106459055501)*COS(-1.2915436464758)*COS(RADIANS(addresses.lat))*COS(RADIANS(addresses.lng))+ COS(0.71106459055501)*SIN(-1.2915436464758)*COS(RADIANS(addresses.lat))*SIN(RADIANS(addresses.lng))+ SIN(0.71106459055501)*SIN(RADIANS(addresses.lat))))*3963.19) as accurate_distance Is there a way to do that without just using find_by_sql and rewriting the whole existing query? Thanks!

    Read the article

  • How can I manage building library projects that produce both a static lib and a dll?

    - by Scott Langham
    I've got a large visual studio solution with ~50 projects. There are configurations for StaticDebug, StaticRelease, Debug and Release. Some libraries are needed in both dll and static lib form. To get them, we rebuild the solution with a different configuration. The Configuration Manager window is used to setup which projects need to build in which flavours, static lib, dynamic dll or both. This can by quite tricky to manage and it's a bit annoying to have to build the solution multiple times and select the configurations in the right order. Static versions need building before non-static versions. I'm wondering, instead of this current scheme, might it be simpler to manage if, for the projects I needed to produce both a static lib and dynamc dll, I created two projects. Eg: CoreLib CoreDll I could either make both of these projects reference all the same files and build them twice, or I'm wondering, would it be possible to build CoreLib and then get CoreDll to link it to generate the dll? I guess my question is, do you have any advice on how to structure your projects in this kind of situation? Thanks.

    Read the article

  • Can I create support multiple database transactions on a single connection?

    - by draezal
    I have created a HyperSQL Database. I was just wondering whether I could run multiple transactions on a single connection. I didn't want to spawn a new connection for each transaction due to the overhead associated with this. Looking at some similar questions the suggestion appeared to be to create a pool of database connections and then block waiting for one to become available. This is a workable, but not desirable solution. Background Info (if this is relevant to the answer). My application will create a new thread when some request comes in. This request will require a database transaction. Then some not insignificant time later this transaction will be committed. Any advice appreciated :)

    Read the article

  • has_many :through when join table doesn't contain FK to both tables

    - by seth.vargo
    I have a structure that isn't really a has_many :through example, but I'd like it to behave like one: # user.rb belongs_to :blog has_many :posts # post.rb belongs_to :user # blog.rb has_many :users has_many :posts, :through => :users # this obviously doesn't work becase # both FKs aren't in the blogs table I want to get ALL posts for a blog in an array. I'm aware that I can do this with Ruby using each or getting fancy with collect, but I'd like to let SQL do the work. Can someone explain how I can set up my models in a way that lets me call @blog.posts using SQL, not Ruby? Edit: I know in SQL I can write something like: SELECT * FROM posts WHERE posts.user_id IN ( SELECT users.id FROM users WHERE users.blog_id = 7 ) which obviously shows two queries are needed. I don't think this is possible with a join, but I'm not totally sure. It's obvious that a subquery is needed, but how do I get rails to build that subquery with ARel instead of having to return and use Ruby to loop and collect and such?

    Read the article

  • Bash Read Array from External File

    - by jmituzas
    I have setup a Bash menu script that also requires user input. These inputs are wrote (appended to) a text file named var.txt like so: input[0]='192.0.0.1' input[1]='username' input[2]='example.com' input[3]='/home/newuser' Now what I am trying to accomplish is to be able to read from var.txt from a script kinda like this: useradd var.txt/${input[1]} now I know that wont work just using it for an example. Thanks in Advance, Joe

    Read the article

  • Phase REST XML into variable

    - by 001
    I want to get a response from the REST XML web service, and phase it into variables so I can use them in my program. 1) How come this code does not work? I get an empty string... // Get response string ws_response=""; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { // Get the response stream StreamReader reader = new StreamReader(response.GetResponseStream()); // web service response string ws_response = reader.ReadToEnd; // <---???? I get an empty string // do phasing here (ie XML element into variable) etc.. // }

    Read the article

  • How to override loading a TImage from the object inspector (at run-time)?

    - by Mawg
    Further to my previous question, which did not get a useful answer despite a bounty, I will try rephrasing the question. Basically, when the user clicks the ellipsis in the object inspector, Delphi opens a file/open dialog. I want to replace this handling with my own, so that I can save the image's path. I would have expected that all I need to do is to derive a class from TImage and override the Assign() function, as in the following code. However, when I do the assign function is never called. So, it looks like I need to override something else, but what? unit my_Image; interface uses Classes, ExtCtrls, Jpeg, Graphics; type Tmy_Image = class(Timage) private FPicture : TPicture; protected procedure OnChange(Sender: TObject); public { Public declarations } Constructor Create(AOwner: TComponent); override; procedure SetPicture(picture : TPicture); procedure Assign(Source: TPersistent); override; published { Published declarations - available in the Object Inspector at design-time } property Picture : TPicture read FPicture write SetPicture; end; // of class Tmy_Image() procedure Register; implementation uses Controls, Dialogs; procedure Register; begin RegisterComponents('Standard', [Tmy_Image]); end; Constructor Tmy_Image.Create(AOwner: TComponent); begin inherited; // Call the parent Create method Hint := 'Add an image from a file|Add an image from a file'; // Tooltip | status bar text AutoSize := True; // Control resizes when contents change (new image is loaded) Height := 104; Width := 104; FPicture := TPicture.Create(); self.Picture.Bitmap.LoadFromResourceName(hInstance, 'picture_poperty_bmp'); end; procedure Tmy_Image.OnChange(Sender: TObject); begin Constraints.MaxHeight := Picture.Height; Constraints.MaxWidth := Picture.Width; Self.Height := Picture.Height; Self.Width := Picture.Width; end; procedure Tmy_Image.SetPicture(picture : TPicture); begin MessageDlg('Tmy_Image.SetPicture', mtWarning, [mbOK], 0); // never called end; procedure Tmy_Image.Assign(Source: TPersistent); begin MessageDlg('Tmy_Image.Assign', mtWarning, [mbOK], 0); // never called end; end.

    Read the article

  • Tracd + varnish ( + nginx) setup on ubuntu 10.10

    - by user66831
    I have a currently setup trac server in domain.tld/subdir which is being proxied via nginx, I setup varnish and passed trac directly and the difference was visible to the naked eye, so I was wondering if anyone has setup tracd + varnish or tracd + nginx + varnish and would share the configs or pointers on the setup. would appreciate it :) thank you. my varnish config : http://kingpin.pastebin.com/fRLmckTk

    Read the article

  • Some HTTPS connections via NAT fail, but work on firewall itself.

    - by hnxn
    Hi, I am having trouble establishing some HTTPS connections from internal machines, even though these same connections work if initiated on the firewall itself. The firewall machine is running Ubuntu 10.04.1 and shorewall 4.4.6. The internet connection is Bell PPPoE DSL (in Canada). I have tried various MTU settings, it doesn't seem to make any difference. Other protocols (HTTP, FTP, etc) generally work. The problem seems to be limited to certain sites; this one never works from an internal machine, but always works from the firewall itself: From internal machine: $ wget https://images.fedex.com/images/ascend/shared/headers/nxgen/corp_logo.gif --2011-01-13 20:51:31-- https://images.fedex.com/images/ascend/shared/headers/nxgen/corp_logo.gif Resolving images.fedex.com... 184.24.96.69 Connecting to images.fedex.com|184.24.96.69|:443... connected. ^C From firewall: $ wget https://images.fedex.com/images/ascend/shared/headers/nxgen/corp_logo.gif --2011-01-13 20:58:28-- https://images.fedex.com/images/ascend/shared/headers/nxgen/corp_logo.gif Resolving images.fedex.com... 184.24.96.69 Connecting to images.fedex.com|184.24.96.69|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 840 [image/gif] Saving to: `corp_logo.gif' 2011-01-13 20:58:28 (149 MB/s) - `corp_logo.gif' saved [840/840] This URL always works from both internal and firewall: https://encrypted.google.com/images/logos/ssl_logo_lg.gif Any troubleshooting tips would be greatly appreciated!

    Read the article

  • Configure nginx to reverse proxy a single url, and issue 301 redirects to everything else

    - by Martin
    I am using nginx to issue redirects for a domain we are changing, but one of our old mobile apps becomes broken by this redirect when it issues one specific POST request to the old domain. Here is the current nginx configuration, how could I add a reverse proxy to perform a POST to the URL /post_url and redirect everything else the same as now? server { listen 80; server_name olddomain.com www.olddomain.com; rewrite ^(.*) http://www.newdomain.com$1 permanent; }

    Read the article

  • Mac OSX: Adobe Flash player 10.1.85.3 text issue

    - by sparkey
    Running Flash Player 10.1.85.3. on OS-X 10.6.4 I've run into a very strange issue with Adobe/Macromedia Flash. Text in dialogs sometimes is not displayed, and the containing boxes are distorted. It occurs in all browsers. This is best demonstrated on YouTube in some of their ads, as well as in Google Analytics overlays on graphs. You can see the issue here: As you can see, where I have moused over the high point, there should be a dialog with some text, but instead it is quite broken. I've tried uninstalling and reinstalling the Flash plugin several times, reinstalling Google Chrome, validating my fonts with FontBook (removed all dupes/ fonts with warnings). Also as a last resort I checked/ repaired perms on my disk. What should I do?

    Read the article

  • Qualifying 'happiness' in software development?

    - by mummey
    It occurred to me today that often the real goal of questions asked on sites such as this one (where the questions tend to be more open-ended than say, SO) is for the OP to become happier upon achieving the result. We often excuse this by saying our desire is to be more productive or release a better product, but if you continue to look down this path you can determine that the OP seeks greater productivity or product-quality because those are important to his/her 'happiness'. With that in-mind I ask this: Have their been efforts to study software development from this perspective? In other words, what practises increase happiness in those who develop software as a career, and who, if anyone, has researched this specifically? As I mentioned above, they may include strategies that increase productivity or improve product quality, but by no means should they be limited to just those.

    Read the article

  • Nvidia problem after inappropriate shut down

    - by bhappy
    Hi, After by battery died on my laptop I started my computer after plugging it to the ac adapter, for no reason that I know I cant use the visual effects any more as if my graphic card is not installed (my graphic card is GeForce 300m and nvidia x-settings is working) I tried generating a new xorg.conf file but nothing happened I marked all the installed nvidia driver in synaptic for re installation and didn't really help I googled the problem appears to be popular but couldn't find a solid solution Any Ideas ?

    Read the article

  • Using django-haystack, how do I perform a search with only partial terms?

    - by Sri Raghavan
    I've got a Haystack/xapian search index for django.contrib.auth.models.User. The template is simply {{object.get_full_name}} as I intend for a user to type in a name and be able to search for it. My issue is this: if I search, say, Sri (my full first name) I come up with a result for the user object pertaining to my name. However, if I search Sri Ragh - that is, my full name, and part of my last name, I get no results. How can I set Haystack up so that I can get the appropriate results for partial queries? (I essentially want it to search *Sri Ragh*, but I don't know if wildcards would actually do the trick, or how to implement them). This is my search query: results = SearchQuerySet().filter(content='Sri Ragh')

    Read the article

  • LINQ to SQL:DataContext.SubmitChanges not updating immediately

    - by aximili
    I have a funny problem. Doing DataContext.SubmitChanges() updates Count() in one way but not in the other, see my comment in the code below.(DC is the DataContext) var compliances = c.DataCompliances.Where(x => x.ComplianceCriteria.FKElement == e.Id); if (compliances.Count() == 0) // Insert if not exists { DC.DataCompliances.InsertOnSubmit(new DataCompliance { FKCompany = c.Id, FKComplianceCriteria = criteria.Id }); DC.SubmitChanges(); compliances = c.DataCompliances.Where(x => x.ComplianceCriteria.FKElement == e.Id); // At this point DC.DataCompliances.Count() has increased, // but compliances.Count() is still 0 // When I refresh the page however, it will be 1 } Why does that happen? I need to update compliances after inserting one. Does anyone have a solution?

    Read the article

  • Access violation C++ (Deleting items in a vector)

    - by Gio Borje
    I'm trying to remove non-matching results from a memory scanner I'm writing in C++ as practice. When the memory is initially scanned, all results are stored into the _results vector. Later, the _results are scanned again and should erase items that no longer match. The error: Unhandled exception at 0x004016f4 in .exe: 0xC0000005: Access violation reading location 0x0090c000. // Receives data DWORD buffer; for (vector<memblock>::iterator it = MemoryScanner::_results.begin(); it != MemoryScanner::_results.end(); ++it) { // Reads data from an area of memory into buffer ReadProcessMemory(MemoryScanner::_hProc, (LPVOID)(*it).address, &buffer, sizeof(buffer), NULL); if (value != buffer) { MemoryScanner::_results.erase(it); // where the program breaks } }

    Read the article

  • How to encrypt data in php using Public/Private keys?

    - by Xeoncross
    I have a small string of some data (less than 1kb) that I would like to have user agents pass to other sites when they are sent from my site. In order for the other sites to verify that I was the one that created the string I though of two options. The server pings me back to confirm (like paypal, openid, etc..) I use public/private keys to prove I sent the message (like PGP, DKIM, etc..) I don't want to setup HMAC because that would mean I have to use custom keys for each site which would be a pain. Out of those two choices it seems that #2 would save on bandwidth which makes it seem like a better choice. So how can you setup public/private key cryptography using PHP and are there any downsides?

    Read the article

  • Create comma separated string from 2 lists the groovy way

    - by Micor
    What I have so far is: def imageColumns = ["products_image", "procuts_subimage1", "products_subimage2", "prodcuts_subimage3", "products_subimage4"] def imageValues = ["1.jpg","2.jpg","3.jpg"] def imageColumnsValues = [] // only care for columns with values imageValues.eachWithIndex { image,i -> imageColumnsValues << "${imageColumns[i]} = '${image}'" } println imageColumnValuePair.join(", ") It works but I think it could be better. Wish there was a collectWithIndex ... Any suggestions?

    Read the article

  • XNA how to organize code with game components (managers)

    - by Johannes
    XNA If I have a button class, and I have a buttonManager class that manages what buttons to be drawn to the screen depending on what the current game state is (main menu, in game, etc), how do I organize my code so that when I click on a button, it takes the user to a different screen. (ex. options menu, ingame). To be more specific, if I were to put the check to see if the user clicks on the button within the buttonManager how would I have the game switch and run the actual game (which is in an entire different class)? Main gameclass buttonManager game component (adds buttons) Button class

    Read the article

  • JAX-RS --- How to return JSON and HTTP Status code together?

    - by masato-san
    I'm writing REST web app (Netbean6.9, JAX-RS, Toplink-essential) and trying to return JSON and Http status code. I have code ready and working just to return JSON when HTTP GET Method is called from client. Code snippet @Path("get/id") @GET @Produces("application/json") public M_?? getMachineToUpdate(@PathParam("id") String id) { //some code to return JSON . . return myJson But I also want to return HTTP status code (500, 200, 204 etc) along with returning JSON. I tried using HttpServletResponse object, response.sendError("error message", 500); But this made browser to think it's real 500 so output web page was regular Http 500 error page. What I want to is just to return status code so that my Javascript on client side can handle some logic depending on what HTTP status code is returned. (maybe just to display the error code and message on html page.) Is it possible to do so? or should HTTP status code not be used for such thing?

    Read the article

  • google url shortener api and jquery not working

    - by rahim
    i cant seem to get google's new url shortener api to work with jquery's post method: $(document).ready(function() { $.post("https://www.googleapis.com/urlshortener/v1/url", { longUrl: "http://www.google.com/"}, function(data){ console.log("data" + data); }); $('body').ajaxError(function(e, xhr, settings, exception) { $(this).text('fail'+e); console.log(exception); }); }); all of this gives me an empty (data) response AND an empty (exception) response. any ideas? ive also tried this with no success: $.ajax({ type: 'POST', url: "https://www.googleapis.com/urlshortener/v1/url", data: { longUrl: "http://www.google.com/"}, success: success, dataType: "jsonp" });

    Read the article

  • Apache ReWriteEngine throwing 500 Internal Server Error for too many internal redirects... why?!?!?!

    - by Stephen G
    I'm trying to implement a new ReWrite rule on my local dev machine. I have 13 rules set up already, and all work fine (even as of this writing). However, for some reason the newest one is throwing me 500 Internal Server Errors. The ReWrite rule is: RewriteRule stuff/public_html/vault/mystuff/view/(.*) /stuff/public_html/vault/mystuff/view/index.php?stuff=$1 RewriteRule stuff/public_html/vault/mystuff/view/(.*)/ /stuff/public_html/vault/mystuff/view/index.php?stuff=$1 Checked my apache logs and got this: [Thu Jan 13 22:07:43 2011] [error] [client ::1] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary., referer: http://localhost:8888/stuff/public_html/vault/mystuff/all/index.php?curr=7 On the script I am trying to redirect to view/index.php?stuff=$1, there is nothing that even remotely resembles a redirect of any kind. I do have a very, very basic session verifier being called at the top of the landing script, which is as follows: //Start session session_start(); //Check whether the session variable SESS_MEMBER_ID is present or not if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) == '')) { header("location: ".$root_http.""); exit(); } However, when I access the page directly, it acts as it should, and there is no redirect. All of my other ReWrite rules and their corresponding landing pages are set up the exact same way. This is blowing my mind. Any help, PLEASE!?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >