#include <stdio.h>
typedef struct Table Table;
struct Table {
int Height;
int Width;
};
Table * create_table(int height, int width)
{
Table *mytable_ptr;
Table my = {height, width};
mytable_ptr = &my;
return mytable_ptr;
}
int main()
{
Table * my;
my = create_table(10, 20);
int height = my->Height;
printf("h%d\n", height);
}
Thursday, 12 September 2013
Friday, 7 June 2013
Test tomcat 6.0 installation in Ubuntu 12
1. compile a test servlet
a. create a java class named PuppyServlet.java
package dog;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class PuppyServlet extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html><body>");
out.println("<center>Hello, world! I have a cute puppy</center>");
out.println("</body></html>");
out.close();
}
}
b. set class path in .bashrc
export CLASSPATH=/usr/share/java/servlet-api.jar
c. compile
javac PuppyServlet.java
2. create directories and configure file to deploy this sevlet
a. go to /var/lib/tomcat6/webapps create a directories
cd /var/lib/tomcat6/webapps
mkdir test
cd test
mkdir WEB-INF
cd WEB-INF
mkdir classes
cd classes
mkdir dog
b. put PuppyServlet.class in dog directory
c. create web.xml file and put it in WEB-INF direcory
<web-app version="2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xsi:schemalocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>dog.PuppyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/mytest</url-pattern>
</servlet-mapping>
</web-app>
3. go to http://localhost:8080/test/mytest
should see: Hello, world! I have a cute puppy
a. create a java class named PuppyServlet.java
package dog;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
public class PuppyServlet extends HttpServlet {
public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html><body>");
out.println("<center>Hello, world! I have a cute puppy</center>");
out.println("</body></html>");
out.close();
}
}
b. set class path in .bashrc
export CLASSPATH=/usr/share/java/servlet-api.jar
c. compile
javac PuppyServlet.java
2. create directories and configure file to deploy this sevlet
a. go to /var/lib/tomcat6/webapps create a directories
cd /var/lib/tomcat6/webapps
mkdir test
cd test
mkdir WEB-INF
cd WEB-INF
mkdir classes
cd classes
mkdir dog
b. put PuppyServlet.class in dog directory
c. create web.xml file and put it in WEB-INF direcory
<web-app version="2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xsi:schemalocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
<servlet>
<servlet-name>test</servlet-name>
<servlet-class>dog.PuppyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/mytest</url-pattern>
</servlet-mapping>
</web-app>
3. go to http://localhost:8080/test/mytest
should see: Hello, world! I have a cute puppy
Thursday, 6 June 2013
Enviorment variables
1. View all environment variables
export -p
2. View individual variables
echo $variable_name
3. Set variable dynamically
export APPLICATION_ENV='local'
4. Set variable permanently
put export statement in .profile
export -p
2. View individual variables
echo $variable_name
3. Set variable dynamically
export APPLICATION_ENV='local'
4. Set variable permanently
put export statement in .profile
Wednesday, 27 March 2013
More MySql tips
dump db
mysqldump --host='127.0.0.1' --user=root --password='passwd' --column-statistics=0 db_name>dw.sql
redirect result to a csv file
select * from usermanager_users
into outfile '/tmp/test.csv' fields terminated by ',' enclosed by '"'
lines terminated by '\n';
redirect result on command line
mysql -u [username ] -p[password] [db_name] -e " SELECT * FROM [tbl_name] " > file_name
Case sensitive compare
#Will match first name Mary, but not match mary
SELECT first_name FROM `name` WHERE first_name REGEXP BINARY 'Mary';
Show stored procedures
SHOW PROCEDURE STATUS WHERE Db = 'db_name'\G
# show details of procedure
SHOW CREATE PROCEDURE procedure_name\G
Create a mysql user
CREATE USER lshen@'10.18.276.170' IDENTIFIED BY 'eikdkdk123scx';
select * from mysql.user where User="lshen"\G
GRANT SELECT ON *.* TO lshen@'10.18.276.170';
FLUSH PRIVILEGES;
Query Cache
If swap between different MySQL versions, cache may cause problem. For example, they may use the different end character. Therefore, need to flush cache.
#To check whether the query cache is present in your MySQL server
mysql> SHOW VARIABLES LIKE 'have_query_cache';
#To monitor query cache performance
mysql> SHOW STATUS LIKE 'Qcache%';
#removes all query results from the query cache
mysql> RESET QUERY CACHE ;
Subscribe to:
Posts (Atom)