Tag Archive for copy

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;
}
}

source

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;
}

source

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

source

rsync backup directory

rsync -a --delete /cygdrive/e/ /cygdrive/c/nsussman_thumb_drive

source

Summarize Web page bookmarklet

//url-escaped, ready for use:
javascript:function%20userSel()%7Bif%20(window.getSelection)%7Btxt%20=%20window.getSelection();%7Delse%20if%20(document.getSelection)%20%20%20%20%7Btxt%20=%20document.getSelection();%7Delse%20if%20(document.selection)%7Btxt%20=%20document.selection.createRange().text;%7Delse%20return;%20%20return%20txt;%7Dfunction%20add(h)%7Bb.appendChild(h);%7Dfunction%20makeTag(t)%7Breturn%20document.createElement(t);%7Dfunction%20makeText(tag,text)%7Bt=makeTag(tag);%20t.appendChild(document.createTextNode(text));%20return%20t;%7Dp=document.location;%20q=document.title.replace(/%5C[[%5E%5C]]*%5C](.*)%20-%20JAG%20JIRA/,%20'$1');%20d=window.open().document;%20d.open();%20d.close();%20b=d.body;%20d.title%20=%20q%20+%20'%20:%20summary%20:%20JIRA';%20u=p+'%5Cn'+q+'%5Cn'+userSel();%20add(makeText('style',%20'textarea%7Bwidth:100%;height:100%;%7D'));%20add(makeText('textarea',%20u));%20void%200

//unescaped, with line breaks
javascript: function userSel() {
if (window.getSelection) {
txt = window.getSelection();
} else if (document.getSelection) {
txt = document.getSelection();
} else if (document.selection) {
txt = document.selection.createRange().text;
} else return;
return txt;
}
function add(h) {
b.appendChild(h);
}
function makeTag(t) {
return document.createElement(t);
}
function makeText(tag, text) {
t = makeTag(tag);
t.appendChild(document.createTextNode(text));
return t;
}
p = document.location;
q = document.title.replace(/[[^]]*](.*) - JAG JIRA/, '$1');
d = window.open().document;
d.open();
d.close();
b = d.body;
d.title = q + ' : summary : JIRA';
u = p + '
' + q + '
' + userSel();
add(makeText('style', 'textarea{width:100%;height:100%;}'));
add(makeText('textarea', u));
void 0;

source

copy selected text

function getSelectedText(){
if (window.getSelection){
txt = window.getSelection();
}
else if (document.getSelection) {
txt = document.getSelection();
}
else if (document.selection){
txt = document.selection.createRange().text;
}
else return;
return txt;
}

source

Duplicate file

# so we can work with relative paths
cd "$TM_DIRECTORY"

# construct a default name for the duplicate
def_name=`perl -pe <<<"$TM_FILENAME" 's/^(.*?)(.[^.]*)?$/$1 copy$2/'`

# prompt user for a name
CocoaDialog inputbox --text "$def_name" --button1 "Duplicate" --button2 "Cancel"|{

# if user selected 'Duplicate' and file doesn't exist
read res; read new_name;
if [[ "$res" == "1" && ! -e "$new_name" ]]; then

# do the actual duplication
cp -p "$TM_FILENAME" "$new_name"

# force TM to refresh project drawer and open duplicate
{ osascript -e 'tell application "SystemEvents" to activate'
-e 'tell application "TextMate" to activate'

# open -a TextMate "$new_name";
} &>/dev/null &

fi
}

source

DOS copy directories with subdirectories

xcopy _adodb c:WAMPApache2.2_adodb /S

source