postgresql “New Server Registration” connection problem on ubuntu?

“connection error” or “authentication problem” when trying to register a new server in pgAdmin III?

(ubuntu or xubuntu)

This post shows how to obtain & setup the “Host”, “Port”, “Username”, and “Password” of postgresql.

1) Obtain default port.  To do that, open up /etc/postgresql/x.xversion/main/postgresql.conf

See “port= 5432″. You may change the port used by postgresql.

postgresblog

2) Obtain Host.

Search the listen_addresses. For instance, here 'localhost' is my defaut host. You may alter the host here.

3) Change password.

Open terminal.

———————————————–

~$: psql -d postgres -U postgres

psql (9.1.3) Type "help" for help.
postgres=# alter user postgres with password 'mynewpassword'; ALTER ROLE
postgres=# q
~$:sudo /etc/init.d/postgresql restart
———————————————————-
Now you can run pgAdminIII. On form New Server Registration, set ‘Username’ to “postgres”, type in password you entered before, and the field ‘Name’ is up to your choice.

Paint & using Mouse in Java

/** this simple program allows user to draw by click & drag with the mouse. The example contains “Main.java” and “draw.java” classes. The “select paint” method in “draw.java” can be used to add new paint style, e.g, different colors. Any queries, feel free to ask…

By Devansh Ramen

*/

// Main.java

import java.awt.Component;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
public class Main {

public static void main(String[] args) {
JFrame window = new JFrame(“Clipping”);
draw content = new draw();
window.setContentPane(content);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLocation(100,75);
window.setSize(500,500);
window.setVisible(true);
}
}

———————————————————————————————————————————–

//draw.java

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.JPanel;
//MouseListener: interface containing methods required to ‘listen’ to mouse events
public class draw extends JPanel implements MouseListener, MouseMotionListener {

private int prevX, prevY;
private Graphics paint;
private Polygon triangle= new Polygon();
private String drawtype;

public draw() {
setBackground(Color.WHITE);
addMouseListener(this);
addMouseMotionListener(this);
}

private void selectpaint() {
paint = getGraphics();
paint.setColor(Color.BLACK);
drawtype = “line”;
// to choose polygon to draw
}

public void mousePressed(MouseEvent evt) {
int x = evt.getX(); // capture start position
int y = evt.getY();
prevX = x; //set previous same position at first
prevY = y;
selectpaint();
}

public void mouseReleased(MouseEvent evt) {
paint.dispose();
paint = null;
}

public void line(MouseEvent evt){
int x = evt.getX(); // capture new x coordinate
int y = evt.getY(); // capture new y coordinate
paint.drawLine(prevX, prevY, x, y);
prevX = x;
prevY = y;
}

public void mouseDragged(MouseEvent evt) {
if (drawtype== “line”){
line(evt);
}

}

public void mouseMoved(MouseEvent evt) { } //mouse moves but no button pressed
public void mouseEntered(MouseEvent evt) { }
public void mouseExited(MouseEvent evt) { }
public void mouseClicked(MouseEvent evt) { }

}

Real-time collaborative editor on browser

Understanding and Applying Operational Transformation

this link explains concepts about real-time and collaborative editor on web quite well. It uses concepts which are used by google docs ( and other google wave variants)

http://www.codecommit.com/blog/java/understanding-and-applying-operational-transformation

php “XSLTProcessor::setParameter” function

xmltransform.php
<?php
$xml= new DOMDocument();
$xml-> load(“testparam.xml”);

$xsl= new DOMDocument();
$xsl-> load(“testparam.xsl”);

$xsltproc= new XSLTProcessor();
$xsltproc-> importStylesheet($xsl);

$variable= “myvalue”;    //this part for passing parameter ‘myparam’ to xsl
$xsltproc->setParameter(”, ‘myparam’, $variable);

echo $xsltproc->transformToXML($xml);
?>

——————————————————————————————

testparam.xsl

<?xml version=”1.0″?>
<xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”&gt;
<xsl:template match=”/”>
<html>
<body>
–<p style=”color:red;”> Value parameter: <xsl:value-of select=”$myparam”/></p>
–<h2>Parameter works everywhere</h2>
–<table border=”1″>

—–<xsl:for-each select=”mytestnode”>

——–<tr>
———–<td> <xsl:value-of select=”$myparam”/> </td>
——-</tr>

—–</xsl:for-each>
–</table>

</body>
</html>
</xsl:template>
</xsl:stylesheet>

php ‘nl2br’ function; used to generate from used in mysql records

echo nl2br(“break line with \n nl2br”);

‘nl2br’ function is used to echo ‘</br>’ from ‘/n’ which is used by mysql for new lines… So for mysql fields:

echo nl2br($rowchord['myfield']);

Hosting webpages for free

http://www.serversfree.com/

It allows you to create cron jobs, mysql database, provides good file manager system…

Reference (&) vs Dereference (*) in C

This page explains pointers in details and can be very helpful:
http://www.cplusplus.com/doc/tutorial/pointers/

Two important points:

  • & is the reference operator and can be read as “address of”
  • * is the dereference operator and can be read as “value pointed by”
Follow

Get every new post delivered to your Inbox.