sure, you know about s/foo/bar/ which replaces bar where foo exists.
Let's say you want to find foo but only when it comes before bar, and you want to replace some but not all of it.
s/\(foo\)bar/\1goo/
Will replace foobar with foogoo
will keep foodoo as is.
You can use this to, for instance, insert something before a comma:
s/\([a-z]\),/\1 = 0,/
foo, is now foo = 0,
or insert something between foo and bar
s/\(foo\)\(bar\)/\1 nutty \2/
changes foobar to foo nutty bar
Thursday, December 20, 2012
Saturday, December 1, 2012
Windows update error 80070005 quick resolution
If you've been infected by malware that "hides everything", don't forget to unhide the folders under c:\windows\SoftwareDistribution\
open an administrative level command prompt and type this:
cd \windows\SoftwareDistribution
attrib -r -s -h /s /d *.*
if you want to open the firehose (somewhat) safely, you might try this from c:\windows:
attrib -r -h /s /d *.*
You won't be able to unhide system files, but you will unhide everything that you otherwise have access to.
(Be very certain you're in the SoftwareDistribution folder prior to runnning the attrib command line, otherwise you just unhid/unreadonly/unsystem the entire folder you're in.)
This should quickly fix the WindowsUpdate_80070005 error and allow you to download Windows Updates as well as Microsoft Security Essentials updates if you're encountering 0x80070005 error.
There's no warranty about whether you try this stuff. It may make things work, but you should at least consider whether you're comfortable with this.
open an administrative level command prompt and type this:
cd \windows\SoftwareDistribution
attrib -r -s -h /s /d *.*
if you want to open the firehose (somewhat) safely, you might try this from c:\windows:
attrib -r -h /s /d *.*
You won't be able to unhide system files, but you will unhide everything that you otherwise have access to.
(Be very certain you're in the SoftwareDistribution folder prior to runnning the attrib command line, otherwise you just unhid/unreadonly/unsystem the entire folder you're in.)
This should quickly fix the WindowsUpdate_80070005 error and allow you to download Windows Updates as well as Microsoft Security Essentials updates if you're encountering 0x80070005 error.
There's no warranty about whether you try this stuff. It may make things work, but you should at least consider whether you're comfortable with this.
Thursday, November 15, 2012
Windows 7 NAS Shares can't connect
Thanks to this post, I implemented a GPO that disabled the requirements of Microsoft signatures for network shares and the NAS (LaCIE, et al) I couldn't see from Windows 7 x64bit now could be seen (after reboot of workstation).
Monday, November 5, 2012
mysql cheat to check is number
Is that value a number or a string?
select cast("2apple" AS UNSIGNED), cast("3 bananas" AS UNSIGNED), cast(0+ "4 cars" AS UNSIGNED), cast("100" AS UNSIGNED), cast("BAR" AS UNSIGNED), "5 bears" regexp "[A-Za-z]", "6" regexp "[A-Za-z]"
Returns:
2, 3, 4, 100, 0, 1, 0
Summary: Best way to check if the value is (only) a number is to check if it doesn't contain letters (assuming that letters are adequate for this detection. If you're expecting symbols but no letters, you'll need to test for the symbols).But, if you want to get the "Value" of the string (numbers before letters), CAST it as unsigned.If you know there will *never* be numbers before characters, you can use the CAST and test if greater than zero.
select cast("2apple" AS UNSIGNED), cast("3 bananas" AS UNSIGNED), cast(0+ "4 cars" AS UNSIGNED), cast("100" AS UNSIGNED), cast("BAR" AS UNSIGNED), "5 bears" regexp "[A-Za-z]", "6" regexp "[A-Za-z]"
Returns:
2, 3, 4, 100, 0, 1, 0
Summary: Best way to check if the value is (only) a number is to check if it doesn't contain letters (assuming that letters are adequate for this detection. If you're expecting symbols but no letters, you'll need to test for the symbols).But, if you want to get the "Value" of the string (numbers before letters), CAST it as unsigned.If you know there will *never* be numbers before characters, you can use the CAST and test if greater than zero.
Thursday, November 1, 2012
Linux log files various ways to log
let's say the application has a log output:
Overwrite:
wget -o logfilename.ext ...
Append:
wget -a logfilename.ext ...
Overwrite with a date log:
wget -o logfilename_`date +%Y-%m-%d`.ext ...
This gives you a daily log output.
Output goes to stdout:
Overwrite:
echo "something" > logfile
Append: (creates if not exist)
echo "something" >> logfile
Daily log:
echo "something" >> logfile_`date +%Y-%m-%d`
Output (errors) goes to stderr
include with your standard log:
echo "something" > logfile 2>&1
Overwrite:
wget -o logfilename.ext ...
Append:
wget -a logfilename.ext ...
Overwrite with a date log:
wget -o logfilename_`date +%Y-%m-%d`.ext ...
This gives you a daily log output.
Output goes to stdout:
Overwrite:
echo "something" > logfile
Append: (creates if not exist)
echo "something" >> logfile
Daily log:
echo "something" >> logfile_`date +%Y-%m-%d`
Output (errors) goes to stderr
include with your standard log:
echo "something" > logfile 2>&1
Sunday, October 28, 2012
Javascript table red if negative
"How do I make a table show red in a cell if negative?"
There are likely a few things to watch out for (a minus in a text name or something like that.)
There are likely a few things to watch out for (a minus in a text name or something like that.)
//quick cheat red if negative.
var table = document.getElementById("my_table");
for (var j=0, row; row=table.rows[j]; j++) {
for (var i=0, cell; cell= row.cells[i]; i++) {
if (cell.innerText.indexOf("-")>-1) {
cell.style.color="red";
}
}
}
var table = document.getElementById("my_table");
for (var j=0, row; row=table.rows[j]; j++) {
for (var i=0, cell; cell= row.cells[i]; i++) {
if (cell.innerText.indexOf("-")>-1) {
cell.style.color="red";
}
}
}
Thursday, September 20, 2012
How do I add a value to a PHP array without a key?
$myarray = array(
'key1' => 'value',
'another value'
)
OK, so that works, but sometimes you just want to use bracket notation to add 'another value' entry without disturbing the array or including a key.
$myarray[]='another another value';
This adds a (hidden) key to the value. If you aren't using numbers in your index, it is likely that the hidden key might be zero. If not, it may be max integer key +1. You can't necessarily rely on the key number being consistent, but at least it's how to add a stand-alone value to an array without including a key.
'key1' => 'value',
'another value'
)
OK, so that works, but sometimes you just want to use bracket notation to add 'another value' entry without disturbing the array or including a key.
$myarray[]='another another value';
This adds a (hidden) key to the value. If you aren't using numbers in your index, it is likely that the hidden key might be zero. If not, it may be max integer key +1. You can't necessarily rely on the key number being consistent, but at least it's how to add a stand-alone value to an array without including a key.
Subscribe to:
Posts (Atom)