Daily Archives

Articles indexed Monday April 19 2010

Page 7/113 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • Parsing and replacing Javascript identifiers with Rhino in Java

    - by Parhs
    Suppose I let the user to write a condition using Javascript, the user can write conditions to perform a test and return true or false. E.g.: INS>5 || ASTO.valueBetween(10,210) I want to find which variables are used in the script that the user wrote. I tried to find a way to get the identifier names in Java. The Rhino library didn't help a lot. However I found that via handling exceptions I could get all the identifiers. So this problem is solved. So everything is great, but there is one little problem. How can I replace these identifiers with a numeric identifier? E.g. INS should be _234 and ASTO should be _331. INS and ASTO etc are entities in my database. I want to replace them, because the name may change. I could do it using a replace but this isn't easy because: It should be reversible. E.g. ASTO to _234 and _234 to ASTO again. Replacing _23 with MPLAH may also replace _234. This could be fixed with regexp somehow. What if _23 is in a comment section? Rare to happen, but possible /* _23 fdsafd ktl */. It should also be replaced. What if it is a name of a function? E.g. _32() {}. Also rare, but it shouldn't be replaced. What if it is enclosed in "" or ''? I am sure that there are a lot more cases. Any ideas?

    Read the article

  • Where Not In OR Except simulation of SQL in LINQ to Objects

    - by Thinking
    Suppose I have two lists that holds the list of source file names and destination file names respectively. The Sourcefilenamelist has files as 1.txt, 2.txt,3.txt, 4.txt while the Destinaitonlist has 1.txt,2.txt. I ned to write a linq query to find out which files are in SourceList that are absent in DestinationFile list. e.g. here the out put will be 3.txt and 4.txt. I have done this by a foreach statement. but now I want to do the same by using LINQ(C#). Edit: My Code is List<FileList> sourceFileNames = new List<FileList>(); sourceFileNames.Add(new FileList { fileNames = "1.txt" }); sourceFileNames.Add(new FileList { fileNames = "2.txt" }); sourceFileNames.Add(new FileList { fileNames = "3.txt" }); sourceFileNames.Add(new FileList { fileNames = "4.txt" }); List<FileList> destinationFileNames = new List<FileList>(); destinationFileNames.Add(new FileList { fileNames = "1.txt" }); destinationFileNames.Add(new FileList { fileNames = "2.txt" }); IEnumerable<FileList> except = sourceFileNames.Except(destinationFileNames); And Filelist is a simple class with only one property fileNames of type string.

    Read the article

  • deleted deleted deleted deleted

    - by Robert
    deleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleteddeleted deleted deleted deleted

    Read the article

  • serializing JSON files with newlines in Python

    - by user248237
    I am using json and jsonpickle sometimes to serialize objects to files, using the following function: def json_serialize(obj, filename, use_jsonpickle=True): f = open(filename, 'w') if use_jsonpickle: import jsonpickle json_obj = jsonpickle.encode(obj) f.write(json_obj) else: simplejson.dump(obj, f) f.close() The problem is that if I serialize a dictionary for example, using "json_serialize(mydict, myfilename)" then the entire serialization gets put on one line. This means that I can't grep the file for entries to be inspected by hand, like I would a CSV file. Is there a way to make it so each element of an object (e.g. each entry in a dict, or each element in a list) is placed on a separate line in the JSON output file? thanks.

    Read the article

  • 3D Screensaver interfering with WPF application (Windows XP)

    - by Andrew Keith
    I have a fairly large application that uses WPF for its user interface. I recently found an unusual defect regarding 3D screensavers. The 3D screensavers 3D FlowerBox,3D Flying Objects,3D Pipes,3D Text causes 1 of my WPF windows to disappear when the screensaver activates. Other screensavers are fine. My application only encounters this problem on Windows XP. I have some experience with DirectX. When a 3D screensavers activates, the d3d device context will be switched to exclusive mode. I reckon that WPF has trouble restoring the device context when the device switches back to cooperative mode (hence why its only affecting windows XP) Has anyone seen such a scenario occur before ? Is there a remedy for the problem ? Windows XP SP3, DirectX 9.0c, .NET 3.5

    Read the article

  • Is it possible to sendkeys / Post Message directly to a HtmlElement rather than to a C# webbrowser

    - by Jakub
    I would like to send keys to a c# web browser control element directly, not just the window with the correct focus. Right now I am able to send a key using PostMessage and documentHandle and focus like this i.e. Pseudo Code HtmlElement el = getelement(); el.Focus(); IntPtr docptr = browser.Handle; PostMessage(docptr,WM_KEYDOWN,1,0); .... KEYCHAR, KEYUP.. I was wondering if anyone knows of any way to be able to do this in a background, so that the focus is not on the element. Basically is there a way to get a IntPtr to the HtmlElement itself, than use that instead in the PostMessage or SendKeys API rather than the browser handle/ptr.

    Read the article

  • OpenMP - running things in parallel and some in sequence within them

    - by Sayan Ghosh
    Hi, I have a scenario like: for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { for (k = 0; k < x; k++) { val = 2*i + j + 4*k if (val != 0) { for(t = 0; t < l; t++) { someFunction((i + t) + someFunction(j + t) + k*t) } } } } } Considering this is block A, Now I have two more similar blocks in my code. I want to put them in parallel, so I used OpenMP pragmas. However I am not able to parallelize it, because I am a tad confused that which variables would be shared and private in this case. If the function call in the inner loop was an operation like sum += x, then I could have added a reduction clause. In general, how would one approach parallelizing a code using OpenMP, when we there is a nested for loop, and then another inner for loop doing the main operation. I tried declaring a parallel region, and then simply putting pragma fors before the blocks, but definitely I am missing a point there! Thanks, Sayan

    Read the article

  • UITableViewCells appear behind backgroundView

    - by Khanzor
    I am having a problem setting the background of UITableView to a UIImageView (see below for why I am doing this), once the view is set, it works fine, and scrolls with the UITableView, but it hides the elements of the Table View. I need to have a UIImageView as the background for a UITableView. I know this has been answered before, but the answers are to use: [UIColor colorWithPatternImage:[UIImage imageNamed:@"myImage.png"]]; Or something like (which I need to use): UIImageView *background = [MainWindow generateBackgroundWithFrame:tableView.bounds]; [tableView addSubview:background]; [tableView sendSubviewToBack:background]; The reason I need to use the latter is because of my generateBackgroundWithFrame method, which takes a large image, and draws a border around that image to the dimensions specified, and clips the remainder of the image: + (UIImageView *) generateBackgroundWithFrame: (CGRect)frame { UIImageView *background = [[[UIImageView alloc] initWithFrame:frame] autorelease]; background.image = [UIImage imageNamed:@"globalBackground.png"]; [background.layer setMasksToBounds:YES]; [background.layer setCornerRadius:10.0]; [background.layer setBorderColor:[[UIColor grayColor] CGColor]]; [background.layer setBorderWidth:3.0]; return background; } Please note: I understand that this might poorly effect performance, but I don't have the resources to go through and make those images for each potential screen in the app. Please do not answer this question with a mindless "you shouldn't do this" response. I am aware that it is possibly the wrong thing to do. How do I show my UITableView control elements? Is there something that I am doing wrong in my delegate? Here is a simplified version: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(20, 20, 261, 45) reuseIdentifier:CellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; UIImage *rowBackground; NSString *imageName = @"standAloneTVButton.png"; rowBackground = [UIImage imageNamed:imageName]; UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 5, 300, 200)]; textView.backgroundColor = [UIColor clearColor]; textView.textColor = [UIColor blackColor]; textView.font = [UIFont fontWithName:@"Helvetica" size:18.0f]; Purchase *purchase = [[PurchaseModel productsPurchased] objectAtIndex:indexPath.row]; textView.text = [purchase Title]; selectedTextView.text = textView.text; UIImageView *normalBackground = [[[UIImageView alloc] init] autorelease]; normalBackground.image = rowBackground; [normalBackground insertSubview:textView atIndex:0]; cell.backgroundView = normalBackground; [textView release]; } return cell; }

    Read the article

  • Using s/// in an expression

    - by mikeY
    I got a headache looking for this: How do you use s/// in an expression as opposed to an assignment. To clarify what I mean, I'm looking for a perl equivalent of python's re.sub(...) when used in the following context: newstring = re.sub('ab', 'cd', oldstring) The only way I know how to do this in perl so far is: $oldstring =~ s/ab/cd/; $newstring = $oldstring; Note the extra assignment.

    Read the article

  • Construct a LPCWSTR on WinCE in C++ (Zune/ZDK)

    - by James Cadd
    What's a good way to construct an LPCWSTR on WinCE 6? I'd like to find something similar to String.Format() in C#. My attempt is: OSVERSIONINFO vi; memset (&vi, 0, sizeof vi); vi.dwOSVersionInfoSize = sizeof vi; GetVersionEx (&vi); char buffer[50]; int n = sprintf(buffer, "The OS version is: %d.%d", vi.dwMajorVersion, vi.dwMinorVersion); ZDKSystem_ShowMessageBox(buffer, MESSAGEBOX_TYPE_OK); That ZDKSystem_ShowMessageBox refers to the ZDK for hacked Zunes available at: http://zunedevwiki.org This line of code works well with the message box call: ZDKSystem_ShowMessageBox(L"Hello Zune", MESSAGEBOX_TYPE_OK); My basic goal is to look at the exact version of WinCE running on a Zune HD to see which features are available (i.e. is it R2 or earlier?). Also I haven't seen any tags for the ZDK so please edit if something is more fitting!

    Read the article

  • Office Web Components compatibility issues

    - by Sebastian
    Hello, I'm doing some research on the convenience of using Office Web Components on a web to show pivot tables and graphics and I have a question regarding this. Does the use of these components will turn my web app (at least for this feature) into a "Internet Explorer only" app Thanks in advance!

    Read the article

  • Strategy game programming in Java, how the map and unit classes should work/relate each other.

    - by Gabriel A. Zorrilla
    As a way of learning Java i'm doing a little strategy game. You have a game map and military units. The gamemap and the units are Jpanels which are binded together in another class called GameWindow, which has a JLayeredPane where the gamepap is below the units. Every time i click a unit (and therefore, the JPane) I can get the unit's information. The problem comes when i want to move a unit... each unit is self drawn inside it's Jpanel, how do i represent the change in position over the gamemap? I'm thinking about reloading the whole game window based on a position change of a unit (because the JPAnels that represent the units are created in the GameWindow, not drawn in the gamemap). Another more elegant option, should be repainting the whole map, with the units. But that way the units would lose it's status of objects (no more JPAnels, just being drawn in the gamemap paint() method), and how would i tell if one unit is clicked? I dont know how people with more experience in games handle the class structure in strategy games. I believe i have the right structure (map, game units, each one an object) but I'm having difficulties making it work together. Here is a snapshot of the map with a couple of units:

    Read the article

  • How to detect Javascript pop-up notifications in WatiN?

    - by Ian P
    I have a, what seems to be, rather common scenario I'm trying to work through. I have a site that accepts input through two different text fields. If the input is malformed or invalid, I receive a Javascript pop-up notification. I will not always receive one, but I should in the event of (like I said earlier) malformed data, or when a search result couldn't be found. How can I detect this in WatiN? A quick Google search produced results that show how to click through them, but I'm curious as to whether or not I can detect when I get one? In case anyone is wondering, I'm using WatiN to do some screen scraping for me, rather than integration testing :) Thanks in advance! Ian

    Read the article

  • How do I set a time in a time_select view helper?

    - by brad
    I have a time_select in which I am trying to set a time value as follows; <%= f.time_select :start_time, :value => (@invoice.start_time ? @invoice.start_time : Time.now) %> This always produces a time selector with the current time rather than the value for @invoice.start_time. @invoice.start_time is in fact a datetime object but this is passed to the time selector just fine if I use <%= f.time_select :start_time %> I guess what I'm really asking is how to use the :value option with the time_select helper. Attempts like the following don't seem to produce the desired result; <%= f.time_select :start_time, :value => (Time.now + 2.hours) %> <%= f.time_select :start_time, :value => "14:30" %>

    Read the article

  • Given an array of integers [x0 x1 x2], how do you calculate all possible permutations from [0 0 0] t

    - by user319951
    I am writing a program that takes in an ArrayList and I need to calculate all possible permutations starting with a list of zeroes, up to the value in the corresponding input list. Does anyone know how to iteratively calculate these values? For example, given [ 1 2 ] as input, it should find and store the following lists: [0 0], [1 0], [1 1], [1 2], [0 1], [0 2] Thanks!

    Read the article

  • QT vs. Net - REAL comparisons for R.A.D. projects

    - by Pirate for Profit
    Man in all these Qt vs. .NET discussions 90% these people argue about the dumbest crap. Trying to get a real comparison chart here, because I know a little about both frameworks but I don't know everything. I believe Qt and .NET both have strengths and weaknesses. This is to make a comparison that highlights these so people can make more informed decisions before embarking on a project, in the spirit of R.A.D. Event Handling In Qt the event handling system is very simple. You just emit signals when something cool happens and then catch them in slots. ie. // run some calculations, then emit valueChanged(30, false, 20.2); and then catching it, any object can make a slot to recieve that message easily void MyObj::valueChanged(int percent, bool ok, float timeRemaining). It's easy to "block" an event or "disconnect" when needed, and works seamlessly across threads... once you get the hang of it, it just seems a lot more natural and intuitive than the way the .NET event handling is set up (you know, void valueChanged(object sender, CustomEventArgs e). And I'm not just talking about syntax, because in the end the .NET anonymous delegates are the bomb. I'm also talking about in more than just reflection (because, yes, .NET obviously has much stronger reflection capabilities). I'm talking about in the way the system feels to a human being. Qt wins hands down for the simplest yet still flexible event handling system ever i m o. Plugins and such I do love some of the ease of C# compared to C++, as well as .NET's assembly architecture, even though it leads to a bunch of .dll's (there's ways to combine everything into a single exe though). That is a big bonus for modular projects, which are a PITA to import stuff in C++ as far as RAD is concerned. Database Ease of Doing Crap Also what about datasets and database manipulations. I think .net wins here but I'm not sure. Threading/Conccurency How do you guys think of the threading? In .NET, all I've ever done is make like a list of master worker threads with locks. I like QConcurrentFramework, you don't worry about locks or anything, and with the ease of the signal slot system across threads it's nice to get notified about the progress of things. QConcurrent is the simplest threading mechanism I've ever played with. Memory Usage Also what do you think of the overall memory usage comparison. Is the .NET garbage collector pretty on the ball and quick compared to the instantaneous nature of native memory management? Or does it just let programs leak up a storm and lag the computer then clean it up when it's about to really lag? Doesn't the just-in-time compiler make native code that is pretty good, like and that only happens the first time the program is run? However, I am a n00b who doesn't know what I'm talking about, please school me on the subject.

    Read the article

  • Make Map Key Sorted According To Insert Sequence

    - by Yan Cheng CHEOK
    Without help from additional container (like vector), is it possible that I can make map's key sorted same sequence as insertion sequence? #include <map> #include <iostream> using namespace std; int main() { map<const char*, int> m; m["c"] = 2; m["b"] = 2; m["a"] = 2; m["d"] = 2; for (map<const char*, int>::iterator begin = m.begin(); begin != m.end(); begin++) { // How can I get the loop sequence same as my insert sequence. // c, b, a, d std::cout << begin->first << std::endl; } getchar(); }

    Read the article

  • What scenarios are possible where the VS C# compiler would not compile a reference of a reference?

    - by SuperKing
    Hello, I'm probably asking this question wrong (and that may be why Google isn't helping), but here goes: In Visual Studio I am compiling a C# project (let's call it Project A, the startup project) which has a reference to Project B. Project B has a reference to a Project C, so when A gets built, the dlls for B gets placed in the bin directory of A, as does the dll for C (because B requires C, and A requires B). However, I have apparently made some change recently so that the dll for Project C does not go into the bin directory of Project A when rebuilding the solution. I have no idea what I've done to make this happen. I have not modified the setup of the solution itself, and I have only added additional references to the project files. Code wise, I have commented out most of the actual code in Project B that references classes in Project C, but did not remove the reference from the project itself (I don't think this matters). I was told that perhaps the C# compiler was optimizing somehow so that it was not building Project C, but really I'm out of ideas. I would think someone has run into something similar before Any thoughts? Thanks!

    Read the article

  • Problem with filling dataset

    - by Brian
    This is a small portion of my code file. Each time my debugger reaches the line 'NewDA.Fill(NewDS);' at runtime it jumps to the catch. I'm positive the daynumber variable gets a value that's present in the database and I've tried the query outside of the codefile on my database and it works fine. I'm also using the connectionstring 'db' on more parts of the code with successful results. string QueryNew = "SELECT activityname AS [Name], activitycategorynumber AS [Category] " + "FROM ACTIVITY WHERE daynumber = @daynumber"; SqlCommand NewCmd = new SqlCommand(QueryNew, db); NewCmd.Parameters.Add("@daynumber", SqlDbType.Int).Value = daynumber; SqlDataAdapter NewDA = new SqlDataAdapter(NewCmd); DataSet NewDS = new DataSet(); NewDA.Fill(NewDS);

    Read the article

  • global scope of variable

    - by shantanuo
    The following shell scrip will check the disk space and change the variable "diskfull" to 1 if the usage is more than 10% The last echo always shows 0 I tried the global diskfull=1 in the if clause but it did not work. How do I change the variable to 1 if the disk consumed is more than 10% #!/bin/sh diskfull=0 ALERT=10 df -HP | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output; do #echo $output usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 ) partition=$(echo $output | awk '{ print $2 }' ) if [ $usep -ge $ALERT ]; then diskfull=1 exit fi done echo $diskfull

    Read the article

  • DataGrid finding a control

    - by nat
    HI I have a DataGrid (yes would be nicer if it was a gridview but nothing i can do about that) in the itemDataBound event i am adding a hidden field into the first cell of each row I am setting its ID based on something, and then saving its clientID in a List for later attempts to get the value from it but try as i might i cant find anything with findcontrol have tried here is the itemdatabound bit foreach(page in datasource){ HiddenField hidOrder = new HiddenField(); hidOrder.ID = "order_" + page.Id.ToString(); hidOrder.Value = page.Ordering.ToString(); e.Item.Cells[0].Controls.Add(hidOrder); idList.Add(hidOrder.ClientID); } then this is a button click event.. int numRows = FrontEndDataGrid.Items.Count; for (int i = 0; i < numRows; i++){ foreach(string hidID in idList){ HiddenField hf = FrontEndDataGrid.Items[i].FindControl(hidID) as HiddenField; //ssadly this never finds anything //have also tried looping around the cells for each 'row' - no luck there either } } any ideas? thanks nat

    Read the article

  • How to check if user submit Arabic words from a form?

    - by ronanray
    Hi Experts.. Is there any reliable way to check if user has entered Arabic words into a form and tries to submit it? Can Javascript handle this? Or, only server script like .NET can do this? I'm thinking that if possible the script should directly prevent the user from inputting Arabic words into the form and show an alert pop up. Please share any examples if you have any idea how to do it. Thanks

    Read the article

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