Posts

Showing posts from June, 2015

javascript select opt group from son sample

As shown in http://jsfiddle.net/DVKMK/3/ and http://stackoverflow.com/questions/13956667/create-html-select-with-optgroup-from-json

<div id="somewhere"></div>

var json = [{"Foo":[{"id":1,"name":"aaa"},{"id":2,"name":"bbb"}]},{"Bar":[{"id":3,"name":"ccc"},{"id":4,"name":"ddd"}]}];

var $select = $("<select>");
$.each(json, function(i, optgroups) {

    $select.appendTo("#somewhere");

    $.each(optgroups, function(groupName, options) {
        var $optgroup = $("<optgroup>", {label: groupName});
        $optgroup.appendTo($select);

        $.each(options, function(j, option) {
            var $option = $("<option>", {text: option.name, value: option.id});
            $option.appendTo($optgroup);
        });
    });
});


Solved : ERROR: type "geometry" does not exist

ERROR:  type "geometry" does not exist 

I fixed this error by running following code in SQL editor of your selected database in pgAdmin.

CREATE EXTENSION postgis;




Comments are welcomed!. Cheers!! ;)

svn working copy locked.

Image
Just to remember if your svn working copy locked, do the following steps to resolve.

1. Open your project
2. Right click on the project
3. Choose Subversion -> Working Copy -> Cleanup.

Problem solved.
These steps work on NetBean IDE.

Create custom sequence for PostgreSQL Primary Key with auto-increment.

Image
You can use standard sequence and formatting functions to customise the value.
to_char(nextval('test_seq'), 'TS0000000FM')  FM : prefix fill mode (suppress padding blanks and trailing zeroes)

CREATE SEQUENCE test_seq;
CREATE TABLE test_table
(
 s_no CHAR(8) NOT NULL DEFAULT to_char(nextval('test_seq'), 'TS0000000FM'),
 txt TEXT
);
ALTER SEQUENCE test_seq OWNED BY test_table.s_no; 
You can read more on this example and about postgresql formatting functions in following links.

sources : 
http://www.quora.com/How-do-I-create-a-custom-sequence-for-a-PostgreSQL-primary-key-e-g-A0000001
http://www.postgresql.org/docs/9.4/static/functions-formatting.html

Display name of the month from the current date using javascript

Image
This code is to display name of the month from the current date.
<p id="demo"></p>
<script>
function myFunction() {
    var month = new Array();
    month[0] = "January";
    month[1] = "February";
    month[2] = "March";
    month[3] = "April";
    month[4] = "May";
    month[5] = "June";
    month[6] = "July";
    month[7] = "August";
    month[8] = "September";
    month[9] = "October";
    month[10] = "November";
    month[11] = "December";
    var d = new Date();
    var n = month[d.getMonth()];
    document.getElementById("demo").innerHTML = n;
}
</script> source : http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_date_getmonth
  pic screenshot from : http://s345014333.onlinehome.us/LoganGreer/wordpress/

JQuery 12/24 hours Clock

Image
HTML
<span id="clock"></span>
javascript
function updateClock() {
    var currentTime = new Date();
    var currentHoursAP = currentTime.getHours();
    var currentHours = currentTime.getHours();
    var currentMinutes = currentTime.getMinutes();
    var currentSeconds = currentTime.getSeconds();

    // Pad the minutes and seconds with leading zeros, if required
    currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
    currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;

    // Choose either "AM" or "PM" as appropriate
    var timeOfDay = (currentHours < 12) ? "AM" : "PM";

    // Convert the hours component to 12-hour format if needed
    currentHoursAP = (currentHours > 12) ? currentHours - 12 : currentHours;

    // Convert an hours component of "0" to "12"
    currentHoursAP = (currentHoursAP == 0) ? 12 : currentHoursA…

Committing PostgreSQL Transaction with PHP.

Image
Committing PostgreSQL Transaction with PHP.
<?php $constring = "host=localhost port=5432 dbname=yourdb user=youruser password=yourpassword"; 
$pglink = pg_connect($constring) or die('Could not connect');
pg_query("BEGIN") or die("Could not start transaction\n");
$user = pg_query("insert into users values(1, 'JJ')"); $staff = pg_query("insert into staffs values(1, 'JJ','Staff')"); 
if($user and staff){        //Committing transaction        pg_query("COMMIT") or die("Transaction commit failed\n");  } else {       //Rolling transaction        pg_query("ROLLBACK") or die("Transaction rollback failed\n");  }
pg_close($pglink); ?>


The purpose of my posts is to keep the note of my works and, at the same time helping others. I hope this post will help someone.  Anything?? Please leave a comment. Good Luck!! ;)

SQL command to view columns of the specified table

Image
SELECT column_name,data_type, character_maximum_length
FROM information_schema.columns
WHERE table_name   = '<your table name>'
This command usually works in many database engines.

How to reset your mac OSX user account if you are locked out.

Image
How I Reset my MacOSX
1. Shutdown your computer if it is on.
2. Start your computer and immediately press and hold Command + S to enter Single-user mode
3. When the terminal is opened. Enter these command one at a time and press Enter after each command:

------------
mount -uw /
rm /var/db/.AppleSetupDone
reboot
------------

Above commands will do the following things:

- Mount the internal hard drive with write permission
- Remove the Mac setup file. This is the file that OSX checks to determine if the system is ready to setup.
- Reboot the Mac.
--------------
After rebooting, you will see the setup screen of your Mac. Go through it and, once you get into your mac, Go to System Preferences > Users & Groups:

There, you will see your user account, open it and change your password (don't forget to change your keyboard back to English),
then you can restart your computer and you can get back into your account and continue your work.....

hope this helps someone else...