require 'initialized_by_hash' # copies a file, providing feedback on the progress of the operation. # # source: a path to the file that should be duplicated # destination: a path to the the new copy # report_rate: the number of times each second to report # # example: # fd = FileDuplication.new :source => ARGV[0], :destination => ARGV[1] # fd.begin do | bytes_done, bytes_left| # puts '%i %i' % [ bytes_done, bytes_left] # end # class FileDuplication attr_accessor :source, :destination, :report_rate initialized_by_hash private def fill_in_blanks @report_rate = 10 unless @report_rate end public # begins this file duplication operation, providing feedback to the default # block as the operation progresses. # def begin # check that both source and destination have been specified raise 'cannot copy from an unspecified source' unless @source raise 'cannot copy to unspecified destination' unless @destination begin source = File.open @source sink = File.open @destination, 'w' bytes_done = 0 bytes_left = File.size @source when_last_reported = Time.at 0 scrap = '' # report the commencement of the operation yield bytes_done, bytes_left # while there are still some bytes left to copy.. while 0 < bytes_left do # don't try to copy more bytes than are left to copy block_size = [ 10240, bytes_left].min # copy the bytes in the focus block source.sysread block_size, scrap sink.syswrite scrap bytes_done += block_size bytes_left -= block_size # if enough time has passed that another report should be made.. now = Time.now if when_last_reported + 1.0 / @report_rate <= now # report on progress yield bytes_done, bytes_left when_last_reported = now end end # report the completion of the operation yield bytes_done, bytes_left ensure sink.close if sink source.close if source end end end # --------------------------------------------------------------- 80 column rule
Tag Archive for copy
file_duplication
website copy protection
// this needs mootools framework and disable rightclick or better the contextmenu
document.addEvent('contextmenu',function(e){
e=new Event(e);
//alert('success');
e.stop();
});
function selectnone() {
document.body.ondrag = function () { return false; };
document.body.onselectstart = function () { return false; };
if(window.ie || window.opera){document.body.setProperty("unselectable","on");}
if(window.gecko){document.body.setStyle("MozUserSelect","none");}
if(window.webkit){document.body.setStyle("KhtmlUserSelect","none");}
}
// call selectnone() onload/domready
copy directory (unix)
cp -R /verzsource/ /target
File copy in ruby
require "ftools" File.copy(src,target)
Toggles instructional and default copy text and styles
/**
* Add instructional copy support for text fields and text area.
* The method will clear the copy, and swap styles.
*
* @param textField the text element that will be enhanced.
* @param copyClass class used for instructional copy
* @param noCopyClass class used for plain text
*/
function sl_addClearCopyListeners (textField, copyClass, noCopyClass){
// set default value in the object itself
textField.originalCopy = textField.value;
textField.copyClass = copyClass;
textField.noCopyClass = noCopyClass;
// add listiners
textField.onfocus = function(){
if (this.value == this.originalCopy){
this.value = '';
sl_replaceClass(this, this.copyClass, this.noCopyClass);
return false;
}
return true;
};
textField.onblur = function(){
if (this.value == ''){
sl_replaceClass(this, this.noCopyClass, this.copyClass);
this.value = this.originalCopy;
return false;
}
return true;
};
};
/**
* Replace a class with another, leaving other classes untouched.
* If the class does not exist, nothing will happen.
*
* @param domElement the text element that will be enhanced.
* @param oldClass class to replace
* @param newClass the replacement class
*/
function sl_replaceClass(domElement, oldClass, newClass){
var elementClass = '' + domElement.className;
// save some work, avoid flashing
if (elementClass.indexOf(oldClass) > -1){
elementClass = elementClass.replace(oldClass , newClass);
domElement.className = elementClass;
}
}
Category: Uncategorized |
Tags: area, copy, field, input, instructional, javascript, text, textarea, TextField
Clone Array
// set clone items function
function CLONE_ITEMS (itemsArray) {
// create temp items array
tempItems = new Array();
// loop through each object in items array
for (currentItem in itemsArray) {
// create new object for current item
tempItems[currentItem] = new Object();
// loop through current item
for (currentObject in itemsArray[currentItem]) {
//
tempItems[currentItem][currentObject] = itemsArray[currentItem][currentObject];
}
}
//
return tempItems;
}
clipboard commands for OSX
pbcopy < filename #copies contents of a text, rtf, or eps file to the clipboard pbpaste #pastes content of clipboard to stdout
rsync backup directory
rsync -a --delete /cygdrive/e/ /cygdrive/c/nsussman_thumb_drive
Category: Uncategorized |
Tags: backup, copy, cygwin, files, one-liners, productivity, rsync, security