in-place

Replace entire HTML document in-place

≯℡__Kan透↙ 提交于 2019-11-28 01:02:12
I'm trying to avoid using a data URI because I do not want the generated document to be stored in the browser's history. Is it possible to replace the entire HTML document in-place? I tried jQuery("html").html("<html>....</html>") , but the style information does not survive. You probably want to do this: jQuery("body").html("new content"); ...where "new content" would ideally only include the markup that would normally appear within the body element and not the rest. That will replace the body element's contents, whilst leaving anything you have in head (like style sheet information) alone.

Need Perl inplace editing of files not on command line

馋奶兔 提交于 2019-11-27 23:26:00
问题 I have a program that has a number of filenames configured internally. The program edits a bunch of configuration files associated with a database account, and then changes the database password for the database account. The list of configuration files is associated with the name of the database account via an internal list. When I process these files, I have the following loop in my program: BEGIN { $^I = '.oldPW'; } # Enable in-place editing ... foreach (@{$Services{$request}{'files'}}) {

How can I convert tabs to spaces in every file of a directory?

。_饼干妹妹 提交于 2019-11-27 16:34:36
How can I convert tabs to spaces in every file of a directory (possibly recursively)? Also, is there a way of setting the number of spaces per tab? Martin Beckett Warning: This will break your repo. This will corrupt binary files , including those under svn , .git ! Read the comments before using! find . -type f -exec sed -i.orig 's/\t/ /g' {} + The original file is saved as [filename].orig . Downsides: Will replace tabs everywhere in a file. Will take a long time if you happen to have a 5GB SQL dump in this directory. Simple replacement with sed is okay but not the best possible solution. If

Stable separation for two classes of elements in an array

删除回忆录丶 提交于 2019-11-27 15:15:46
Consider the following problem. We are given an array of elements belonging to one two classes: either red or blue. We have to rearrange the elements of the array so that all blue elements come first (and all red elements follow). The rearrangement must be done is stable fashion, meaning that the relative order of blue elements must be preserved (same for red ones). Is there a clever algorithm that would perform the above rearrangement in-place? A non-in place solution is, of course, straightforward. An obvious in-place solution would be to apply any stable sorting algorithm to the array.

What is an in-place constructor in C++? [duplicate]

谁都会走 提交于 2019-11-27 13:36:54
Possible Duplicate: C++'s “placement new” What is an in-place constructor in C++? e.g. Datatype *x = new(y) Datatype(); This is called the placement new operator. It allows you to supply the memory the data will be allocated in without having the new operator allocate it. For example: Foo * f = new Foo(); The above will allocate memory for you. void * fm = malloc(sizeof(Foo)); Foo *f = new (fm) Foo(); The above will use the memory allocated by the call to malloc . new will not allocate any more. You are not, however, limited to classes. You can use a placement new operator for any type you

In-Place Radix Sort

故事扮演 提交于 2019-11-27 09:57:24
This is a long text. Please bear with me. Boiled down, the question is: Is there a workable in-place radix sort algorithm ? Preliminary I've got a huge number of small fixed-length strings that only use the letters “A”, “C”, “G” and “T” (yes, you've guessed it: DNA ) that I want to sort. At the moment, I use std::sort which uses introsort in all common implementations of the STL . This works quite well. However, I'm convinced that radix sort fits my problem set perfectly and should work much better in practice. Details I've tested this assumption with a very naive implementation and for

How to remove trailing whitespaces for multiple files?

谁都会走 提交于 2019-11-27 09:24:26
问题 Are there any tools / UNIX single liners which would remove trailing whitespaces for multiple files in-place . E.g. one that could be used in the conjunction with find . 回答1: You want sed --in-place 's/[[:space:]]\+$//' file That will delete all POSIX standard defined whitespace characters, including vertical tab and form feed. Also, it will only do a replacement if the trailing whitespace actually exists, unlike the other answers that use the zero or more matcher ( * ). --in-place is simply

Sort a part of a list in place

非 Y 不嫁゛ 提交于 2019-11-27 07:47:21
Let's say we have a list: a = [4, 8, 1, 7, 3, 0, 5, 2, 6, 9] Now, a.sort() will sort the list in place. What if we want to sort only a part of the list, still in place? In C++ we could write: int array = { 4, 8, 1, 7, 3, 0, 5, 2, 6, 9 }; int * ptr = array; std::sort( ptr + 1, ptr + 4 ); Is there a similar way in Python? fviktor I'd write it this way: a[i:j] = sorted(a[i:j]) It is not in-place sort either, but fast enough for relatively small segments. Please note, that Python copies only object references, so the speed penalty won't be that huge compared to a real in-place sort as one would

Move all odd positioned element to left half and even positioned to right half in-place

好久不见. 提交于 2019-11-27 07:01:36
Given an array with positive and negative integers, move all the odd indexed elements to the left and even indexed elements to the right. The difficult part of the problem is to do it in-place while maintaining the order. e.g. 7, 5, 6, 3, 8, 4, 2, 1 The output should be: 5, 3, 4, 1, 7, 6, 8, 2 If the order didn't matter, we could have been used partition() algorithm of quick sort. How to do it in O( N )? Get largest sub-array having size 3 k +1 Apply cycle leader algorithm to the parts of this sub-array, starting from positions 1, 3, 9, ... 3 k-1 : move element to its proper position in sub

In-place replacement of all occurrences of an element in a list in python [duplicate]

这一生的挚爱 提交于 2019-11-27 05:58:50
问题 This question already has an answer here: Replace values in list using Python [duplicate] 7 answers Assume I have a list: myl = [1, 2, 3, 4, 5, 4, 4, 4, 6] What is the most efficient and simplest pythonic way of in-place ( double emphasis ) replacement of all occurrences of 4 with 44 ? I'm also curious as to why there isn't a standard way of doing this (especially, when strings have a not-in-place replace method)? 回答1: We can iterate over the list with enumerate and replace the old value with