Daily Archives

Articles indexed Thursday May 27 2010

Page 14/122 | < Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >

  • How can I get this week's dates in Perl?

    - by ABach
    I have the following loop to calculate the dates of the current week and print them out. It works, but I am swimming in the amount of date/time possibilities in Perl and want to get your opinion on whether there is a better way. Here's the code I've written: #!/usr/bin/env perl use warnings; use strict; use DateTime; # Calculate numeric value of today and the # target day (Monday = 1, Sunday = 7); the # target, in this case, is Monday, since that's # when I want the week to start my $today_dt = DateTime->now; my $today = $today_dt->day_of_week; my $target = 1; # Create DateTime copies to act as the "bookends" # for the date range my ($start, $end) = ($today_dt->clone(), $today_dt->clone()); if ($today == $target) { # If today is the target, "start" is already set; # we simply need to set the end date $end->add( days => 6 ); } else { # Otherwise, we calculate the Monday preceeding today # and the Sunday following today my $delta = ($target - $today + 7) % 7; $start->add( days => $delta - 7 ); $end->add( days => $delta - 1 ); } # I clone the DateTime object again because, for some reason, # I'm wary of using $start directly... my $cur_date = $start->clone(); while ($cur_date <= $end) { my $date_ymd = $cur_date->ymd; print "$date_ymd\n"; $cur_date->add( days => 1 ); } As mentioned, this works, but is it the quickest or most efficient? I'm guessing that quickness and efficiency may not necessarily go together, but your feedback is very appreciated.

    Read the article

  • Emailing smtp with Python error

    - by jakecar
    I can't figure out why this isn't working. I'm trying to send an email from my school email address with this code I got online. The same code works for sending from my GMail address. Does anyone know what this error means? The error occurs after waiting for about one and a half minutes. import smtplib FROMADDR = "FROM_EMAIL" LOGIN = "USERNAME" PASSWORD = "PASSWORD" TOADDRS = ["TO_EMAIL"] SUBJECT = "Test" msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (FROMADDR, ", ".join(TOADDRS), SUBJECT) ) msg += "some text\r\n" server = smtplib.SMTP('OUTGOING_SMTP', 587) server.set_debuglevel(1) server.ehlo() server.starttls() server.login(LOGIN, PASSWORD) server.sendmail(FROMADDR, TOADDRS, msg) server.quit() And here's the error I get: Traceback (most recent call last): File "emailer.py", line 13, in server = smtplib.SMTP('OUTGOING_SMTP', 587) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 239, in init (code, msg) = self.connect(host, port) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 295, in connect self.sock = self._get_socket(host, port, self.timeout) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 273, in _get_socket return socket.create_connection((port, host), timeout) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.py", line 514, in create_connection raise error, msg socket.error: [Errno 60] Operation timed out

    Read the article

  • How do you get the host address and port from a System.Net.EndPoint?

    - by cyclotis04
    I'm using a TcpClient passed to me from a TcpListener, and for the life of me I can't figure out a simple way to get the address and port it's connected to. The best I have so far is _client.Client.RemoteEndPoint.ToString(); which returns a string in the form FFFF::FFFF:FFFF:FFF:FFFF%00:0000. I've managed to extract the address and port using Regular Expressions, but this seems like overkill. What am I missing?

    Read the article

  • CSS sprites navigation and User with image disabled.....

    - by metal-gear-solid
    I made a css menu with css sprites but the problem is with sprite we don't use inline image we use in background only so if images are disabled in browser then nothing will show . any solution for this ? For example : See this menu and turn off images : http://line25.com/wp-content/uploads/2009/css-menu/demo/demo.html (it will not be seen if images are disabled in browser) this menu is against on this quote Ensure your website works with images disabled Creating a site that relies too heavily on images is never a good idea. Although almost a thing of the past, there are still users who run at very low internet speeds. Also, if a user needs to—for whatever reason—disable images, can they still access all the content they need to? http://csswizardry.com/quick-tips/#tip-02 Shouldn't we use this type of navigation.

    Read the article

  • PHP / javascript live chat using too much bandwidth

    - by David
    So I am learning about javascript, so I am making a live chat system with PHP and javascript. I have it so the javascript refreshes the log (each message gets logged in a file on the server), and it refreshes every second. Im using firebug to monitor the resource usage, and I see under the net tab each times its updated, and the bytes add up really fast. I know I can change it to update less, but is there a way that when a user on the other end I'm talking to, when the send a message, it gets sent to the server, then an alert gets sent to me saying that the chatlog needs to update somehow. That way it only updates when the log is updated. let me know, thanks

    Read the article

  • Concatenative language inrepreter in Java

    - by Vojislav Stojkovic
    I'm interested in finding a concatenative language interpreter in Java. Ideally, it should satisfy the following conditions: It has an interpreter, not (only) a bytecode compiler for JVM. The language itself has decent documentation, not only a few examples and a "I'll document the rest someday" notice. The project is not completely abandoned. In short, I'm looking for a reasonably "alive" concatenative language that can be embedded into Java easily.

    Read the article

  • Why does my REST request return garbage data?

    - by Alienfluid
    I am trying to use LWP::Simple to make a GET request to a REST service. Here's the simple code: use LWP::Simple; $uri = "http://api.stackoverflow.com/0.8/questions/tagged/php"; $jsonresponse= get $uri; print $jsonresponse; On my local machine, running Ubuntu 10.4, and Perl version 5.10.1: farhan@farhan-lnx:~$ perl --version This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi I can get the correct response and have it printed on the screen. E.g.: farhan@farhan-lnx:~$ head -10 output.txt { "total": 1000, "page": 1, "pagesize": 30, "questions": [ { "tags": [ "php", "arrays", "coding-style" (... snipped ...) But on my host's machine to which I SSH into, I get garbage printed on the screen for the same exact code. I am assuming it has something to do with the encoding, but the REST service does not return the character set type in the response, so how do I force LWP::Simple to use the correct encoding? Any ideas what may be going on here? Here's the version of Perl on my host's machine: [dredd]$ perl --version This is perl, v5.8.8 built for x86_64-linux-gnu-thread-multi

    Read the article

  • Measuring daemon CPU utilization over a portion of it's wall clock run time

    - by WhirlWind
    I am dealing with a network-related daemon: it takes data in, processes it, and spits it out. I would like to increase the performance of this daemon by profiling it and reducing it's CPU utilization. I can do this easily on Linux with gprof. However, I would also like to use something like "time" to measure it's total CPU utilization over a period of time. If possible, I would like to time it over a period that is less than its total run time: thus, I would like to start the daemon, wait awhile, generate CPU statistics, stop generating them, then stop the daemon at some later time. The "time" command would work well for me, but it seems to require that I start and stop the daemon as a child of time. Is there a way to measure CPU utilization for only a portion of the daemon's wall clock time?

    Read the article

  • Have any software engineers gotten math degrees later in their careers?

    - by vin
    I have a bachelors in computer science and worked the last 12 years as a software engineer. I'm bored with doing general development work, so I want to specialize. I'm thinking about getting a master's degree in math so I can build math models and write algorithms to implement them. I'm unsure what type of work I'd do (financial, gaming, graphics, science, research, etc) but I'm open minded. I would need to refresh my undergrad math skills (which are old and faded), but I loved algebra and calculus. I've been working with couple statisticians so I've been finding myself more interested in statistics. Since I'm a parent supporting a household, I would have to continue working while studying. Have any software engineers taken this route? (Specifically, going from BS in comp sci to MS in math.) If so, what advice do you have for coursework, financing, and getting a job that combines programming with advanced math? How abundant are these kinds of jobs? I'm not sure where one starts. Also, how do you hop from a BS to an MS in a different subject?

    Read the article

  • Canvas element covering the entire screen?

    - by Stefan Kendall
    I'm trying to use <canvas> in iPhone Safari, and if I place the element in the body, there are unused pixels to the left and top of the element. I tried specifying margin:0;padding:0 with CSS to no avail. What's going on here? <html> <head> $(document).ready(function() { $('#screen').attr("height", $(window).height() ); $('#screen').attr("width", $(window).width() ); //prevent scrolling $(document).bind('touchstart touchmove', function(e) { e.preventDefault(); }); }); </script> </head> <body> <canvas id = "screen"> </canvas> </body> </html>

    Read the article

  • Using Window Handle to disable Mouse clicks using c#

    - by srk
    I need to disable the Mouse Clicks, Mouse movement for a specific windows for a Kiosk application. Is it Feasible in C# ? I have removed the menu bar and title bar of a specific window, will that be a starting point to achieve the above requirement ? How can i achieve this requirement. The code for removing the menu bar and title bar using window handle : #region Constants //Finds a window by class name [DllImport("USER32.DLL")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); //Sets a window to be a child window of another window [DllImport("USER32.DLL")] public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent); //Sets window attributes [DllImport("USER32.DLL")] public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); //Gets window attributes [DllImport("USER32.DLL")] public static extern int GetWindowLong(IntPtr hWnd, int nIndex); [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)] static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName); [DllImport("user32.dll")] static extern IntPtr GetMenu(IntPtr hWnd); [DllImport("user32.dll")] static extern int GetMenuItemCount(IntPtr hMenu); [DllImport("user32.dll")] static extern bool DrawMenuBar(IntPtr hWnd); [DllImport("user32.dll")] static extern bool RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags); //assorted constants needed public static uint MF_BYPOSITION = 0x400; public static uint MF_REMOVE = 0x1000; public static int GWL_STYLE = -16; public static int WS_CHILD = 0x40000000; //child window public static int WS_BORDER = 0x00800000; //window with border public static int WS_DLGFRAME = 0x00400000; //window with double border but no title public static int WS_CAPTION = WS_BORDER | WS_DLGFRAME; //window with a title bar public static int WS_SYSMENU = 0x00080000; //window menu #endregion public static void WindowsReStyle() { Process[] Procs = Process.GetProcesses(); foreach (Process proc in Procs) { if (proc.ProcessName.StartsWith("notepad")) { IntPtr pFoundWindow = proc.MainWindowHandle; int style = GetWindowLong(pFoundWindow, GWL_STYLE); //get menu IntPtr HMENU = GetMenu(proc.MainWindowHandle); //get item count int count = GetMenuItemCount(HMENU); //loop & remove for (int i = 0; i < count; i++) RemoveMenu(HMENU, 0, (MF_BYPOSITION | MF_REMOVE)); //force a redraw DrawMenuBar(proc.MainWindowHandle); SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_SYSMENU)); SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~WS_CAPTION)); } } }

    Read the article

  • std::out_of_range error?

    - by vette982
    I'm dealing with a file with a linked list of lines with each node looking like this: struct TextLine{ //The actual text string text; //The line number of the document int line_num; //A pointer to the next line TextLine * next; }; and I'm writing a function that adds spaces at the beginning of the lines found in the variable text, by calling functions like linelist_ptr->text.insert(0,1,'\t'); The program compiles, but when I run it I get this error: terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at Aborted Any ideas?

    Read the article

  • How to use PHP to POST to a web page then get the results back, locally

    - by Patrick Gates
    I have a page on my web server that is PHP that is set to do this if ($_POST['post'] == true) { echo: 'hello, world'; } I want to create a page that calls to that page, posts "post" equal to "true" and then returns the value "hello, world". I have a script that works, but only if the pages are on different servers. Unfortunately, both of these pages are on the same server, so, heres my code, and I'm hoping you guys can help me, Thank you :) function post($site, $post) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$site); curl_setopt($ch, CURLOPT_FAILONERROR,1); curl_setopt ($ch, CURLOPT_POST, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_TIMEOUT, 15); $retValue = curl_exec($ch); curl_close($ch); return $retValue; } echo post('data.php', 'post=true');

    Read the article

  • Advice on creating admin panel where user can upload, remove and order the files

    - by Manoj
    I'm working on a website where a logged-in admin needs the ability to upload and manage multiple PDFs from their computer. They'd need to be able to upload/remove the files. Also, there would need to be a way that they can sort the list of uploaded files and save that order so that other visitors to the page would see the list of files in that particular order. I looked into jQuery Uploadify among other things. Would javascript be the right way to go? Thanks, Manoj

    Read the article

  • Plesk SiteBuilder Install (UNIX)

    - by Clear.Cache
    Trying to install site builder from Plesk, for Unix. I have Centos 4x I installed fine using tarball files on their site. Ran: * rpm -Uhv updates/*.rpm * rpm -Uhv sitebuilder/*.rpm Documentation: http://download1.parallels.com/SiteBuilder/4.5.0/doc/install/en_US/html/index.htm Now, http://64.64.96.138/login Doesn't work. http://download1.parallels.com/SiteBuilder/4.5.0/doc/install/en_US/html/index.htm?fileName=performing_first_login_to_sitebuilder.htm What am I doing wrong here?

    Read the article

  • Tips For Maintaining the Website

    The main advantage of the online media is that it has got the ability to update, change and enhance it anytime without any negative effect. In fact, the website which does not offer its customers an evolving growing experience, than that website becomes insecure and unusable.

    Read the article

  • SSE SIMD Optimization For Loop

    - by Projectile Fish
    I have some code in a loop for(int i = 0; i < n; i++) { u[i] = c * u[i] + s * b[i]; } So, u and b are vectors of the same length, and c and s are scalars. Is this code a good candidate for vectorization for use with SSE in order to get a speedup?

    Read the article

  • Getting exception when coming back while loading data in controller while using LibXml.

    - by user133611
    Hi All, In my project i using LibXml to parse data, when i select a row in first controller i will take to next conttroller where i will get data using libxml if i click on the back button while loading the page i am getting exception. if i click afetr loading is completed it is working fine ca any one help me. the exception is showing here (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { // Process the downloaded chunk of data. xmlParseChunk(_xmlParserContext, (const char *)[data bytes], [data length], 0); } Thank You

    Read the article

  • Explaining abstraction to a non-programmer.

    - by Dominic Bou-Samra
    Abstraction is a concept that seems difficult to explain, without reverting to using programming terminology. I've thought about it a lot, and I can't come up with a satisfactory answer. Does anyone have any very general, yet very pertinent explanations? Metaphors, similes etc are all welcome.

    Read the article

  • Why use infinite loops?

    - by Moishe
    Another poster asked about preferred syntax for infinite loops. A follow-up question: Why do you use infinite loops in your code? I typically see a construct like this: for (;;) { int scoped_variable = getSomeValue(); if (scoped_variable == some_value) { break; } } Which lets you get around not being able to see the value of scoped_variable in the for or while clause. What are some other uses for "infinite" loops?

    Read the article

  • How can I filter a date of a DateTimeField in Django?

    - by Xidobix
    I am trying to filter a DateTimeField comparing with a date. I mean: MyObject.objects.filter(datetime_attr=datetime.date(2009,8,22)) I get an empty queryset list as an answer because (I think) I am not considering time, but I want "any time". Is there an easy way in Django for doing this? * I have the time in the datetime setted, it is not 00:00.

    Read the article

< Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >