Daily Archives

Articles indexed Monday February 7 2011

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

  • What is the ideal self hosted search engine?

    - by Tim Post
    I have an internal (intranet) site that is comprised of several blogs and forums, hundreds of static pages, lots of PDF files and several other document types. Its been glued together loosely over the last couple of years and now its my job to maintain it. I'm looking for a search engine that I can host myself that ideally: Allows for searching the Blog / Forum databases directly if given the database information and tables to search. Handles most text documents (PDF/DOC/ODF) Is open source, or allows access to the source code once purchased It doesn't matter to me what language or platform it is written in. Normally, I'd just use Google site search, but that's not an option for an intranet.

    Read the article

  • Site Search Engine for 1,000 page website

    - by Ian
    I manage a website with about 1,000 articles that need to be searchable by my members. The site search engines I've tried all had their own problems: Fluid Dynamics Search Engine Since it's written in perl, it was a bit hacky to integrate with my PHP-based CMS. I basically had to file_get_contents the search results page. However, FDSE had the best search results. Google CSE Ugh, the search results SUCK. It can't find documents even using unique strings. I'm so surprised that a Google search product is this bad. Nor can I get any answers on their 'help' forums, and I am a paying user. Boo, Google. Boo. Sphider Again, bad search results. Unable to locate some phrases used in link text. Better results than Google CSE though. Shame on Google that a free PHP script has better search results than their paid application. IndexTank This one looked really promising. I got all set up with their PHP API client. But it would only randomly add articles that I submitted. Out of 700+ articles I pushed to the index through their API, only 8 made it in. Unable to find any help on this subject. Update for IndexTank -- Got the above issue fixed, so this looks most promising so far. The site itself runs on php/mysql and FreeBSD, though this shouldn't matter for a web crawling indexer. I've looked at Lucene, but I don't know anything about Java or installing Java programs on my web server. I also do not have root access on my web server, if this would be required for installation. I really don't need a lot of fancy features. It just needs to be able to crawl my web site and return great (even decent!) search results. I don't need any crazy search operators. It doesn't need to index off my primary domain. It just needs to work! Thanks, Hive Mind!

    Read the article

  • Correct handling of return data

    - by Serhiy
    Hello, I have a question related to correct handling of returns of the DAO library I'm writing for one project. This library probably is going to be used by another people and I want to do it correctly. So I would like to know, how I should deal with return statements of the functions of my DAO. Example 1 I have function to getCustomer which should return String. In case query doesn't return any result should I return null, empty string or throw some kind of Exception? Example 2 I have function getCutomerList which return ArrayList. In case query doesn't return any result should I return null, empty ArrayList or throw some Exception? Example 3 Some sql exception was detected, what should I do: throw exception or do try..catch of the block where it can occur? What is the "good" practice or "best" practice to apply in my case? Thanks on advance, Serhiy.

    Read the article

  • How can i handle mouse double click event on textbox?

    - by Kar Cheng
    Hello, I want to open one child window on mouse double click of textbox. I know the only event available in Silverlight is MouseLeftButtonDown and you have to simulate double click. However it still doesn't work when i click in the middle of the textbox. It only works when i double click on the border of the textbox. Anybody has any ideas of how can i do this? If any 3rd party library is available then also it's fine. Thanks in advance:)

    Read the article

  • Help with calling a secure (SSL) webservice in Android.

    - by mmattax
    I'm new to Android and am struggling to make a call to an SSL web service for an Android Application. My code is as follows: Log.v("fs", "Making HTTP call..."); HttpClient http = new DefaultHttpClient(); HttpGet request = new HttpGet("https://example.com/api"); try { String response = http.execute(request, new BasicResponseHandler()); Log.v("fs", response); } catch (Exception e) { Log.v("fs", e.toString()); } The Output is: Making HTTP call... javax.net.SSLPeerUnverifiedException: No peer certificate Any suggestions to make this work would be great. EDIT I should note that this is a valid cert. It is not self-signed.

    Read the article

  • How to set the URL of a link to a variable using WATIR

    - by Alex
    Using WATIR and Excel, I'd like to take the first row of a table in Excel, visit the URL, then set the 12th link on the page as a variable in the cell next to the cell with the URL, then go to the next line and repeat. I'm stuck on getting the URL of the 12th link on the page to set as a variable that I can feed into the next cell in Excel. Here's what I have and it's not working. worksheet = workbook.WorkSheets(1) # get first workbook #declare test site test_site = worksheet.Range("a2").text #open ie ie = Watir::IE.new #go to test_site ie.goto test_site #find primlink ie.link(:index, 12).text = "primlink" puts primlink Any ideas?

    Read the article

  • What does this structure actually do?

    - by LGTrader
    I found this structure code in a Julia Set example from a book on CUDA. I'm a newbie C programmer and cannot get my head around what it's doing, nor have I found the right thing to read on the web to clear it up. Here's the structure: struct cuComplex { float r; float i; cuComplex( float a, float b ) : r(a), i(b) {} float magnitude2( void ) { return r * r + i * i; } cuComplex operator*(const cuComplex& a) { return cuComplex(r*a.r - i*a.i, i*a.r + r*a.i); } cuComplex operator+(const cuComplex& a) { return cuComplex(r+a.r, i+a.i); } }; and it's called very simply like this: cuComplex c(-0.8, 0.156); cuComplex a(jx, jy); int i = 0; for (i=0; i<200; i++) { a = a * a + c; if (a.magnitude2() > 1000) return 0; } return 1; So, the code did what? Defined something of structure type 'cuComplex' giving the real and imaginary parts of a number. (-0.8 & 0.156) What is getting returned? (Or placed in the structure?) How do I work through the logic of the operator stuff in the struct to understand what is actually calculated and held there? I think that it's probably doing recursive calls back into the stucture float magnitude2 (void) { return return r * r + i * i; } probably calls the '*' operator for r and again for i, and then the results of those two operations call the '+' operator? Is this correct and what gets returned at each step? Just plain confused. Thanks!

    Read the article

  • Linq to Entities Joins

    - by Bob Avallone
    I have a question about joins when using Linq to Entities. According to the documentation the use on the join without a qualifier performs like a left outer join. However when I execute the code below, I get a count returned of zero. But if I comment out the three join lines I get a count of 1. That would indicate that the join are acting as inner join. I have two questions. One which is right inner or outer as the default? Second how do I do the other one i.e. inner or outer? The key words on inner and outer do not work. var nprs = (from n in db.FMCSA_NPR join u in db.FMCSA_USER on n.CREATED_BY equals u.ID join t in db.LKUP_NPR_TYPE on n.NPR_TYPE_ID equals t.ID join s in db.LKUP_AUDIT_STATUS on n.NPR_STATUS_ID equals s.ID where n.ROLE_ID == pRoleId && n.OWNER_ID == pOwnerId && n.NPR_STATUS_ID == pNPRStatusId && n.ACTIVE == pActive select n).ToList(); if (nprs.Count() == 0) return null;

    Read the article

  • Replace some column values depending on a condition, MATLAB

    - by darkcminor
    I have a matrix like A= 4.0000 120.0000 92.0000 0 0 37.6000 0.1910 30.0000 10.0000 168.0000 74.0000 0 0 38.0000 0.5370 34.0000 10.0000 139.0000 80.0000 0 0 27.1000 1.4410 57.0000 1.0000 139.0000 60.0000 23.0000 846.0000 30.1000 0.3980 59.0000 5.0000 136.0000 72.0000 19.0000 175.0000 25.8000 0.5870 51.0000 7.0000 121.0000 0 0 0 30.0000 0.4840 32.0000 I want to replace the values of the first column that are greater than '5' to 0, also in the second column if the values are in range 121-130 replace them by 0, if they are in range 131-140 replece by 1, 141-150 by 2, 151-160 by 3... so the result matrix would be A= 4.0000 0.0000 92.0000 0 0 37.6000 0.1910 30.0000 0.0000 4.0000 74.0000 0 0 38.0000 0.5370 34.0000 0.0000 1.0000 80.0000 0 0 27.1000 1.4410 57.0000 1.0000 1.0000 60.0000 23.0000 846.0000 30.1000 0.3980 59.0000 5.0000 1.0000 72.0000 19.0000 175.0000 25.8000 0.5870 51.0000 0.0000 0.0000 0 0 0 30.0000 0.4840 32.0000 How to acomplish this? I was trying something like counter=1; for i = 1: rows if A(i,1) > 5 A(i ,1) = 0; end if A(i,2) > 120 && A(i,2) < 130 A(i ,2) = 0; end counter = counter+1; end Using a case could do the trick?

    Read the article

  • Matlab Correlation Function

    - by Joka
    function letter=read_char(imgn, num_letters) global templates comp=[ ]; for n=1:num_letters sem=corr2(imgn, templates{1,n}); comp=[comp sem]; end vd=find(comp==max(comp)); Can someon please explain what the 'FOR' loop does and how 'vd' is calculated? Also, what is the variable 'comp' and what will it looks like as the array also contains itself and another variable 'sem' which is calculated from the corr2 function. thanks

    Read the article

  • AsyncTask never finishes when other tasks are running

    - by rebeccamaher
    In my app, I show a menu screen immediately to the user and then use an AsyncTask to load some data from disk. Loading takes about 3 seconds if that's all the app had to do. When the user hits a menu option and the data hasn't loaded yet, a "Please wait, loading" screen appears. I have two problems: I recently added ads to my app and have found this is making my app hang sometimes because the AsyncTask never finishes loading. What seems to be happening is that the ad banner (I'm using admob and this happens when adsense ads are shown which admob do occasionally) is using resources by playing a simple animation and the AsyncTask never gets a chance to finish. I want to play a simple looping animation (e.g. making a view rotate) on my menu screen and this makes the AsyncTask take about 5 times longer to finish which renders the background loading pointless. How can I avoid situations where my background data never finishes loading or has such a low priority it takes a long time? I can't seem to find a way to increase the priority of an AsyncTask.

    Read the article

  • normalize data to scale from 1 to 10

    - by Matjaz Lipus
    I have a following data set: A B N 1 3 10 2 3 5 3 3 1 3 6 5 10 10 1 20 41 5 20 120 9 I'm looking for an excel function that will normalize A and B to N on scale from 1 to 10. In above example it would be 1 of 3 is best so N = 10 2 of 3 is in the middle N = 5 3 of 3 is worst N=1 20 of 120 is in second decade N=9 A = 1 && A <= B B is natural number 1 <= N <= 10

    Read the article

  • Android 2.2: Screen brightness/timeout question

    - by Johan
    Im using the following code to adjust the brightness of the screen: public void SetBright(float value) { Window mywindow = getWindow(); WindowManager.LayoutParams lp = mywindow.getAttributes(); lp.screenBrightness = value; mywindow.setAttributes(lp); } But i want the brightness to be 0% for a specific time. But when i use SetBright(0.0f), i cant change it back. I made a timer that runs for a minute with 0% brightness, then turns it back to 100%. Works when i use 10% for example. But when i turn it to 0% i cant seem to wake it up again. Any ideas how to solve this?

    Read the article

  • What does $this generally mean in PHP?

    - by xczzhh
    I am really new to PHP, so I am kind of confused seeing these different operators all day. Here is some code I came across when watching a video tutorail, I'd appreciate it if some could explain a little bit: function index() { $config = Array( 'protocol' => 'smtp', 'smtp_host' => 'ssl://smtp.googlemail.com', 'smtp_port' => 465, 'smtp_user' => '[email protected]', 'smtp_pass' =>'password', ); $this->load->library('email', $config); $this->email->set_newline("\r\n"); $this->email->from('[email protected]', 'Jerry'); $this->email->to('[email protected]'); $this->email->subject('this is an email test'); $this->email->message('this is test message!'); if($this->email->send()) { echo 'Your email was sent'; } else { show_error($this->email->print_debugger()); } } ...

    Read the article

  • Multiple user database design

    - by dieguitoweb
    I have to develop a basic social network for an academic purpose; but I need some tips for the users management.. The users are subdivided into 3 groups with different privilege: admins,analysts and standards users. For every user should be stored into the database the following information: name,lastname,e-mail,age,password. I'm not quite sure how I should design the database between theese two solutions: 1)one table called 'users' with the 'role' attribute that explain what a user can do and what can't do, and the permissions are managed via php 2)every application user is a database user created with the query 'CREATE ROLE' (It's a postgres database) and he has permissions on some tables granted with the 'GRANT' statement You should take into account that the project is for a database exam.. thanks

    Read the article

  • Force NCover 1.5.8 to use v4 framework like testdriven.net does?

    - by Sam Holder
    I want to run coverage from the command line, but can't seem to get NCover 1.5.8 to instrument the code. It must be possible as when I run coverage tests with TestDriven.net it works. the difference seems to be that TD.NET is able to get NCover to use framework 4.0 (you get this in the log when it runs : MESSAGE: v4.0.30319) but from the command line I can't make it (I get this in the log : MESSAGE: v2.0.50727) So how can I make NCover play nice with nunit from the commandline, like it does with TD.NET?

    Read the article

  • How to prepare a codebase for compiling on both Windows and Unix-based systems

    - by Max
    Hi! I am wondering about different solutions to easily compile my cross-platform application for both windows and unix. Right now I am using a makefile on Ubuntu, but before my codebase grows larger I'd like to perform the steps necessary to compile it on Windows, and then continue doing so regularly to see that it still works. I'd preferably not contaminate my SVN codebase repository with multiple "makefile" solutions, such as VC++ solutions and so on, I'd like a more automatic way. I tried using mingw with make for windows, but it seems my secondexpansion awesomeness doesn't work on the Windows version (or something like that). It wouldn't compile, and also complained about _winNT or something like that not being defined. How should I prepare my codebase for cross-platform easy compiling? Things like buildtools, perhaps autogenerate VS file from makefile, or something similar. Some preprocessor magic in a stdinc file perhaps? Thanks!

    Read the article

  • using libcurl to create a standalone site-polling program

    - by aitchnyu
    I am creating a standalone (no DLLs) windows C/C++ program that uses HTTP POST to periodically send data to an HTTP server. I identified libCURL as the HTTP client library as it seems simple and reliable. I still need to identify the environment (an IDE) which I can use to develop my project. My program has: poller- which checks the status of the connection a file writer when polled link is down a component which POSTs the file when link is up What is the appropriate IDE for this project? I heard endorsements for DevC++ and Visual C. I am a newb to coding and this site. Pardon me if I am unclear in anything.

    Read the article

  • Linq-to-XML explicit casting in a generic method

    - by vlad
    I've looked for a similar question, but the only one that was close didn't help me in the end. I have an XML file that looks like this: <Fields> <Field name="abc" value="2011-01-01" /> <Field name="xyz" value="" /> <Field name="tuv" value="123.456" /> </Fields> I'm trying to use Linq-to-XML to get the values from these fields. The values can be of type Decimal, DateTime, String and Int32. I was able to get the fields one by one using a relatively simple query. For example, I'm getting the 'value' from the field with the name 'abc' using the following: private DateTime GetValueFromAttribute(IEnumerable<XElement> fields, String attName) { return (from field in fields where field.Attribute("name").Value == "abc" select (DateTime)field.Attribute("value")).FirstOrDefault() } this is placed in a separate function that simply returns this value, and everything works fine (since I know that there is only one element with the name attribute set to 'abc'). however, since I have to do this for decimals and integers and dates, I was wondering if I can make a generic function that works in all cases. this is where I got stuck. here's what I have so far: private T GetValueFromAttribute<T>(IEnumerable<XElement> fields, String attName) { return (from field in fields where field.Attribute("name").Value == attName select (T)field.Attribute("value").Value).FirstOrDefault(); } this doesn't compile because it doesn't know how to convert from String to T. I tried boxing and unboxing (i.e. select (T) (Object) field.Attribute("value").Value but that throws a runtime Specified cast is not valid exception as it's trying to convert the String to a DateTime, for instance. Is this possible in a generic function? can I put a constraint on the generic function to make it work? or do I have to have separate functions to take advantage of Linq-to-XML's explicit cast operators?

    Read the article

  • Android How do you save an image with your own unique Image Name?

    - by Usmaan
    This sounds like a issue a beginner like me would only have...this is my code... private void saveAvatar(Bitmap avatar) { String strAvatarFilename = Id + ".jpg"; try { avatar.compress(CompressFormat.JPEG, 100, openFileOutput(strAvatarFilename, MODE_PRIVATE)); } catch (Exception e) { Log.e(DEBUG_TAG, "Avatar compression and save failed.", e); } Uri imageUriToSaveCameraImageTo = Uri.fromFile(new File(PhotoActivity.this.getFilesDir(), strAvatarFilename)); Editor editor = Preferences.edit(); editor.putString(PREFERENCES_AVATAR, imageUriToSaveCameraImageTo.getPath()); editor.commit(); ImageButton avatarButton = (ImageButton) findViewById(R.id.ImageButton_Avatar); String strAvatarUri = Preferences.getString(PREFERENCES_AVATAR, ""); Uri imageUri = Uri.parse(strAvatarUri); avatarButton.setImageURI(null); avatarButton.setImageURI(imageUri); } This does save the image but when i go to look at the image on the sd card ti is called imag001 etc not the ID i am labelling it. How do i save the image with a name i want to call it? regards

    Read the article

  • South African MVPs deserve their title.

    - by MarkPearl
    Recently I read a post by someone who felt the Microsoft MVP program had failed. My local experience with the MVP program would tend for me to disagree. On Saturday I attended a free Windows Phone 7 event organized by Robert MacLean and Rudi Grobler both of whom are local MVP’s. First of all, kudos to them for organizing the event which included a free lunch and flash stick and had some great content for a free event. Secondly, this is not the first time that either of these two MVP’s have organized events. They are active in the community, present at the majority of local events and are always approachable and give an “honest” opinion. For me, that is what an MVP stands for and at least in my region I feel that the MVP program is a real success.

    Read the article

  • Setting jQuery after ASP.net AJAX partial post back

    - by Steve Clements
    OK, so for some reason you have a mega mashup solution with ASP.net AJAX, jQuery and web forms.  Perhaps you are just on the migration from AjaxControlToolkit to the jQuery UI framework – who knows!! Anyway, the problem is that when you post back with something like an UpdatePanel, you will find that your nicely setup jQuery stuff, like the datepicker for example will no longer work. You may have something like this… $(document).ready(function () {     $(".date-edit").datepicker({ dateFormat: "dd/mm/yy", firstDay: 1, showOtherMonths: true, selectOtherMonths: true }); });   When you’re ASP.net UpdatePanel post back, you will find that your datepicker has gone.  Bugger! Well you need to add this little gem to set it back up again once the UpdatePanel comes back to the page. var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_endRequest(function () {     $(".date-edit").datepicker({ dateFormat: "dd/mm/yy", firstDay: 1, showOtherMonths: true, selectOtherMonths: true }); });   Or like me, you would have a javascript function, something like InitPage(); do all your work in there and call that on document.ready and endRequest. Your choice…you have the power   Share this post :

    Read the article

  • Silverlight ProgressBar issues with Binding

    - by Chris Skardon
    The ProgressBar pretty much does what it says on the tin, displays progress, in a bar form (well, by default anyhow). It’s pretty simple to use: <ProgressBar Minimum="0" Maximum="100" Value="50"/> Gives you a progress bar with 50% of it filled: Easy! But of course, we’re wanting to use binding to change the value, again, pretty easy, have a ViewModel with a ‘Value’ in it, and bind: <ProgressBar Minimum="0" Maximum="100" Value="{Binding Value}"/> Spiffy, and whilst we’re at it, why not bind the Maximum value as well – after all, we can’t be sure of the size of the progress, and it’s a pain to have to work out the percentage (when the progress bar can do it for us): <ProgressBar Minimum="0" Maximum="MaximumValue" Value="{Binding Value}"/> Right, this will work absolutely fine. Or will it??? On the face of it, it looks good, and testing it shows no issues, until at one point we go from: Maximum = 100; Value = 90; to Maximum=60; Value=50; On the face of it not unreasonable. The problem is more obvious if we look at the states of the properties after each set (initially Maximum is set at 1, Value = 0): Code Maximum Value Value < Maximum Maximum = 100; 100 0 True Value = 90; 100 90 True Maximum = 60; 60 90 False Value = 50; 60 50 True Everything is good until the Value is less than the Maximum, at this point the Progress Bar breaks. That’s right, it no longer updates itself, it will always look 100% full. The simple solution – always ensuring you set Value before Maximum is fine unless you’re using a ProgressBar in a less controlled environment – where for example you’re setting a ‘container’ with both values at the same time. The example I have is in a DataTemplate, I have a DataTemplate for a BusyIndicator, (specifically the BusyContentTemplate). The binding works this way: <BusyIndicator BusyContent="{Binding BusyContent}" BusyContentTemplate="{Binding ProgressTemplate}"/> With the template as the ProgressBar defined above… I was setting my BusyContent like this: BusyContent = content; aaaaaand finally, ‘content’ is a class: public class ContentClass : INotifyPropertyChanged { //Obviously this is properly implemented… public double Maximum { get;set;} public double Value { get;set;} } Soooo… As I was replacing the BusyContent wholesale, the order of the binding being set was outside of my control, so – how to go about it? Basically? Fudge it. Modify the ContentClass to include a method: public void Update(double value, double max) { Value = value; Maximum = max; } and change where the setting is to be: BusyContent.Update(content.Value, content.Maximum); Thereby getting the order correct.. Obvious really. Meh :|

    Read the article

  • HTML5 and Visual Studio 2010

    - by Harish Ranganathan
    All of us work with Visual Studio (or the free Visual Web Developer Express Edition) for developing web applications targeting ASP.NET / ASP.NET MVC or Silverlight etc.,  Over the years, Visual Studio has grown to a great extent.  From being a simple limited functionality tool in VS.NET 2002 to the multi-faceted, MEF driven Visual Studio 2010, it has come a long way.  And as much as Visual Studio supports rapid web development by generating HTML mark up, it also added intellisense for some of the HTML specifications that one has otherwise monotonously type every time.  Ex.- In Visual Studio 2010, one can just type the angular bracket “<” and then the first keyword “h” or “x” for html or xhtml respectively and then press tab twice and it would render the entire markup required for XHTML or HTML 1.0/1.1 strict/transitional and the fully qualified W3C URL. The same holds good for specifying HTML type declaration.  Now, the difference between HTML and XHTML has been discussed in detail already, though, if you are interested to know, you can read it from http://www.w3schools.com/xhtml/xhtml_html.asp But, the industry trend or the buzz around is HTML5.  With browsers like IE9 Beta, Google Chrome, Firefox 4 etc., supporting HTML5 standards big time, everyone wants to start developing HTML5 based websites. VS developers (like me) often get the question around when would VS start supporting HTML5.  VS 2010 was released last year and HTML5 is still specifications under development.  Clearly, with the timelines we started developing Visual Studio (way back in 2008), HTML5 specs were almost non-existent.  Even today, the HTML5 body recommends not to fully depend on the entire mark up set as they are still under development specs and might change in the future. However, with Visual Studio 2010 SP1 beta, there is quite a bit of support for HTML5 based web development.  In fact, one of my colleagues pointed out that SP1 beta’s major enhancement is its ability to support HTML5 tags and even add server mode to them. Lets look at the existing validation schema available in Visual Studio (Tools – Options – Validation) This is before installing Visual Studio 2010 SP1 Beta.  Clearly, the validation options are restricted to HTML 4.01 and XHTML 1.1 transitional and below. Also, lets consider using some of the new HTML5 input type elements.  (I found out this, just today from my friend, also an, ASP.NET team member) <input type=”email”> is one of the new input type elements according to the HTML5 specification.  Now, this works well if you type it as is  in Visual Studio and the page renders without any issue (since the default behaviour is, if there is an “undefined” type specified to input tag, it would fall back on the default mode, which is text. The moment you add <input type=”email” runat=”server” >, you get an error Naturally you don’t get intellisense support as well for these new tags.  Once you install Visual Studio 2010 Service Pack 1 Beta from here (it takes a while so you need to be patient for the installation to complete), you will start getting additional Validation templates for HTML5, as below:- Once you set this, you can start using HTML5 elements in your web page without getting errors/warnings.  Look at the screen shot below, for the new “video” tag which is showing up in intellisense (video is a part of the new HTML5 specifications)     note that, you still need to hook up the <!DOCTYPE html /> on the top manually as it doesn’t change automatically  (from the default XHTML 1.0 strict) when you create a new page. Also, the new input type tags in HTML5 are also supported One, can also use the <asp:TextBox type=”email” which would in turn generate the <input type=”email”> markup when the page is rendered.  In fact, as of SP1 beta, this is the only way to put the new input type tags with the runat=”server” attribute (otherwise you will get the parser error mentioned above.  This issue would be fixed by the final release of SP1 beta) Going further, there may be more support for having server tags for some of the common HTML5 elements, but this is work in progress currently. So, other than not having runat=”server” support for the new HTML5  input tags, you can pretty much build and target HTML5 websites with Visual Studio 2010 SP1 Beta, today.  For those who are running Visual Studio 2008, you also have the “HTML5 intellisense for Visual Studio 2010 and 2008” available for download, from http://visualstudiogallery.msdn.microsoft.com/d771cbc8-d60a-40b0-a1d8-f19fc393127d/ Note that, if you are running Visual Studio 2010, the recommended approach is to install the SP1 beta which would be the way forward for HTML5 support in Visual Studio. Of course, you need to test these on a browser supporting HTML5 such as IE9 Beta or Chrome or FireFox 4.  You can download IE9 Beta from here You can also follow the Visual Web Developer Team Blog for more updates on the stuff they are building. Cheers !!!

    Read the article

  • JavaScript Class Patterns

    - by Liam McLennan
    To write object-oriented programs we need objects, and likely lots of them. JavaScript makes it easy to create objects: var liam = { name: "Liam", age: Number.MAX_VALUE }; But JavaScript does not provide an easy way to create similar objects. Most object-oriented languages include the idea of a class, which is a template for creating objects of the same type. From one class many similar objects can be instantiated. Many patterns have been proposed to address the absence of a class concept in JavaScript. This post will compare and contrast the most significant of them. Simple Constructor Functions Classes may be missing but JavaScript does support special constructor functions. By prefixing a call to a constructor function with the ‘new’ keyword we can tell the JavaScript runtime that we want the function to behave like a constructor and instantiate a new object containing the members defined by that function. Within a constructor function the ‘this’ keyword references the new object being created -  so a basic constructor function might be: function Person(name, age) { this.name = name; this.age = age; this.toString = function() { return this.name + " is " + age + " years old."; }; } var john = new Person("John Galt", 50); console.log(john.toString()); Note that by convention the name of a constructor function is always written in Pascal Case (the first letter of each word is capital). This is to distinguish between constructor functions and other functions. It is important that constructor functions be called with the ‘new’ keyword and that not constructor functions are not. There are two problems with the pattern constructor function pattern shown above: It makes inheritance difficult The toString() function is redefined for each new object created by the Person constructor. This is sub-optimal because the function should be shared between all of the instances of the Person type. Constructor Functions with a Prototype JavaScript functions have a special property called prototype. When an object is created by calling a JavaScript constructor all of the properties of the constructor’s prototype become available to the new object. In this way many Person objects can be created that can access the same prototype. An improved version of the above example can be written: function Person(name, age) { this.name = name; this.age = age; } Person.prototype = { toString: function() { return this.name + " is " + this.age + " years old."; } }; var john = new Person("John Galt", 50); console.log(john.toString()); In this version a single instance of the toString() function will now be shared between all Person objects. Private Members The short version is: there aren’t any. If a variable is defined, with the var keyword, within the constructor function then its scope is that function. Other functions defined within the constructor function will be able to access the private variable, but anything defined outside the constructor (such as functions on the prototype property) won’t have access to the private variable. Any variables defined on the constructor are automatically public. Some people solve this problem by prefixing properties with an underscore and then not calling those properties by convention. function Person(name, age) { this.name = name; this.age = age; } Person.prototype = { _getName: function() { return this.name; }, toString: function() { return this._getName() + " is " + this.age + " years old."; } }; var john = new Person("John Galt", 50); console.log(john.toString()); Note that the _getName() function is only private by convention – it is in fact a public function. Functional Object Construction Because of the weirdness involved in using constructor functions some JavaScript developers prefer to eschew them completely. They theorize that it is better to work with JavaScript’s functional nature than to try and force it to behave like a traditional class-oriented language. When using the functional approach objects are created by returning them from a factory function. An excellent side effect of this pattern is that variables defined with the factory function are accessible to the new object (due to closure) but are inaccessible from anywhere else. The Person example implemented using the functional object construction pattern is: var personFactory = function(name, age) { var privateVar = 7; return { toString: function() { return name + " is " + age * privateVar / privateVar + " years old."; } }; }; var john2 = personFactory("John Lennon", 40); console.log(john2.toString()); Note that the ‘new’ keyword is not used for this pattern, and that the toString() function has access to the name, age and privateVar variables because of closure. This pattern can be extended to provide inheritance and, unlike the constructor function pattern, it supports private variables. However, when working with JavaScript code bases you will find that the constructor function is more common – probably because it is a better approximation of mainstream class oriented languages like C# and Java. Inheritance Both of the above patterns can support inheritance but for now, favour composition over inheritance. Summary When JavaScript code exceeds simple browser automation object orientation can provide a powerful paradigm for controlling complexity. Both of the patterns presented in this article work – the choice is a matter of style. Only one question still remains; who is John Galt?

    Read the article

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