This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import imp | |
import shutil | |
import pkgutil | |
import logging | |
from optparse import make_option | |
from django.core.management.base import BaseCommand, CommandError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using the trim method (trimLeft and trimRight methods also exist) | |
var txtBox = document.getElementById("test"); | |
var line = txtBox.value.split("\n"); | |
var resultString = ""; | |
for (var i=0; i < lines.length; i++) { | |
var strng = lines[i].trim(); | |
resultString += strng + "-"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get textarea string and split on new lines | |
var txtBox = document.getElementById("inputbox"); | |
var lines = txtBox.value.split("\n"); | |
// generate HTML version of text | |
var resultString = "<p>"; | |
for (var i = 0; i < lines.length ; i++) { | |
resultString += lines[i] + "<br />"; | |
} | |
resultString += "</p>"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// embedded into html tags <script type="text/javascript"></script> | |
window.onload = function() { | |
// get keyword list | |
var keywordList = prompt("Enter keywords, separated by commas",""); | |
// use split to create array of keywords | |
var arrayList = keywordList.split(","); | |
// build result HTML |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Use a combination of the typeof operator, the valueof method (shared by all objects) and the length property of String objects | |
// true if variable exists, is a string, and has a length greater than zero | |
if (( | |
(typeof unkownVariable != "undefined") | |
&& (typeof unknownVariable.valueOf() == "string") | |
&& (unknownVariable.length > 0) | |
)) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use the indexOf String method to locate start and end of substring to extract | |
// then extract the string with the substring String method | |
var sentence = "This is one sentence. Here comes the bit to copy: start .. end."; | |
var start = sentence.indexOf(":"); | |
var end = sentence.indexOf(".", start+1); // start searching at position start+1 to avoid first dot | |
var list = sentence.substring(start+1, end); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use the String object's built-in indexOf method to find the position of the substring if it exists: | |
var testValue = "This is Cookbook's test string"; | |
var subsValue = "Cookbook"; | |
var iValue = testValue.indexOf(subsValue, 5); | |
// returns index position of first character of substring, (would have returned -1 if not found) | |
// second parameter indicates index where search is to be started | |
//alternative |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use the equality operator (==) within a conditional test: | |
var strName = prompt("What's your name?", ""); | |
if (strName.toUpperCase () == "SHELLEY") { // case sensitive operator! | |
alert("Your name is Shelley! Good for you!"); | |
}else{ | |
alert("Your name isn't Shelley. Bummer."); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numValue = 23.45; | |
var total "And the total is " + numValue; // string has "And the total is 23.45" | |
// the javascript engine first converts the other data type's value into a string before concatenating |
NewerOlder