Monthly Archives: January 2012

zip files on terminal

zip -r /path/to/filename.zip /path/where/the/files/are/placed/

mysql foreign key check

turn off

SET FOREIGN_KEY_CHECKS=0;

turn on

SET FOREIGN_KEY_CHECKS=1;

ex.:

SET FOREIGN_KEY_CHECKS=0;
YOUR QUERY;
SET FOREIGN_KEY_CHECKS=1;

svn ignore

1 – go to folder where your files are placed

2 – Edit the properties for the current directory

svn propedit svn:ignore .

3 – Add the files or patterns ex:

Ignores all .conf files on the current directory

*.conf

4 – Save your file (^X if you’re using nano)

5 – Confirm what you did (you can skip this)

You can see your property

svn propget svn:ignore .

You should see an ‘I’ next to the ignored files

svn status --no-ignore

6 – Commit your changes

svn commit -m 'svn ignore'

Now you can ask:
- Ok, but if I want to undo these changes or add some new files or patterns?

I say: Easy!

- If you and to add new files or patterns: Repeat all above steps (1 – 6)

If you want do undo these changes, you need to go to your directory and type:

svn propdel svn:ignore

chmod recursive on terminal

chmod permissionsettings dirname* -R

unrar files on linux ubuntu

sudo apt-get install unrar
unrar x file.rar

PHP Rest with cURL

request.php

function request($request_type) {
 
	$ch = curl_init();
 
	curl_setopt ($ch, CURLOPT_URL, "http://localhost/server.php");
 
	switch (true) {
 
		case $request_type == 'get':
 
			curl_setopt ($ch, CURLOPT_HEADER, 0);
 
			break;
 
		case $request_type == 'post':
 
			curl_setopt($ch, CURLOPT_POST, 1);
			curl_setopt($ch, CURLOPT_POSTFIELDS, array('foo' => 'bar'));
 
			break;
 
		case $request_type == 'put' :
 
			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
 
			break;
 
		case $request_type == 'delete':
 
			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
 
			break;
 
	}
 
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
	return curl_exec($ch);
}
 
var_dump(request('get'));
 
var_dump(request('post'));
 
var_dump(request('put'));
 
var_dump(request('delete'));

server.php

echo 'REQUESTED: ' . $_SERVER['REQUEST_METHOD'];

Smarty with php count function

{if $myarray|@count gt 0}...{/if}

Javascript Countdown

var countdown = {
    d : 0, h : 0, m : 0, s : 0,
    set : function(d, h, m ,s) {
        this.d = d;
        this.h = h;
        this.m = m;
        this.s = s;
        this.begin();
    },
 
    begin : function() {
 
    	if (this.d > 0 || this.h > 0 || this.m > 0 || this.s > 0) {
 
    		if (this.s == 0) {
 
    			if (this.m == 0) {
 
    				if (this.h == 0) {
 
    					if (this.d > 0) {
 
    						this.h = 23;
    						this.m = 59;
	    					this.s = 59;
    						this.d--;
 
    					} else {
 
    						this.h = 0;
	    					this.m = 0;
	    					this.s = 0;
    					}
 
    				} else {
 
    					this.h--;
    					this.m = 59;
    					this.s = 59;
    				}
 
    			} else {
 
    				this.m--;
    				this.s = 59;
    			}
 
    		} else {
 
    			this.s--;
    		}
 
	    	document.getElementById('day').innerHTML 	= (this.d <=9 ? '0' + this.d : this.d);
	    	document.getElementById('hour').innerHTML 	= (this.h <=9 ? '0' + this.h : this.h);
	    	document.getElementById('minute').innerHTML = (this.m <=9 ? '0' + this.m : this.m);
	    	document.getElementById('second').innerHTML = (this.s <=9 ? '0' + this.s : this.s);
 
    		setTimeout(function(){
	    		countdown.begin();
	    	}, 1000);
 
    	}
    }
}

usage:

Day:
<p id="day"></p>
<br />
Hour:
<p id="hour"></p>
<br />
Minute:
<p id="minute"></p>
<br />
Second:
<p id="second"></p>
<script type="text/javascript">
countdown.set(1, 0, 0, 3);
</script>

php.ini on ubuntu

/etc/php5/apache2/php.ini
Page 1 of 11