Posted on December 27th, 2010 in programming, web | Comments Off
Had to copy a large DB into a new one…Since MySQL Administrator and PHPMyAdmin failed to backup the 3.7Gb Database I was forced to do it from Shell like this:
mysqldump -u user -p db-name > output_file.out
/*- launch this from the shell as root with the credentials of the source DB*/
mysql -u user -p new_db-name < output_file.out
/* - this will copy from the dump file into the new database.
you can also download the resulting file and use it on
another server - you could do this the old fashion way by
copying it on your local machine and then upload it to your
new server and launch the previous command or if you have "scp":*/
scp output_file.out user@remote_ftp_path
Recently I had to save a DataBase from a server only with FTP access and without any tool like PhpMyAdmin or Cpanel. I had only the FTP credentials, the name of the DataBase and the credentials to access the DataBase.
So if you want to save a database to a file only with the aid of PHP here’s a small function that does the trick:
function backup_tables($host,$user,$pass,$name,$tables = '*')
{
$link = mysql_connect($host,$user,$pass);
mysql_select_db($name,$link);
//get all of the tables - if the tables parameter is "*" all the tables will be taken
if($tables == '*')
{
$tables = array();
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_row($result))
{
$tables[] = $row[0];
}
}
else
{
//$tables should be a string of table names separated by coma
$tables = is_array($tables) ? $tables : explode(',',$tables);
}
//cycle through the tables and build the text to be written into the dump file
foreach($tables as $table)
{
$result = mysql_query('SELECT * FROM '.$table);
$num_fields = mysql_num_fields($result);
$return.= 'DROP TABLE '.$table.';';
$row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
$return.= "\n\n".$row2[1].";\n\n";
for ($i = 0; $i < $num_fields; $i++)
{
while($row = mysql_fetch_row($result))
{
$return.= 'INSERT INTO '.$table.' VALUES(';
for($j=0; $j<$num_fields; $j++)
{
$row[$j] = addslashes($row[$j]);
$row[$j] = ereg_replace("\n","\\n",$row[$j]);
if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
if ($j<($num_fields-1)) { $return.= ','; }
}
$return.= ");\n";
}
}
$return.="\n\n\n";
}
//save the dump file
$handle = fopen('db-backup.sql','w+');
fwrite($handle,$return);
fclose($handle);
}
Posted on August 3rd, 2010 in programming, tech | Comments Off
If you wish to select unique combinations of columns on a MySql table you should use GROUP BY like this:
CREATE TABLE dummyTable
SELECT Item1, Item2, Item3, Item4
FROM dummyTable
GROUP BY Item1, Item2, Item3, Item4
this will output the unique combinations of the 4 columns on the dummyTable table.
Tough this is quite simple i did not remember how to do it today. Stumbled at the “[ ]” in the element name.
The HTML part:
and the PHP :
Using this regular expression filter does the trick:
var filterEmail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z])+\.)+([a-zA-Z]{2,4})+$/;
if (filterEmail.test(Email)) //Check the Email Format.
{
//........
}
Posted on October 8th, 2008 in programming, tech, web | Comments Off
| Navigational Shortcuts |
| F10 |
Main menu |
| Shift F10 |
Context menu |
| Ctrl F10 |
View menu |
|
|
| Workspace navigation |
| F12 |
Activate editor |
| Ctrl+Shift+W |
Switch editor |
| Ctrl F6 |
Next editor |
| Ctrl Shift F6 |
Prev editor |
| Ctrl F7 |
Next workspace |
| Ctrl Shift F7 |
Prev workspace |
| Ctrl F8 |
Next perspective |
| Ctrl Shift F8 |
Prev perspective |
| Alt Left |
Back |
| Alt Right |
Forward |
|
|
| Files |
| Alt Shift S |
Show in… |
| Ctrl Shift R |
Jump to file |
| Ctrl N |
New file |
| Ctrl S |
Save file |
| Ctrl Shift S |
Save all files |
| Ctrl F4 |
Close file |
| Ctrl Shift F4 |
Close all files |
|
|
| Find |
| Ctrl L |
Goto line |
| Ctrl F |
Find |
| Ctrl J |
Incremental find |
| Ctrl Shift J |
Incremental find prev |
| Ctrl K |
Find next |
| Ctrl Shift K |
Find prev |
| Ctrl H |
Search workspace |
| Ctrl (dot) |
Navigate next |
| Ctrl (comma) |
Navigate prev |
|
|
| Java navigation |
| F3 |
Goto declaration |
| Ctrl Shift U |
Find references in file |
| Ctrl Shift G |
Find references in workspace |
| Ctrl G |
Find declarations in workspace |
| Ctrl Shift P |
Navigate to matching bracket/brace |
| Ctrl T |
Popup type hierarchy |
| Ctrl Shift T |
Open Type |
| Ctrl O |
Outline of current source |
| Ctrl F3 |
Outline of current cursor position |
| Ctrl Shift Arrow |
Jump beetween methods up or down |
| F2 |
Show Javadoc |
| F4 |
Show hierarchy |
| Ctrl Alt H |
Open call hierarchy |
|
|
|
|
| General editing |
| Alt Arrow |
Move line(s) up or down |
| Alt Shift Up |
Expand selection to enclosing element |
| Alt Shift Right |
Expand selection to next element |
| Alt Shift Left |
Expand selection to previous element |
| Alt Shift Down |
Restore previous selection |
| Ctrl Alt Arrow |
Duplicate line(s) up or down |
| Shift Enter |
Insert line below |
| Ctrl Shift Enter |
Insert line above |
| Ctrl D |
Delete line |
| Ctrl Shift Q |
Toggle Quick Diff |
| Ctrl Shift Y |
Convert to lowercase |
| Ctrl Shift X |
Convert to uppercase |
|
|
| Java editing |
| Alt Shift U |
Remove occurrence annotations |
| Ctrl 1 |
Quick fix (works even when there are no errors |
| Ctrl Shift M |
Add import |
| Ctrl Shift F |
Reformat |
| Ctrl Shift O |
Organize Imports |
| Ctrl / |
Comment |
| Ctrl \ |
UnComment |
| Ctrl Shift Space |
Parameter hints |
| Ctrl |
Hyperlink identifier |
| Ctrl I |
Correct indentation |
| Shift Space |
Incremental content assist |
|
|
| Debugger |
| F5 |
Step into |
| F6 |
Step over |
| F7 |
Run to return |
| F8 |
Resume |
| F9 |
Relaunch last |
| F11 |
Run/debug last |
| Ctrl F11 |
Run |
| Ctrl Shift B |
Toggle breakpoint |
| Ctrl D |
Display |
| Ctrl Q |
Inspect |
| Ctrl R |
Run to line |
| Ctrl U |
Run snippet |
|
|
| Refactoring |
| Alt T |
Refactoring menu |
| Ctrl Shift Z |
Undo refactor |
| Ctrl Shift Y |
Redo refactor |
| Alt Shift R |
Rename |
| Alt Shift V |
Move |
| Alt Shift I |
Inline |
| Alt Shift M |
Extract method |
| Alt Shift L |
Extract local |
| Alt Shift C |
Change method signature |
|
|
| Misc |
| F5 |
Refresh |
| F1 |
Infopop |
| F2 |
Show resizeable hover |
… of course these can all be customized by going to Window -> Preferences -> General -> Keys
Posted on June 9th, 2008 in programming, tech, web | Comments Off
Posted on June 6th, 2008 in programming | Comments Off
A little filter that detects if the The X-Forwarded-For (XFF) HTTP header is set.
If it’s set it means that the call arrived trough a proxy, and when the “getRemoteAddr()” method is called by the server it will return the last proxy in the IP array.
So basicly what this does is (if XFF is set) forces the “getRemoteAddr()/getRemoteHost()” methods to always return the first IP in the XFF header.
Here’s the filter class:
public final class EditHeader implements Filter {
private FilterConfig filterConfig;
public void init(FilterConfig filterConfig) throws
ServletException {
System.out.println("Filter initialized");
this.filterConfig = filterConfig;
}
public void destroy() {
System.out.println("Filter destroyed");
this.filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
chain.doFilter( new MyWrapper((HttpServletRequest) request), response);
}
}
Here you have the filter wrapper class:
public final class MyWrapper extends
HttpServletRequestWrapper {
public HttpServletRequest httpRequest = (HttpServletRequest) super.getRequest();
public String reqAddr = httpRequest.getRemoteAddr();
public String reqHost = httpRequest.getRemoteHost();
public MyWrapper(HttpServletRequest servletRequest) {
super(servletRequest);
}
public String getRemoteAddr() {
String callerChain = httpRequest.getHeader("X-Forwarded-For");
if (callerChain==null ||callerChain.equals(""))
return reqAddr+"abc";
StringTokenizer tempStringTokenizer = new StringTokenizer(callerChain, ",");
return (tempStringTokenizer.nextToken());
}
public String getRemoteHost() {
String callerChain = httpRequest.getHeader("X-Forwarded-For");
if (callerChain==null ||callerChain.equals(""))
return reqHost+"def";
StringTokenizer tempStringTokenizer = new StringTokenizer(callerChain, ",");
return (tempStringTokenizer.nextToken());
}
And here’s a little test servlet :
public class test extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("");
out.println("Test");
out.println("");
out.println("Caller Host :" +req.getRemoteAddr() + "");
out.println("Caller Addr :" + req.getRemoteHost() +"");
out.println("");
}
}
The web.xml looks like this :
EditHeader
EditHeader
EditHeader
test
test
test
test
test
Docs:
http://java.sun.com/products/servlet/Filters.html
http://www.onjava.com/pub/a/onjava/2004/03/03/filters.html
http://www.developer.com/java/ent/article.php/3467801
Drag&drop Tabs
Requests:
A dynamic user interface using the jQuery javascript library that allows an user to drag and drop a tab from one tab component to another.
Resources and online documentation used:
Time Management :
The order of events over the past days :
- Friday, May 30: 3 hours of reading/resource searching on JQuery.
- Saturday, May 31: 3-4 hours of tutorials and examples, experiencing with the JQuery UI.
- Sunday, June 1: 2 hours – putting together the interface.
The Interface :
The JQuery UI components used are:
The order of events managed:
- Create the two tab sets using JQuery’s tabs component.
- Make the tabs draggable with JQuery’s draggable component.
- Make the heads of the tab sets a “droppable” area so that it can recieve a new dragged element.
- On the “drop” event : Get the corespondent content of a dragged tab, remove drgged tab from the source tab set, add new tab into the destination tab set with a coresponding content identical to the one it came from
I used the “flora” theme found in the resources available in the JQuery documentation.
View the interface!
Main issues:
-didn’t figure out why the movement from the right set to the left one doesn’t work propperly
-didn’t manage to make the 2 containing divs display “on the same line” in IE6.. tried with a wrapper div but still not working