Skip to content

Instantly share code, notes, and snippets.

@xxl007
xxl007 / Instructions.md
Last active November 22, 2022 21:01
IP camera appliance with Ubuntu on a Raspberry Pi 3
import os
import imp
import shutil
import pkgutil
import logging
from optparse import make_option
from django.core.management.base import BaseCommand, CommandError
@xxl007
xxl007 / 1.10.trimming_whitespace_from_the_ends_of_a_string.js
Last active August 29, 2015 14:00
Trimming Whitespace from the Ends of a String
// 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 + "-";
}
@xxl007
xxl007 / 1.9.processing_individual_lines_of_a_textarea.js
Last active August 29, 2015 14:00
Processing Individual Lines of a Textarea
// 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>";
@xxl007
xxl007 / 1.7.breaking_a_keyword_string_into_separate_keywords.js
Created April 20, 2014 20:10
Breaking a Keyword String into Separate Keywords
// 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
@xxl007
xxl007 / 1.6.checking_for_an_existing_non_empty_string.js
Created April 20, 2014 19:31
Checking for an Existing, Nonempty String
//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)
)) {
}
@xxl007
xxl007 / 1.5.extracting_a_substring_from_a_string.js
Created April 20, 2014 19:19
Extracting a Substring from a String
// 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);
@xxl007
xxl007 / 1.4.finding_a_substring_in_a_string.js
Created April 20, 2014 18:27
Finding a Substring in a String
// 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
@xxl007
xxl007 / 1.3.conditionally_comparing_strings.js
Created April 20, 2014 17:48
Conditionally Comparing Strings
// 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.");
}
@xxl007
xxl007 / 1.2.concatenating_a_string_and_another_data_type.js
Created April 20, 2014 17:32
Concatenating a String and Another Data Type
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