Search Results For : code

Quick note on Web.config file

A quick note on Web.config file in the ASP.NET project. It is worth noting that the file is a XML File (read this for more info – https://msdn.microsoft.com/en-us/library/ff400235.aspx )

One issue that hindered my process earlier was that the content in the value has special character it in, particularly, one of my SQL server’s password has a special character in it.

I would have to go and replace them accordingly. For instance, my password is <Password1& (note that < and ” is inclusive), i would have to change it to
&lt;Password1&amp;

You can refer to the list here – https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

Code snippets for downloading images and displaying images from Android Internal storage

Reference to http://developer.android.com/guide/topics/data/data-storage.html#filesInternal

Saving of images into internal storage

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());
fos.close();

Displaying of images from internal storage

FileInputStream in = openFileInput(FILENAME);
Bitmap image = BitmapFactory.decodeStream(in);
imageView.setImageBitmap(image);

Delete data from database automatically at regular interval

Recently I attended a session where a few developers would discuss about the website they have done. One of the developers approached me and asked me if there is a way that you could delete data from MySQL database once a week / at regular interval. I thought this short tutorial will be useful for one who wish to do so on the LAMP stack.

Step 1: We will come up with the php file that will do the delete function, from MySQL database and upload it.

$link = mysql_connect(‘localhost’, ‘mysql_user’, ‘mysql_password’);

if (!$link) {
die(‘Could not connect: ‘ . mysql_error());
}

mysql_select_db(‘mydb’);

mysql_query(“DELETE FROM mytable WHERE WHERE dateInserted > ‘2012-9-9′”);

In my sample code above, i did, “DELETE FROM mytable WHERE WHERE dateInserted > ‘2012-9-9′”. It depends on what you want to do, you can always change the conditions on why it should be deleted. I have also saved it as DeleteData.php

 

Step 2: Since I have cPanel, i used cPanel and go into Cron Jobs

 

 

 

 

 

 

 

Step 3: I will setup the cron job to run at once a week.(Of course you can set otherwise)

 

 

 

 

 

 

Note that for Command, you have to specify where the file lies, after you upload.

You can download the mentioned, DeleteData.php here.

Delete records from mysql automatically

Hope this is helpful for those who are finding a quick tutorial on how this can done. If you have any questions, please feel free to email guohong@limguohong.com, use the contact us form or alternatively you can comment. 🙂

I will post a tutrial on how we can do this on WISA stack.

Visual Basic reverse For Loop

Something quickie post here. Since I am not from a vb background, this took me a little more than 3 mins to figure this out. Thought will be good to post this.

For i = 10 to 0 step -1
STATEMENT
Next

This is the the C# version of the loop.

for(int i=10; i<0; i--){ STATEMENT; }

Thanks to : http://msdn.microsoft.com/en-us/library/5z06z1kb.aspx