Daily Archives

Articles indexed Saturday December 25 2010

Page 17/22 | < Previous Page | 13 14 15 16 17 18 19 20 21 22  | Next Page >

  • Does single or double quote matter in str_ireplace in PHP ?

    - by Richards
    Hi, I've to replace newline (\n) with & in a string so that the received data could be parsed with parse_str() into array. The thing is that when I put \n in single quote it somehow turns out as to be replaced with a space: str_ireplace(array('&', '+', '\n'), array('', '', '&'), $response) "id=1 name=name gender=gender age=age friends=friends" But when I put \n in double quotes then it works just fine: str_ireplace(array('&', '+', "\n"), array('', '', '&'), $response) "id=1&name=name&gender=gender&age=age&friends=friends" Why is that so?

    Read the article

  • How to use a loop to download HTML with paging?

    - by Nai
    I want to loop through this URL and download the HTML. https://www.googleapis.com/customsearch/v1?key=AIzaSyAAoPQprb6aAV-AfuVjoCdErKTiJHn-4uI&cx=017576662512468239146:omuauf_lfve&q=" + searchTermFormat + "&num=10" +"&start=" + i start and num controls the paging of the URL. So if &start=2, and &num=10, it will scrape 10 results from page 2. Given that Google has a max limit of num = 10, how can I write a loop that loops through the HTML and scrape the results for the first 10 pages? This is what I have so far which just scrapes the first page. //input search term Console.WriteLine("What is your search query?:"); string searchTerm = Console.ReadLine(); //concantenate the strings using + symbol to make it URL friendly for google string searchTermFormat = searchTerm.Replace(" ", "+"); //create a new instance of Webclient and use DownloadString method from the Webclient class to extract download html WebClient client = new WebClient(); int i = 1; string Json = client.DownloadString("https://www.googleapis.com/customsearch/v1?key=AIzaSyAAoPQprb6aAV-AfuVjoCdErKTiJHn-4uI&cx=017576662512468239146:omuauf_lfve&q=" + searchTermFormat + "&num=10" + "&start=" + i); //create a new instance of JavaScriptSerializer and deserialise the desired content JavaScriptSerializer js = new JavaScriptSerializer(); GoogleSearchResults results = js.Deserialize<GoogleSearchResults>(Json); //output results to console Console.WriteLine(js.Serialize(results)); Console.ReadLine();

    Read the article

  • one table is shared between several websites

    - by sami
    I have a static table that's shared by several websites. By static, I mean that the data is read but never updated by the websites. Currently, all websites are served from the same server but that may change. I want to minimize the need for creating/maintaining this table for each of the websites, so I thought about turning it to an xml file that's stored in a shared library that all websites have access to. The problem is I use an ORM and use forign key constraints to ensure integrity of the ids used from that table, so by removing that table out of the MySQL database into an XML file, will this affect the integrity of the ids coming from that table? My table looks like this <table name="entry"> <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" /> <column name="title" type="VARCHAR" size="500" required="true" /> </table> and I use it as a foreign key in other tables <table name="refer"> <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" /> <column name="linkto" type="INTEGER"/> <foreign-key foreignTable="entry"> <reference local="linkto" foreign="id" /> </foreign-key> </table> So I'm wondering if I remove that table out of the database, is there a way to retain that referential integrity? And of course are these any other efficient ways to do the same thing? I just don't want to have to repeat that table for several websites.

    Read the article

  • Height of a binary tree

    - by Programmer
    Consider the following code: public int heightOfBinaryTree(Node node) { if (node == null) { return 0; } else { return 1 + Math.max(heightOfBinaryTree(node.left), heightOfBinaryTree(node.right)); } } I want to know the logical reasoning behind this code. How did people come up with it? Does some have an inductive proof? Moreover, I thought of just doing a BFS with the root of the binary tree as the argument to get the height of the binary tree. Is the previous approach better than mine?Why?

    Read the article

  • .NET's double.NaN - how does this counterintuitive feature work?

    - by GeReV
    I stumbled upon the definition of double.NaN in code: public const double NaN = (double)0.0 / (double)0.0; This is done similarly in PositiveInfinity and NegativeInfinity. double.IsNaN (with removing a few #pragmas and comments) is defined as: [Pure] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] public static bool IsNaN(double d) { if (d != d) { return true; } else { return false; } } This is, by far, the most counterintuitive thing I have ever seen in the .NET framework. How is 0.0 / 0.0 represented "behind the scenes"? How can division by 0 be possible in double, and why does NaN != NaN?

    Read the article

  • Can you help me refactor this piece of clojure code to produce a seq?

    - by ique
    I want to produce a seq that I can later do a (map) over. It should look like this: ((0 0) (0 1) (0 2) (0 3) ... (7 7)) The piece of code I have to do it right now seems very, very ugly to produce such a simple result. I need some help getting this straight. (loop [y 0 x 0 args (list)] (if (and (= y 7) (= x 7)) (reverse (conj args (list y x))) (if (= x 7) (recur (+ y 1) 0 (conj args (list y x))) (recur y (+ x 1) (conj args (list y x))))))

    Read the article

  • Combine guava's ImmutableList and varargs

    - by Stas Kurilin
    I want create constructor that will take one or more integers and save it into field as ImmutableList. According to "The right way to use varargs to pass one or more arguments" by Bloch's Item 42 I create smt like class Foo{ private final ImmutableList<Integer> bar; public Foo(Integer first, Integer... other) { this.bar = ImmutableList.<Integer>builder() .add(first) .addAll(Arrays.asList(other)) .build(); } } Why builder doesn't get generic automatically? And, as it smells. How I can rewrite it?

    Read the article

  • Access logs show someone "GET"ing a random ip, why does this return 200?

    - by Wilduck
    I have a small linux box set up with Apache as a way to teach myself Apache. I've set up port forwarding on my router so it's accessible from the outside world, and I've gotten a few strange requests for pages that don't exist from an ip address in China. Looking at my access_log shows that most of these return 404 errors, which I'm guessing is a good thing. However, there is one request that looks like this: 58.218.204.110 - - [25/Dec/2010:19:05:25 -600] "GET http://173.201.161.57/ HTTP/1.1" 200 3895 I'm curious what this request means... That ip address is unconnected to my server as far as I know, and visiting it simply tells me information about my uid. So, my questions are: How is it that this request is showing up in my access_log, why is it returning 200, and is this a bad thing (do I need to set up more security)?

    Read the article

  • Deploying a Django application in a virtual Ubuntu Server

    - by mfsaint
    I have a virtualbox machine running Ubuntu Server 10.04LTS. My intention is to this machine to work like a VPS, this way I can learn and prepare for when I get a VPS service. Apache+mod_wsgi for deploying the Django app seems the right choice to me. I have the domain (marianofalcon.com.ar) but nothing else, no DNS. The problem is that I'm pretty lost with all the deployment stuff. I know how to configure mod_wsgi(with the django.wsgi file) and apache(creating a VirtualHost). Something is missing and I don't know what it is. I think that I lack networking skills ant that's the big problem. Trying to host the app on a virtualbox adds some difficulty because I don't know well what IP to use. This is what I've got: file placed at: /etc/apache2/sites-available: NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin [email protected] ServerName www.my-domain.com ServerAlias my-domain.com Alias /media /path/to/my/project/media DocumentRoot /path/to/my/project WSGIScriptAlias / /path/to/your/project/apache/django.wsgi ErrorLog /var/log/apache2/error.log LogLevel warn CustomLog /var/log/apache2/access.log combined </VirtualHost> django.wsgi file: import os, sys wsgi_dir = os.path.abspath(os.path.dirname(__file__)) project_dir = os.path.dirname(wsgi_dir) sys.path.append(project_dir) project_settings = os.path.join(project_dir,'settings') os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()

    Read the article

  • Setting Environment Variable for nginx and Rails consumption

    - by kolrie
    Apache's module mod_env offers a handy way of setting environment variables in configuration files, like: <VirtualHost *:80> ServerName xyz.com DocumentRoot /var/www/rails_app/public PassengerAppRoot /var/www/rails_app SetEnv MY_VARIABLE contents </VirtualHost> http://httpd.apache.org/docs/2.0/mod/mod_env.html#setenv However, in nginx I couldn't find anything that serves the same purpose. What's the alternative here? I thought of setting environment variables in .profile files (I am using Ubuntu 10.04), but that wouldn't have the same "per vHost" isolation I have with Apache, right? What are the alternatives here?

    Read the article

  • How to convert eps file to a large jpeg image

    - by Anand
    Hello, I am using Linux. I want to convert an eps file to jpeg file. I find that I can use "convert" command. However, the resulting image looks very small. I want to enlarge the jpeg file by -resize option. It seems not to work. The resulting image is a pure black one. Do anyone has the same problem? Here are more details: 1: if I use convert -scale 1000x1000 your.eps your.jpg the resulting image looks like a low quality image. The eps vector image is not scaled properly. 2: if I use convert -geometry 300% your.eps your.jpg I get a pure black image. Here is my phf file: 2shared.com/document/RXl2Be-g/askquestions.html and my eps file: 2shared.com/file/qrmwKegj/askquestions.html Thank you very much for your help!

    Read the article

  • How to connect to my US network overseas via VPN?

    - by GiH
    I purchased an Apple TV for my parents and I have a netflix account. My parents live overseas, and I was wondering if they could use my account to get it to work. I read that it won't work unless you use proxies or a VPN, so I was wondering if its possible for me to setup a VPN to my network in the US instead of paying a service like StrongVPN? Setup: Router in US - Airport Extreme Router abroad - D-link (not sure of model) I know that the AppleTV doesn't have a built-in VPN client, maybe eventually when its jailbroken there will be an app, but as of now I'll have to use the routers right? Any other ideas are welcome as well!

    Read the article

  • Are Snow Leopard text substitutions scriptable?

    - by yonatron
    I prefer using typographical quotation marks when possible, so I love the Smart Quotes part of Snow Leopard’s text replacement feature. But there are a few cases in which I need to toggle it, and it’s a pain to do so from the contextual menu when I’m typing. Is there any way (preferably via AppleScript, but I can deal with other suggestions) to toggle specific types of text replacement for the frontmost text-input control? And if so, what’s a good way to assign it to a globally-accessible keyboard shortcut (via 3rd-party app if necessary)?

    Read the article

  • Can you write files in Chrome 8?

    - by greggory.hz
    I'm wondering if, with the new File API exposed in Chrome (I'm not concerned with cross-browser support at this time), it would be possible to write back to files opened via a file input. You can see an example of what I'm trying to accomplish here: http://www.grehz.com/ide. I know I can use server side scripts to dynamically create the files and allow the user to download them normally. I'm hoping that there's a way to accomplish this purely client side. I had read somewhere that you can write to files opened via a file input. I haven't been able to find any examples of this, though I have seen passing references to a FileWriter class. I would be completely not surprised if this wasn't possible though (it seems likely that there are security issues with this). Just looking for some guidance or resources. UPDATE: I was reading here: http://dev.w3.org/2009/dap/file-system/file-writer.html As I was playing around in Chrome, it looks like FileSaver and FileWriter are not implemented, but BlobBuilder is. I can call getBlob() on the BB object, is there any way I can then save that without FileSave or FileWriter?

    Read the article

  • What's the best way to return something like a collection of `std::auto_ptr`s in C++03?

    - by Billy ONeal
    std::auto_ptr is not allowed to be stored in an STL container, such as std::vector. However, occasionally there are cases where I need to return a collection of polymorphic objects, and therefore I can't return a vector of objects (due to the slicing problem). I can use std::tr1::shared_ptr and stick those in the vector, but then I have to pay a high price of maintaining separate reference counts, and object that owns the actual memory (the container) no longer logically "owns" the objects because they can be copied out of it without regard to ownership. C++0x offers a perfect solution to this problem in the form of std::vector<std::unique_ptr<t>>, but I don't have access to C++0x. Some other notes: I don't have access to C++0x, but I do have TR1 available. I would like to avoid use of Boost (though it is available if there is no other option) I am aware of boost::ptr_container containers (i.e. boost::ptr_vector), but I would like to avoid this because it breaks the debugger (innards are stored in void *s which means it's difficult to view the object actually stored inside the container in the debugger)

    Read the article

  • NHibernate: Using value tables for optimization AND dynamic join

    - by Kostya
    Hi all, My situation is next: there are to entities with many-to-many relation, f.e. Products and Categories. Also, categories has hierachial structure, like a tree. There is need to select all products that depends to some concrete category with all its childs (branch). So, I use following sql statement to do that: SELECT * FROM Products p WHERE p.ID IN ( SELECT DISTINCT pc.ProductID FROM ProductsCategories pc INNER JOIN Categories c ON c.ID = pc.CategoryID WHERE c.TLeft >= 1 AND c.TRight <= 33378 ) But with big set of data this query executes very long and I found some solution to optimize it, look at here: DECLARE @CatProducts TABLE ( ProductID int NOT NULL ) INSERT INTO @CatProducts SELECT DISTINCT pc.ProductID FROM ProductsCategories pc INNER JOIN Categories c ON c.ID = pc.CategoryID WHERE c.TLeft >= 1 AND c.TRight <= 33378 SELECT * FROM Products p INNER JOIN @CatProducts cp ON cp.ProductID = p.ID This query executes very fast but I don't know how to do that with NHIbernate. Note, that I need use only ICriteria because of dynamic filtering\ordering. If some one knows a solution for that, it will be fantastic. But I'll pleasure to any suggestions of course. Thank you ahead, Kostya

    Read the article

  • Wrap link around links in tweets with php preg_replace

    - by Ben Paton
    Hello I'm trying to display the latest tweet using the code below. This preg_replace works great for wrapping a link round twitter @usernames but doesn't work for web addresses in tweets. How do I get this code to wrap links around urls in tweets. <?php /** Script to pull in the latest tweet */ $username='fairgroceruk'; $format = 'json'; $tweet = json_decode(file_get_contents("http://api.twitter.com/1/statuses/user_timeline/{$username}.{$format}")); $latestTweet = htmlentities($tweet[0]->text, ENT_QUOTES); $latestTweet = preg_replace('/@([a-z0-9_]+)/i', '<a href="http://twitter.com/$1" target="_blank">@$1</a>', $latestTweet); $latestTweet = preg_replace('/http://([a-z0-9_]+)/i', '<a href="http://$1" target="_blank">http://$1</a>', $latestTweet); echo $latestTweet; ?> Thanks for the help, Ben

    Read the article

  • Android: retrieving all Drawable resources from Resources object

    - by Matt Huggins
    In my Android project, I want to loop through the entire collection of Drawable resources. Normally, you can only retrieve a specific resource via its ID using something like: InputStream is = Resources.getSystem().openRawResource(resourceId) However, I want to get all Drawable resources where I won't know their ID's beforehand. Is there a collection I can loop through or perhaps a way to get the list of resource ID's given the resources in my project? Or, is there a way for me in Java to extract all property values from the R.drawable static class?

    Read the article

  • overview/history of resident memory usage

    - by kapet
    I have a fairly complicated program (Python with SWIG'ed C++ code, long running server) that shows a constantly growing resident memory usage. I've been digging with the usual tools for the leak (valgrind, Pythons gc module, etc.) but to no avail so far. I'm a bit afraid that the actual problem is memory fragmentation within Python and/or libc managed memory. Anyway, my question is more specific right now: Is there a tool to visualize resident memory usage and ideally show how it develops over time? I think the raw data is in /proc/$PID/smaps but I was hoping there's some tool that shows me a nice graph of the amounts used by mmap'ed files vs. anonymous mmap'ed memory vs. heap over time so that it's easier to see (literally) what's changing. I couldn't find anything though. Does anybody know of a ready to use tool that graphs memory usage over space and time in an intuitive way?

    Read the article

  • batch source code downloading perl

    - by Jake
    Hello, I know of the "wget" function in shell, but I'm running perl from the command line on a windows machine and I was looking for a method of sequentially downloading the web source code from a site. For example: for www.abcd.com has the extension of it's subsites as 1,2,3 etc such that www.abcd.com/1 or www.abcd.com/2 is the syntax. I would like the source to be labeled as 1.source, 2.source etc for a defined set of pages 1-100 say. Thanks for the help, Jake

    Read the article

  • Java - Confused by the one class per file rule

    - by Mark
    The one class per file rule in Java has me a bit confused. I writing an Android app and trying to implement the accepted answer to this question: Common class for AsyncTask in Android? which calls for an interface definition which class A implements and class B accepts as an argument to its constructor. So I need an A.java and a B.java, but where does the interface go? Does it need a separate java file itself? Do I have to define it inside both A and B? If not how to import it? Also I will have about 10 different AsyncTask classes, but I don't want to bother creating a new file for each one. What would you recommend? Is there a way to put all 10 classes in one file? Or should I create a big if/then block inside the class and pass an argument telling it which of the 10 different tasks I want it to do?

    Read the article

  • Jquery Selecting Multiple Classes, Loading External Files

    - by WillingLearner
    I have 2 links, with the class dynamicLoad. <ul class="navbar"> <li><a href="Page3-News.html" class="dynamicLoad news">NEWS</a></li> <li><a href="Page2-Events.html" class="dynamicLoad">EVENTS</a></li> </ul> and then I have this already working code, which loads external pages into a div named #MainWrapper: <script type="text/javascript"> $( document ).ready( function() { $( 'a.dynamicLoad' ).click( function( e ) { e.preventDefault(); // prevent the browser from following the link e.stopPropagation(); // prevent the browser from following the link $( '#MainWrapper' ).load( $( this ).attr( 'href' ) ); }); }); </script> How do I edit this code and my links, so that i can target the 1st link with the classes of both dynamicLoad and news, and then, load another script and/or pages into the main wrapper, without breaking its already working functionality?

    Read the article

  • ASP.Net Vertical Menu with Scroll functionality

    - by Thomas
    Referring to Menu / Scrolling Example I would like to create / find the same functionality for a vertical menu. I tried the following. <asp:Menu ID="menuAccountMembers" runat="server" StaticSubMenuIndent="16px" Visible="true" RenderingMode="Table" ScrollDownImageUrl="~/Resources/scrolldown.jpg" ScrollUpImageUrl="~/Resources/scrollup.jpg"> <Items> But it doesnt display any scrolling images. I am using .net 4.0 Tried setting menuAccountMembers.RenderingCompatibility = new Version(3, 5); as well. If there a property to only display the first 5 root menu items, then show scroll bars for the rest? It can be click-able, no need to hover over to show next item.

    Read the article

  • Bing maps silverlight control in c#

    - by Dan Sewell
    Hello Chaps. Wondering if you could help me on this one.. Im trying to control my map with this c# code below. But for some reason its not doing anything when I call this method, and im not quite sure why?! Not sure if im using the .Equals properly? C# private void NW_zoom(object sender, ManipulationStartedEventArgs e) { GeoCoordinate abc = new GeoCoordinate(51.510, -0.1151); Map.CenterProperty.Equals(abc); var zoom = 12; Map.ZoomLevelProperty.Equals(zoom); } XMAL map control: <maps:Map ZoomLevel="10" Mode="Road" Margin="0,0,0,54" ZoomBarVisibility="Visible" ScaleVisibility="Visible" CredentialsProvider="xxxxxxx" Grid.Row="1"> <maps:Map.Center> <device:GeoCoordinate Latitude="51.510669" Longitude="-0.11512800"/> </maps:Map.Center> <maps:MapLayer x:Name="QuakeLayer" Height="726" Width="477" /> </maps:Map>

    Read the article

  • Objective-C(iPhone SDK) - Code for Chemical Equation Balancer help

    - by Evan
    -(IBAction) balancer: (id) sender{ double M[4][4]; M[0][0] = 6.0; M[0][1] = 0.0; M[0][2] = -1.0; M[0][3] = 0.0; M[1][0] = 12.0; M[1][1] = 0.0; M[1][2] = 0.0; M[1][3] = 2.0; M[2][0] = 6.0; M[2][1] = 2.0; M[2][2] = -2.0; M[2][3] = 1.0; M[3][0] = 0.0; M[3][1] = 0.0; M[3][2] = 0.0; M[3][3] = 0.0; int rowCount = 4; int columnCount = 4; int lead = 0; for (int r = 0; r < rowCount; r++) { if (lead = columnCount) break; int i = r; while (M[i][lead] == 0) { i++; if (i == rowCount) { i = r; lead++; if (lead == columnCount){ break; } } } double temp[4] ; temp[0] = M[r][0]; temp[1] = M[r][1]; temp[2] = M[r][2]; temp[3] = M[r][3]; M[r][0] = M[i][0]; M[r][1] = M[i][1]; M[r][2] = M[i][2]; M[r][3] = M[i][3]; M[i][0] = temp[0]; M[i][1] = temp[1]; M[i][2] = temp[2]; M[i][3] = temp[3]; double lv = M[r][lead]; for (int j = 0; j < columnCount; j++) M[r][j] = M[r][j] / lv; for (int f = 0; f < rowCount; f++) { if (f != r) { double l = M[f][lead]; for (int j = 0; j < columnCount; j++) M[f][j] = M[f][j] - l * M[r][j]; } } lead++; } NSString* myNewString = [NSString stringWithFormat:@"%g",M[0][3]]; label1.text = myNewString; } This is returning NaN, while it should be returning .16666667 for M[0][3]. Any suggestions on how to fix this?

    Read the article

< Previous Page | 13 14 15 16 17 18 19 20 21 22  | Next Page >