Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Wednesday, June 27, 2012

Check All Check None Javascript

A checkall/check none javascript implementation that doesn't care about ASP.

You ready?


  • Check all
  • Check me!
  • Check me, too!
  • Check this third box.
<script type="text/javascript">
function checkall(id,value) {
   var form = document.getElementById(id);
   for (var n=0; n< form.length; n++)
     if (form.elements[n].type == 'checkbox')
        form.elements[n].checked = value;
  return false;
}
</script>
<form id="myForm">
<ul>
<li><input type="checkbox" onclick="checkall('myForm', this.checked)">Check all</li>
<li><input type="checkbox">Check me!</li>
<li><input type="checkbox">Check me, too!</li>
<li><input type="checkbox">Check this third box.</li>
</ul>
</form>
Code markup via quickhighlighter.com

Tuesday, June 26, 2012

Pass a previous value in a select box

Renamed: Set a default select option when normal default is blank.
Let's say you want to do an event on a select onclick ... maybe something like a select with a blank as default, but if it's clicked, you want to change it to some other default (today's month?) ... but you also want that original blank to be selectable to "erase" the entry. This does not require jQuery or ASP. No need for a library to do this. Use it how you want.



    <script type="text/javascript">
        function setDefault(el) {
            if (el.previousValue != "") {
                return;
            }
            if (el.value) {
                return;
            }
            if (el.value == "") {
                el.value = "choose me"
            }
        }
    </script>
    <select onclick="setDefault(this)" onfocus="this.previousValue=this.value">
        <option value=""></option>
        <option value="skip me">skip me</option>
        <option value="choose me">choose me</option>
    </select>
Code marked up with quickhighlighter.com

Thursday, September 18, 2008

Excel Fix a Phone list

Occasionally, you'll have a list of phone numbers that need a little fixing. This code fixes many things as long as the last 8 digits are like 555-1212 and there's three digits of area code either preceded by "(" or flush left as in "(555)555-1212" or "555-555-1212". The result will always be formatted as (555) 555-1212, unless an area code is given.

A2 represents where the broken number is stored.


=CONCATENATE("(",IF(LEN(A2)<9,"555",IF(LEFT(A2,1)="(",MID(A2,2,3),LEFT(A2,3))),") ",RIGHT(A2,8))


You should change 555 to your local area code.

Monday, July 14, 2008

ASSP Tweak: Filename in maillog.txt

This is a simple change to ASSP (assp.pl) that places the filename of the email in the maillog.txt
First, find and change the following -- it's around line 2578 in 1.1.0 or 8046 in the latest release, inside sub Maillog. The bold lines were added. You'll need to restart ASSP to see this take effect.

Now you know exactly which file pertains to your email and you don't have to grep for it in /spam or /notspam

$Con{$fh}->{maillogfh}=$FH;
$Con{$fh}->{mailloglength}=0;
binmode $FH;
# logging filenames
mlog($fh, "'$fn'");

Wednesday, April 2, 2008

awk before and after

This is attempt number one for my friend who wanted awk based before-and-after.

It's not very interactive, and needs some command line features. The point, I guess, is that you could use this in conjunction with my colorize awk function to have context sensitive searching of words in a way that less can be useful. ETA: Oh, yeah, the point was to add "before" context to tail-f filename | grep "search" , similar to how grep does it on static files. In this case, it's more of tail -f filename | awk -f thisfile.awk, and you could also pipe that through my awk colorizer for the double whammy: context (before and after search) plus color.


BEGIN {
numlinesbefore = 3
numlinesafter = 3
needle = "search"
aftercount = -1
head = ""
tail = ""
}
{
before[numlinesbefore] = $0
for (i = 0; i < numlinesbefore; i++) {

before[i] = before[i+1]
}

if ($0 ~ needle) {
for (i = 0; i < numlinesbefore-1; i++) {
head = head "\n" before[i]
}
aftercount = numlinesafter + 1
tail = ""
print head
}
if (aftercount >= 0) {
print $0
--aftercount
}

if (aftercount == 0 ) {
head = ""
tail = ""
print "---"
aftercount = -1
}
}


Of course,this is an awk program.

awk colorizer for tail.

One of the problems I have with tail -f maillog.txt | grep "search" is that I really did want to watch the noise and not just the signal. Except that I'd like to notice the signal. Here's my printcolor.awk Now I can use tail -f maillog.txt | awk -f printcolor.awk and see the whole tail, with keywords highlighted in *different* colors.

NOTE: ^[ is supposed to be Ctrl-v, Escape; NOT caret, left bracket.


function colorize(word, color)
{
c["red"] = "^[[1;31;40m"
c["green"] = "^[[1;32;40m"
c["yellow"] = "^[[1;33;40m"
c["blue"] = "^[[1;34;40m"
c["magenta"] = "^[[1;35;40m"
if (line ~ word)
{ split (line, a, word)
line=a[1] c[color] (word) "^[[0;37;40m" a[2]
}
}
{line = $0
colorize("whitelist","green")
colorize("Bayesian Spam","red")
print line
}



ETA: If you'd like to be annoyed/beeped at for something that you're looking for, you can add ctrl-v, ctrl-g in the right hand side, eg: "^G^[[1;32;40m" (not caret G)

Blog Archive