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, May 17, 2012

Fun with git

mkdir gittest
cd gittest
edit hello.txt
Hello, World!
exit
cat hello.txt
should be the same
git init
git add .
git commit -m "First commit!"
git branch update
git checkout update
cat hello.txt
should be the same
edit hello.txt
Hello, world!
Don't leave me!
save, exit
git add .
git commit -m "Update hello.txt 1"
Hmm. I don't like that. I've already committed!
git checkout HEAD~1 -- hello.txt
It's back!
edit hello.txt
Hello, world!
I love you!
save and exit
git commit -m "Love never dies"
git checkout master
cat hello.txt
It's gone?
git checkout update
cat hello.txt
It's back!
git log 
I need that entry n commits ago, but just for hello.txt
git checkout HEAD~n -- hello.txt

Thursday, May 3, 2012

Converted my cell to Google Voice

First, this is a Sprint phone that has been used to convert the voicemail to Google Voice, not the same *exact* thing as port-your-number, so if your experience differs, that may be why. Now, my experience. Current impression: Why the heck didn't I do this before? No, really. My phone calls can come in through Google Chat. I can send and receive text messages through email, chat, or Google Voice and know about them. Since I'm mostly working from home, I basically don't need to use my cell phone as much, and even if it's dead, I'm still able to send or receive phone calls *from my number* with a headset on my laptop, desktop ... basically any where. It's really an interesting issue for me because there are so many different ways to communicate I don't even need a cell phone for that it does make me seriously consider whether the smart phone is necessary for me. So far, so good, and it probably won't be worth switching back.

Monday, April 16, 2012

What's your preferred IDE?

Currently, still, it appears to be screen/byobu plus vim.

Probably I am missing all the niceties of something like netbeans, but here's how I set up a cakephp environment:

create a file that contains paths to sections...
---BEGIN FILE ---
cd /path/to/app/Controller
screen -t Controller
cd /path/to/app/Model
screen -t Model
cd /path/to/app/View
screen -t View
cd /path/to/app
screen -t app
cd /path/to/app/webroot/js
screen -t js
cd /path/to/app/webroot/css
screen -t css
cd /path/to/app/webroot/tmp/logs
screen -t logs
---END FILE ---

If you're using tmux instead of screen:
---BEGIN FILE---
cd /path/to/app/Controller
tmux new-window -n Controller
cd /path/to/app/Model
tmux new-window -n Model
cd /path/to/app/View
tmux new-window -n View
cd /path/to/app/
tmux new-window -n approot
cd /path/to/app/webroot/js
tmux new-window -n js
cd /path/to/app/webroot/css
tmux new-window -n css
cd /path/to/app/tmp/logs
tmux new-window -n log
---END FILE---


then simply source the file when you want create the screens for our application
To change between screens, the default mappings of ctrl-a, number will get you there.

I also use :split within vim to work on multiple documents within a given structure. I find this *generally* gives me a quick and easy way to handle the substructures I need and keeps me organized. The few other things most IDEs also have (like class trees and completion) I haven't yet had to use, but I figure I could also macro that as I need. On the logs screen, I can tail -f debug.log.

Tuesday, April 3, 2012

CakePHP helper to suggest input

What's it do?
makes it easier to make a gray suggest input box. Just use drop it as InputHelper.pm in View/Helper/ and call it where and how you need it. call it just like Form->input but add a sample text for the box.
$this->Input->input(fieldname, options array, 'sample text');

As an example, see what happens when you click in , click out, and change the content this box.




<?php App::uses('FormHelper', 'View/Helper');
/* helper to make default input help that disappears when clicked */
/* usage: $this--->Input-&gt;input */
class InputHelper extends FormHelper {
public function input($fieldname, $options=array(null), $fill) {
$options['class'] = ' dimmed';
$options['value'] = $fill;
$options['onClick'] = "if (this.value=='".$fill."') {this.value='';this.style.color='black'}";
$options['onBlur'] = "if (this.value=='') {this.value = '".$fill."'; this.style.color='gray'}";
$out = parent::input($fieldname, $options);
$out .= parent::hidden($fieldname . "_hidden", array('value' =&gt; $fill));
return $out;
}
}
?>

What's with the hidden? If you want to know what the original content was, you can test against this in your Controller to see if fieldname value is equal to fieldname_hidden value and don't store if it matches.

Friday, March 23, 2012

Apology

I made a post on another website and it went pretty bad.
It was a huge error in judgment, and all I have left that I can do is to post an apology.
I truly, deeply, honestly apologize for the post. It was all kinds of wrong, and indeed I made things worse trying to defend an indefensible position.

If such a thing can be in your heart to forgive, please do. If I could take it back, I would. But I realize it was wrong.

I'm sorry.

Blog Archive