Daily Archives

Articles indexed Wednesday May 26 2010

Page 23/118 | < Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >

  • How can I refactor this JavaScript code to avoid making functions in a loop?

    - by Bungle
    I wrote the following code for a project that I'm working on: var clicky_tracking = [ ['related-searches', 'Related Searches'], ['related-stories', 'Related Stories'], ['more-videos', 'More Videos'], ['web-headlines', 'Publication'] ]; for (var x = 0, length_x = clicky_tracking.length; x < length_x; x++) { links = document.getElementById(clicky_tracking[x][0]) .getElementsByTagName('a'); for (var y = 0, length_y = links.length; y < length_y; y++) { links[y].onclick = (function(name, url) { return function() { clicky.log(url, name, 'outbound'); }; }(clicky_tracking[x][1], links[y].href)); } } What I'm trying to do is: define a two-dimensional array, with each instance the inner arrays containing two elements: an id attribute value (e.g., "related-searches") and a corresponding description (e.g., "Related Searches"); for each of the inner arrays, find the element in the document with the corresponding id attribute, and then gather a collection of all <a> elements (hyperlinks) within it; loop through that collection and attach an onclick handler to each hyperlink, which should call clicky.log, passing in as parameters the description that corresponds to the id (e.g., "Related Searches" for the id "related-searches") and the value of the href attribute for the <a> element that was clicked. Hopefully that wasn't thoroughly confusing! The code may be more self-explanatory than that. I believe that what I've implemented here is a closure, but JSLint complains: http://img.skitch.com/20100526-k1trfr6tpj64iamm8r4jf5rbru.png So, my questions are: How can I refactor this code to make JSLint agreeable? Or, better yet, is there a best-practices way to do this that I'm missing, regardless of what JSLint thinks? Should I rely on event delegation instead? That is, attaching onclick event handlers to the document elements with the id attributes in my arrays, and then looking at event.target? I've done that once before and understand the theory, but I'm very hazy on the details, and would appreciate some guidance on what that would look like - assuming this is a viable approach. Thanks very much for any help!

    Read the article

  • Get home directory in Linux, C++

    - by Alex Farber
    I need a way to get user home directory in C++ program running on Linux. If the same code works on Unix, it would be nice. I don't want to use HOME environment value. AFAIK, root home directory is /root. Is it OK to create some files/folders in this directory, in the case my program is running by root user?

    Read the article

  • Erlang Mnesia Equivalent of SQL Select FROM WHERE Field IN (value1, value2, value3, ...)

    - by ErJab
    I have an mnesia table with fields say f1, f2, f3. Now if I were to select all the rows with the field value as V1, I would use mnesia:select and match specifications or a simple mnesia:match_object. Now I need to select all the rows which have V1, V2, V3 ... or Vn (a list of arbitrary length) as the value for field f1. In SQL I would do something like SELECT * FROM tablename WHERE f3 IN (V1, V2, V3, ... , Vn) How do I do this in mnesia?

    Read the article

  • C# / Visual Studio: production and test code placement

    - by Patrick Linskey
    Hi, In JavaLand, I'm used to creating projects that contain both production and test code. I like this practice because it simplifies testing of internal code without artificially exposing the internals in a project's published API. So far, in my experiences with C# / Visual Studio / ReSharper / NUnit, I've created separate projects (i.e., separate DLLs) for production and test code. Is this the idiom, or am I off base? If this idiomatically correct, what's the right way to deal with exposing classes and methods for test purposes? Thanks, -Patrick

    Read the article

  • Binary Search Tree for specific intent

    - by Luís Guilherme
    We all know there are plenty of self-balancing binary search trees (BST), being the most famous the Red-Black and the AVL. It might be useful to take a look at AA-trees and scapegoat trees too. I want to do deletions insertions and searches, like any other BST. However, it will be common to delete all values in a given range, or deleting whole subtrees. So: I want to insert, search, remove values in O(log n) (balanced tree). I would like to delete a subtree, keeping the whole tree balanced, in O(log n) (worst-case or amortized) It might be useful to delete several values in a row, before balancing the tree I will most often insert 2 values at once, however this is not a rule (just a tip in case there is a tree data structure that takes this into account) Is there a variant of AVL or RB that helps me on this? Scapegoat-trees look more like this, but would also need some changes, anyone who has got experience on them can share some thougts? More precisely, which balancing procedure and/or removal procedure would help me keep this actions time-efficient?

    Read the article

  • Lucene.net create+lock errors in ASP.NET

    - by acidzombie24
    I have an issue with Lucene.net. It throws a lock exception. After poking around i notice these things. My code below works in an app bit when calling in Application_Start i get a NoSuchDirectoryException. Not closing the writer (as my code doesnt do below) i WILL get a LockObtainFailedException with the message Lock obtain timed out: SimpleFSLock@<FULL_PATH> from either app or asp.net These thread hinted when spawning threads they get less permissions then i do (but! my main thread has problems as well...) and one solution is to impersonate IIS. I am using visual studios 2010. I am not sure how full blown it is but my attempt to impersonate it failed. So my question is how do i have lucene create the directory and not throw an exception if dont close the writer for some reason (such as power going out)? http://stackoverflow.com/questions/2341163/why-is-my-lucene-index-getting-locked/2499285#2499285 http://stackoverflow.com/questions/1123517/lucene-net-and-i-o-threading-issue/1123981#1123981 static IndexWriter writer = null; static void lucene_init() { bool create = false; string dirname = "LuceneIndex_z"; if (System.IO.Directory.Exists(dirname) == false) create = true; var directory = FSDirectory.GetDirectory(dirname); var analyzer = new StandardAnalyzer(); writer = new IndexWriter(directory, analyzer, create); }

    Read the article

  • Flex - Tab View Multiple DataGrids and same dataProvider

    - by user283403
    I have a flex application in which I have a TabNavigator with multiple tabs and a datagrid in each of those tabs. I have bound s single array of data to each grid. What I want to do is to bind each grid with a particular set of data in that array i.e. to distribute array contents among grids based on data type. For example items starting with letter A could be displayed in first grid, B in second, starting with C in third and so on. Hence you can say alphabetically distribute the data on different grids. The problem is that the data will be added randomly by the user. To make one data array for each grid is not an option (due to design restrictions). Any suggestions please? Thanks in advance

    Read the article

  • CSS: What is the proper way to deal with multiple classes of Text

    - by DavidR
    So I'm on commission for a website, and I'm trying to improve my code. When dealing with a website with multiple types of font (here it's large, there it's small, there it's bold, here it's underlined, etc.) is this where we use the h1-h6, or do we reserve those for times when there is a definite hierarchy, using instead <p class="xxx"> to define different classes for text?

    Read the article

  • L'informaticien, artisan des temps modernes ou le développement est-il plus proche d'un processus in

    L'informaticien, artisan des temps modernes ? Non, le processus complet est plus proche d'un processus industriel Salut, Je viens de lire à l'instant un billet sur l'informatique et un parallèle avec l'artisanat. C'est un sujet qui revient souvent. Peut-on comparer notre métier avec la pratique de l'artisanat ? Personnellement je ne le pense pas, notre métier peut couvrir un large spectre, du technicien spécialisé à l'expert dans son domaine mais en aucun cas je ne le comparerai à de l'artisanat. En fait je compare l'évolution des pratiques de création logicielles à...

    Read the article

  • Raw Materials - Performance Metrics

    Derek adds some bells and whistles to the system. Too many SQL Servers to keep up with?Download a free trial of SQL Response to monitor your SQL Servers in just one intuitive interface."The monitoringin SQL Response is excellent." Mike Towery.

    Read the article

  • Why I don’t need to go on the SQLCruise

    - by Jonathan Kehayias
    Brent Ozar ( Blog | Twitter ) and Tim Ford ( Blog | Twitter ) are putting on a new type of event in the month of August after SQL Saturday #40 in South Florida July, 31st , properly named SQLCruise . The concept is great, at least in my opinion, you pay for a cruise, get to have a break, and at the same time attend a mini-conference on SQL Server with training provided by two great speakers. The cost is relatively affordable, so what could possibly make it better? How about a sponsor offering up...(read more)

    Read the article

  • JQuery validation with default input.

    - by Anthony
    I am using this technique to place default input in the text fields as a hint to users. http://www.dailycoding.com/Posts/default_text_fields_using_simple_jquery_trick.aspx I would like to also validate the fields using jquery validate. How can i get the validater to ignore the default input?

    Read the article

  • Storing SQL queries in Table in sql server

    - by Rohit
    We have multiple jobs in our system.These jobs are listed in a grid. We have 3 different user types (usertypeid 1,2,3). For each user listing is different and he can filter listing by selecting view from a dropdown. ViewName in the below table is the view which needs to be displayed. To achieve this functionality, a fellow developer has created the following table structure and stored sql fragments in SQLExpression in the below table. According to me the query should not be stored in database. What are the pros and cons of this approach and what are the available alternatives? JobListingViewID ViewName SQLExpression UserTypeID 3 All Jobs 1 = 1 3 4 Error Jobs JobStatusID IN ( 2 ) 1 5 Error Jobs JobStatusID IN ( 2 ) 2 6 Error Jobs JobStatusID IN ( 2 ) 3 7 Speech JobStatusID IN ( 1, 3, 8 ) 1

    Read the article

  • an better way to do this code

    - by user295189
    myarray[] = $my[$addintomtarray] //52 elements for ($k=0; $k <= 12; $k++){ echo $myarray[$k].' '; } echo ''; for ($k=13; $k < 26; $k++){ echo $myarray[$k].' '; } echo ''; for ($k=26; $k < 39; $k++){ echo $myarray[$k].' '; } echo ''; for ($k=39; $k <= 51; $k++){ echo $myarray[$k].' '; } how to shorten this array code...all I am doing here is splitting an array of 52 elements into 4 chunck of 13 elements each. In addition I am adding formation with br and space thanks

    Read the article

  • ( Sql Server 2005 C#.Net ) - I want just the insert query for a temp table.

    - by John Stephen
    Hi..I am using C#.Net and Sql Server ( Windows Application ). I had created a temporary table. When a button is clicked, temporary table (#tmp_emp_details) is created. I am having another button called "insert Values" and also 5 textboxes. The values that are entered in the textbox are used and whenever com.ExecuteNonQuery(); line comes, it throws an error message called "Invalid object name '#tbl_emp_answer'.". Below is the set of code..Please give me a solution. Code for insert (in insert value button): private void btninsertvalues_Click(object sender, EventArgs e) { username = txtusername.Text; examloginid = txtexamloginid.Text; question = txtquestion.Text; answer = txtanswer.Text; useranswer = txtanswer.Text; SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=tempdb;Integrated Security=True;"); SqlCommand com = new SqlCommand("Insert into #tbl_emp_answer values('"+username+"','"+examloginid+"','"+question+"','"+answer+"','"+useranswer+"')", con); con.Open(); com.ExecuteNonQuery(); con.Close(); }

    Read the article

  • Don't show Data in DataGrid

    - by mSafdel
    Hi in my app, I used WCF Services for load data from SQL DB then in Completed Event Handler of my ServiceClient write this code: void svc_GetOrdersCompleted(object sender, GetOrdersCompletedEventArgs e) { if (e.Error == null) { dgOrders.ItemsSource = e.Result; txtStatus.Text = ""; } else txtStatus.Text = "Error occured while loading orders from database"; } dgOrders is my DataGrid and And AutoGenerateColumns set to True. in line 5: eResult have a number of Order objects but after this code DataGrid can't show data. Why? this ia my xaml for dgOrders: <data:DataGrid x:Name="dgOrders" Grid.Row="0" Grid.Column="1" AutoGenerateColumns="True" SelectionChanged="dgOrders_SelectionChanged" Foreground="Green"> </data:DataGrid> this is my Source code please guide me.

    Read the article

  • Switch/Case statements in C++

    - by vgoklani
    Regarding the switch/case statement in the C++ code below: "Case 1" is obviously false, so how/why does it enter the do-while loop? #include <iostream> using namespace std; int main() { int test = 4; switch(test) { case 1: do { case 2: test++; case 3: test++; case 4: cout << "How did I get inside the do-while loop?" << endl; break; case 5: test++; } while(test > 0); cout << test << endl; } }

    Read the article

  • Global variable not stable after platform changed.

    - by user350555
    Our embedded system is built on a hw/sw platform made by enea. After the platform updated recently, we found some operations on the global variable keep crashing the system. For example, we have a global map structure holding some data. We can insert/iterate the map once or twice, then the address of the elements in the map suddenly changed to some forbidden addresses like 0x0 or 0x1d, the system just crash. The only different before/after the platform update is : 1) sw part: It's a c++ software and We changed the compiler from diab cc to gcc. 2) hw part: we have a new board, but the cpu is still powerpc405s. I tried every possible way but still can't figure out the reason. Any thoughts?

    Read the article

  • iPhone developer cert not associating with Provisioning Profiles

    - by baudot
    I'm seeing the dreaded "Code Sign error: The identity 'iPhone Developer' doesn't match any valid certificate/private key pair in the default keychain" error. Strange, as it used to work. Not sure what changed. A few of the symptoms I've noticed beyond this: In the project info, for Code Signing Identity, instead of saying "iPhone Developer: My Name Here", it only says "iPhone Developer", followed by a list of grayed out Provisioning Profiles with the error message "profile doesn't match any valid certificate/private key pair in the keychain." In the organizer, if I click the "Developer Profile" sidebar entry, it shows one entry in the "Identities" pane, "iPhone Distribution: My Name Here". However, no profiles show in the Provisioning Profiles pane. In the organizer, if I click the "Provisioning Profiles" sidebar entry, for each of the profiles there it reports "A valid signing identity matching this profile could not be found in your keychain." I've tried a handful of the usual folk cures for this ailment, without success so far, such as: Cleared my old keypairs and expired developer identity cert out of the keychain. Deleted my old developer profile, created a new one, and regenerated the provisioning profile after. Reconfirmed: The App ID on the provisioning portal for this app is a pure wildcard ID. (The "Bundle Identifier" in the info.plist is just the appname, no reversed domain prefix.) Restored my iPhone. Overstalled the latest version of Xcode.

    Read the article

< Previous Page | 19 20 21 22 23 24 25 26 27 28 29 30  | Next Page >