copy

Duplicating a Ruby array of strings

荒凉一梦 提交于 2019-12-03 19:56:12
问题 arr = ["red","green","yellow"] arr2 = arr.clone arr2[0].replace("blue") puts arr.inspect puts arr2.inspect produces: ["blue", "green", "yellow"] ["blue", "green", "yellow"] Is there anyway to do a deep copy of an array of strings, other than using Marshal as i understand that is a hack. I could do: arr2 = [] arr.each do |e| arr2 << e.clone end but it doesn't seem very elegant, or efficient. Thanks 回答1: Your second solution can be shortened to arr2 = arr.map do |e| e.dup end (unless you

CUDA coalesced access to global memory

折月煮酒 提交于 2019-12-03 18:38:08
问题 I have read CUDA programming guide, but i missed one thing. Let's say that i have array of 32bit int in global memory and i want to copy it to shared memory with coalesced access. Global array has indexes from 0 to 1024, and let's say i have 4 blocks each with 256 threads. __shared__ int sData[256]; When is coalesced access performed? 1. sData[threadIdx.x] = gData[threadIdx.x * blockIdx.x+gridDim.x*blockIdx.y]; Adresses in global memory are copied from 0 to 255, each by 32 threads in warp, so

Rails clone copy or duplicate

一世执手 提交于 2019-12-03 16:59:08
问题 I have a nested form and once I save, I want to be able to click a link on the show page to copy or clone that form and open a new one. From there I should be able to make edits (like a new id) and save as a new record. I have seen some examples like this deep_cloneable gem, but I have no idea how to implement it. I think this should be simple, but I just don't understand where to put things in the controller and in the show view. 回答1: If you want to copy an activeRecord object you can use

Android Emulator: How to Copy an Emulator / AVD?

好久不见. 提交于 2019-12-03 16:30:41
I am currently making an upgrade of an existing app that's already on the Google App store (aka Google Play). I want to test that the data conversions go smoothly when customers upgrade. I have an AVD with the old version of the app installed. The usual thing would be to run the new version on this app and see if it works. But the problem is that after doing this, that particular AVD is no longer mimicking that old state. I'd like to make copies of this AVD/Emulator (yeah, the whole thing!) so that I can make repeated tests. This seems like something that would happen often, but I can't find

Will addAll function in Java make a copy

主宰稳场 提交于 2019-12-03 16:05:15
问题 When list.addAll(list2) is called will objects in lists be copied to list? or just copy their references... did not find any explanation on javadoc... 回答1: No copy of the objects or their data are made; their references are simply added to the list object. 回答2: No, the objects will not be copied; references to the same objects will be added to the list. 回答3: In general, java will not copy objects when you "add all", that is, for objects, pointers to the originals are used. * But be careful !

How to get Grunt-Contrib-Copy to copy files/directories relative to given source path

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 15:28:24
问题 First time using this task and what I'm trying to achieve is the following: copy all directories/files from src/js/bower_components/* to build/assets/js/vendor/ I've tried using cwd property but it doesn't work at all when I use it.. I've set it to: src/js/bower_components/ From src . ├── Gruntfile └── src └── js └── bower_components └── jquery I currently get: . ├── Gruntfile └── build └── assets └── js └── vendor src └── js └── bower_components └── jquery What I'd like . ├── Gruntfile └──

Can I make the Ant copy task OS-specific?

故事扮演 提交于 2019-12-03 15:14:32
问题 I have an Ant script that performs a copy operation using the 'copy' task. It was written for Windows, and has a hardcoded C:\ path as the 'todir' argument. I see the 'exec' task has an OS argument, is there a similar way to branch a copy based on OS? 回答1: I would recommend putting the path in a property, then setting the property conditionally based on the current OS. <condition property="foo.path" value="C:\Foo\Dir"> <os family="windows"/> </condition> <condition property="foo.path" value="

How to copy bits from one variable to another?

邮差的信 提交于 2019-12-03 15:13:37
Let's say I have this int variable v1 : 1100 1010 And this variable int v2 : 1001 1110 I need to copy the last four bits from v2 to the last four bits of v1 so that the result is: 1100 1110 ^ ^ last four bits of v2 | | first four bits of v1 How would I got about doing this in C or C++? I read a few articles about bitwise operations but I couldn't find any information specifically about this. Bitwise operations were the right things to look for. v1 = (v1 & ~0xf) | (v2 & 0xf); Is there something specific you didn't understand from the articles you read? How about v1 = (v1 & 0xf0) | (v2 & 0xf);

Copying one FlowDocument to Second FlowDocument

醉酒当歌 提交于 2019-12-03 14:46:52
How can i copy the contents of one FlowDocument to another FlowDocument below is what i tryed foreach (var blk in fd1.Blocks) { fd2.Blocks.Add(blk); } fd1 is FlowDocument1 and fd2 is FlowDocument2. But i get the below error. Collection was modified; enumeration operation may not execute. Thanks Arvind Arvind Because each Block is 'owned' by a FlowDocument, it cannot just be added to another. You must serialize it and then deserialize it, which breaks the bond with the original FlowDocument, which allows you to add it to another. /// <summary> /// Adds one flowdocument to another. /// </summary

Copying text of textarea in clipboard when button is clicked

☆樱花仙子☆ 提交于 2019-12-03 14:43:08
问题 I'm looking to create a jQuery (or javascript) button that selects everything in a textarea and then copies the text to your clipboard when you clicked on button. I have found some examples using the focus event. But I'm looking for a button that you actually have to click for the select and copy. How can i do this work? 回答1: You need to use select() to selecting text of textarea and use execCommand('copy') to coping selected text. Its work in upper version of browsers. $("button").click