KOWTS #3


"To live with no regrets is to live happily."

Generate Random Quotes from a Text File

So to do that, you need a text file full of quotes. HAHAHA
Separated by new line.

$('#btn_modal').click(function () {
    var num = 0;
    $.ajax({
        url: "https://dl.dropboxusercontent.com/u/75734877/taglines.txt",
        type: "GET",
        dataType: "text",
        beforeSend: function () {
            $('#kowts').show().html('<img src="http://www.feelol.com/Content/images/Loading.gif" />');
        },
        success: function (t) {
            var lines = t;
            var lineArr = lines.split('\n');
            num = Math.floor(Math.random() * lineArr.length);
            $('#kowts').show().text(lineArr[num]);
        },
        error: function(){
            alert('Error')
        }
    });
});

Split the quotes from text file by "\n" (new line), then get its length and generate a random number between 0 to maximum length. Then use the generated number as index to get the quote on that particular line. Display it in your HTML element.

<button id="btn_modal">Give me a Quote</button>
<p id="kowts"></p>

#kowts {
    display:none;
    font-weight:bold
}

BTW, the text file that I used is not mine, got from somewhere else I forgot the link. (:

Kowts #2



This song keeps me awake during office hours. :)

Using Bootstrap Multiselect Values in Django Query


Read the documentation of Bootstrap Multiselect . Anyway, just include all the files in you html page (head section), you will need these following files (JS and CSS files):

  1. //ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js
  2. http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css
  3. http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js
  4. https://dl.dropboxusercontent.com/u/75734877/bootstrap-multiselect.css
  5. https://dl.dropboxusercontent.com/u/75734877/bootstrap-multiselect.js
Copy and save the files if you want to serve it with your own, and use it like this in your template:
<script type="text/javascript" src="{% static "js/bootstrap-multiselect.js" %}"></script>
Then refer to this JSFiddle for demo. 

Let's say you have this select element in your page with the id, "bldg_type"

<select class="form-control" id="bldg_type" multiple="multiple">
    <option value="Bank">Bank</option>
    <option value="Barangay Hall">Barangay Hall</option>
    <option value="Cemetery">Cemetery</option>
    <option value="Factory">Factory</option>
    <option value="Fire Station">Fire Station</option>
    <option value="Gas Station">Gas Station</option>
    <option value="Market">Market</option>
    <option value="Medical Institutions">Medical Institutions</option>
    <option value="Other Commercial Establishments">Other Commercial Establishments</option>
    <option value="Other Government Offices">Other Government Offices</option>
    <option value="Police Station">Police Station</option>
    <option value="Religious Institutions">Religious Institutions</option>
    <option value="School">School</option>
    <option value="Sport Center/Gymnasium/Covered Court">Sport Center/Gymnasium/Covered Court</option>
    <option value="Telecommunication Facilities">Telecommunication Facilities</option>
    <option value="Transport Terminal">Transport Terminal</option>
</select>

OnDOMReady, initialize the plug-in like this:

$("#bldg_type").multiselect({
    buttonWidth: "200px"
});

In my case I used those values for my query, this is how I get all the selected values in the function:

    function r(e) {
        var t = $("#bldg_type option:selected"),
            r = [];
        return t.each(function () {
            r.push($(this).val())
        }), $.ajax({
            url: "cnt_bldg/",
            type: "GET",
            dataType: "JSON",
            data: {
                brgy_id: e,
                bldg_type: r,
                munisipyo: $("#munisipyo").val()
            }
       ...

And in your views.py, you can get those value with this:
get_bldg_type = request.GET.getlist('bldg_type[]', default='All')
Here's a sample query I made:

if get_bldg_type != 'All':  
     args.append(Q(bldg_type__in=get_bldg_type))

Kowts #1


I have nothing to say here..HAHA :3

All You Have To Do...

...is savor the moment. I think just this time, I'll stop being so pessimistic of the things that is not yet happening.
I'm happier now, not because of a TV show or an episode of an anime series but because of a GIRL .
I described  her as a cute human being like a puppy or kitten. I love her smile, I love seeing her smile. I love her eyes and the rest of her face (like Tim to Mary). HAHA

It's awkward seeing myself  of being this much happy. (grammar eh?!!) LOL
I can't even stop smiling while listening to the song above.

Tim: We're all traveling through time together, every day of our lives. All we can do is do our best to relish this remarkable ride.
I think, I'll just be "Tim" for a while. It helps. :D

Typeahead Implementation in PHP/MySQL

DEMO
First, you need to include all the necessary files for this to work. Place these three files in the head section of your page..

  • jquery-1.10.2.min.js 
  • bootstrap.min.js
  • bootstrap3-typeahead.min.js

Then, this script:

$(document).ready(function () {
    var objects = [];
    var map = {};
    $('#person').typeahead({
        source: function (query, process) {
            $.ajax({
                url: 'get_person.php',
                type: 'POST',
                dataType: 'JSON',
                async: true,
                success: function (data) {
                    objects = []; //resets the objects 
                    map = {}; //to avoid duplication
                    $.each(data, function (i, object) {
                        map[object.full_name] = object;
                        objects.push(object.full_name);
                    });
                    process(objects);
                }
            });
        }, //end source
        updater: function (item) {
            $('#first_name').val(map[item].fname);
            $('#middle_name').val(map[item].mname);
            $('#last_name').val(map[item].lname);
            return item;
        }
    }); //end of person typeahead
    $('#person').focus(function () {
        $(this).val('');
    });
});

This is my PHP code in which it passes a JSON object to my index.php file.


header('Content-Type: application/json');
 require_once('connection.php');
 $i=0;
 $query = mysqli_query($GLOBALS["___mysqli_ston"], "select userid,title,first_name, middle_name, last_name from tblperson;");
 $array = array();
 while($row = mysqli_fetch_array($query))
 {
     $i++;
     $userid = $row['userid'];
  $title = $row['title'];
  $fname = $row['first_name'];
  $mname = substr($row['middle_name'],0,1);
  $lname = $row['last_name'];
  $data[$i]['userid'] = $userid;
  $data[$i]['fname'] = $fname;
  $data[$i]['mname'] = $mname;
  $data[$i]['lname'] = $lname;
  $data[$i]['full_name'] = $title.$fname." ".$mname."."." ".$lname;
 }
 echo json_encode($data);

Just click the DEMO link above then copy the JavaScript source.

ASDFJKL;


Everytime you tell girls you like them, they always asked "Why?". And I always go with the reason, "I just like you". And then, end of conversation.

Oh girl, I'm sorry. If you can only dissect my body and see what I felt about you. You'll be spending lots of hours reading all my reasons. Because sometimes with my limited source of words and vocabulary, I can't find the exact word. So, maybe you can?

"That feeling between like and love."
Hmmmn, getting there?
Nah, I'm not fond of words.

It's just sad that women love words. I know that you need to spit it out sometimes. Unfortunately, I'm not good in speaking. I haven't confess personally, like expressing my feeling like it's the end of the world. I haven't done that. And I don't have plan doing it except in my wedding vow.

When I tell you I like you , it's always true.
And it means I like every details about you. The soul within your body and all the words; the good and bad that may came out on your mouth.

You see me as a childish and immature person in my age. Oh girl, I've been through a lot. I've experienced the most painful thing already. So, I can always deal with opinions and criticisms. It wouldn't matter if you're not important to me but you are. So, I'll take it and make myself better. Well, of course not for you but for my self-growth.

I'm a happy person but love sad songs. You have to see people in their loneliest moment for you to deeply understand them. It's not enough to be good to them, you have to lift their spirit as much as possible. In this physical world that we live in, I don't strive for greatness. I work hard to be happy. But be happy with valid and righteous reasons. I define happiness as the absence of bitterness from the pain you have suffered. By thinking that you are more than enough and incomparable with others. By recognizing and accepting your imperfections because someday you will find someone that will fill those holes up and will embrace all your flaws. So, don't worry about love. Afterall, it's FREE.

Accept the things you can't change.
Have the courage to change the things you can.
And have the wisdom to know the difference.

It's a quote from Barry Allen's mom but I also heard it from social meetings of alcoholics, addicts, etc. Don't ever beg for love. Because, a love that is formed out of pity will break easily. So, don't ever do that. There is always someone out there who secretly loves you. (and then she smiles because she loves me. HAHAHAHA)

A perfect partner should always brings out the best in you. Who will help you grow in all aspect. Sometimes I wonder why those girls that I dearly liked doesn't like me? And I have this in my mind:

"Ok, it opens up an opportunity for other girls." HAHAHA

I just love girls who smile a lot. (and then she smiles again. HAHAHAHA)

Why are you really reading this? This is just a random thought because my mind loves to fly when I sleep early. So, instead of sending it in air, I decided to write it down. :)

And the song for this babble:

...now she's gone!

I just told her I like her, and now she's gone(not gone, gone). Am I that powerful? hahaha


Well, I am not that proud of myself but I'm always fine with it. Like really, as much as I want her. I just don't beg. It's not my style and I don't even know how to please/court a girl. Which makes me wonder, how did I get a girlfriend before? :)

Anyway, 2015 is coming! I have these list; a new year's resolution:

  • I'll try to go to church as often as possible.
  • Maybe be more mature in interacting with people esp. girls. HAHA
  • Mind OVER Emotion thing. I overthink a lot.
  • I'll work harder. I want to finish my Master's Degree as soon as possible to get married. HAHA
  • I'll sleep early like 10:00 PM.
  • Live healthy? Less caffeine and more water.
I guess that's it! I am happy with my life right now. What more can I ask for? Ahh there's one thing, I want to learn Nihongo. I got plans, you know? haha

My Sweet...Moon!


When this song hits me, I listen to it all over and over again. It's a bit sad but inspiring. I really love kids, like dreaming of having one right now. But I also have this in my mind that I'm not yet capable of giving her(I want a girl BTW) a very beautiful life.
I love the man you're making me
Yeah, every day I'm gonna prove there's nothing I won't do for you
Such a great love for his child.
OK, I should take up guitar lesson now 'cause I'm gonna write a song for my future Naleigh Moon.