Run the following commands separately to change/reset your ‘root’ user password in MySql database.

There is a database called mysqlwhich is the default database. It is where Users such as root are stored. More info can be found
In this script, it is assumed that your new password is MyNewPassword. Hence, replace that with whatever you want your password to be.

UPDATE mysql.user
SET Password=PASSWORD(‘MyNewPassword’)
WHERE User=’root’;
FLUSH PRIVILEGES;

Originally published at http://binyit.blogspot.com.

First, Set up your connectionString and use the following code snippet in a method.

using (SqlConnection con = new SqlConnection(connectionString)){

con.Open();

SqlCommand cmd = new SqlCommand("SELECT userid, username, email, city FROM USERS where username=@username and password=@password", con);
cmd.Paramters.AddWithValue("@username", username);
cmd.Parameters.AddWithValue("@password", password);
cmd.CommandType = CommandType.Text;

UserInfo info = new UserInfo();

using (SqlDataReader rdr = cmd.ExecuteReader())
{
if (rdr.HasRows)
{
rdr.Read(); // get the first row

info.UserID = rdr.GetInt32(0);
info.UserName = rdr.GetString(1);
info.Email = rdr.GetString(2);
info.City = rdr.GetString(3);
}
}
}

Acknowledgement to: Tim of StackOverFlow.com

When upgrading grails to version 2.3.0, I got the following error.

Failed to resolve dependencies ... 
org.grails.plugins:tomcat:2.3.0 ...
hibernate:2.3.0 ...

This is because as of Grails 2.3.0, the tomcat and hibernate plugins (as well as the scaffolding and webflow plugins) have been split out as completely independent plugins and are no longer versioned with Grails. You need to use explicit versions now instead of using $grailsVersion.

Hence, I replaced the following things in my BuildConfig.groovy file

OLD: runtime “:hibernate:$grailsVersion”// For versions prior to Grails 2.3.0
NEW:runtime ‘:hibernate:3.6.10.1’
OLD: build “:tomcat:$grailsVersion” // For versions prior to Grails 2.3.0
NEW: build ‘:tomcat:7.0.42’

And I added the following line to be able to run the create- and generate- scripts in Grails 2.3.0

//To run the create- and generate- scripts in Grails 2.3.0
compile ‘:scaffolding:2.0.0’

Originally published at http://binyit.blogspot.com.

Code Example

<script type="text/javascript">
var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
document.write("<b>" + day + "/" + month + "/" + year + "</b>")
</script>

The result will be 15/1/2014

Here is a complete class that shows how another activity is called when a button in the first activity is pressed.

public class FirstActivity extends Activity implements View.OnClickListener {

Button goToSecondActivityButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.first_activity);

((TextView) findViewById(R.id.textRecommendationMessage)).setText("This is the first activity");

goToSecondActivityButton= (Button) findViewById(R.id.button_go_to_second_activity);
goToSecondActivityButton.setOnClickListener(this);
}

@Override
public void onClick(View view) {

goToSecondActivity();
}

private void goToSecondActivity() {

Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
startActivity(intent);
finish();
}
}

If you have a string variable containing a date value such as 2014–06–03T11:03:44.779+03, then:

Code Example

import java.text.SimpleDateFormat 
import java.text.DateFormat
String mydate = “2014–06–03T11:03:44.779+03”
DateFormat formatter = new SimpleDateFormat(“yyyy-MM-dd”)
Date parsedDate = formatter.parse(mydate)
Date formattedDate = formatter.format(parsedDate)
/* Simplified code in one line
Date parsedAndFormattedDate = formatter.format(formatter.parse(mydate))
*/

Originally published at http://binyit.blogspot.com.

Biniam Asnake

Lead Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store