Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
5 total  XML / RSS feed 

Give remote access to mysql

mysql -u root -p (your password)


then write the following

GRANT ALL PRIVILEGES ON *.* TO user@'%' IDENTIFIED BY 'PASSWORD';


then

FLUSH PRIVILEGES;

Disconnect Windows 2000 RDP session from command line

I use SSH to gain access to my Windows 2000 command line, so that will be reflected in the below steps.


Step #1: Connect to the server if you are not sitting at it
ssh username@win2000server -i privatekey

Step #2: Find out which sessions are currently active
query session

 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
>console                                     0  Conn    wdcon
 rdp-tcp                                 65536  Listen  rdpwd
 rdp-tcp#7         fakeuser                  1  Active  rdpwd

Step #3: We want to kill the connection with an ID of 1 (we can tell by the username and that it is active)
tsdiscon 1 /v

Disconnecting sessionID 1 from sessionname RDP-Tcp#7

That's it :) Easy eh?

Get remote file size, following redirects (PHP)

function get_remote_file_size($url, $readable = true){
   $parsed = parse_url($url);
   $host = $parsed["host"];
   $fp = @fsockopen($host, 80, $errno, $errstr, 20);
   if(!$fp) return false;
   else {
       @fputs($fp, "HEAD $url HTTP/1.1\r\n");
       @fputs($fp, "HOST: $host\r\n");
       @fputs($fp, "Connection: close\r\n\r\n");
       $headers = "";
       while(!@feof($fp))$headers .= @fgets ($fp, 128);
   }
   @fclose ($fp);
   $return = false;
   $arr_headers = explode("\n", $headers);
   foreach($arr_headers as $header) {
                        // follow redirect
                        $s = 'Location: ';
                        if(substr(strtolower ($header), 0, strlen($s)) == strtolower($s)) {
                                $url = trim(substr($header, strlen($s)));
                                return get_remote_file_size($url, $readable);
                        }
                        
                        // parse for content length
       $s = "Content-Length: ";
       if(substr(strtolower ($header), 0, strlen($s)) == strtolower($s)) {
           $return = trim(substr($header, strlen($s)));
           break;
       }
   }
   if($return && $readable) {
                        $size = round($return / 1024, 2);
                        $sz = "KB"; // Size In KB
                        if ($size > 1024) {
                                $size = round($size / 1024, 2);
                                $sz = "MB"; // Size in MB
                        }
                        $return = "$size $sz";
   }
   return $return;
}

Link to Remote Tag

Tag for creating ajax callback links

<%= link_to_remote( "click here",
                         :update => "specific_div_block",
                         :url =>{ :action => :action_name }) %>

SSH tunneling for MySQL

No forking in background and verbose

ssh -2 -v -c blowfish -C -N user@servername.textdrive.com -L 3370/127.0.0.1/3306


Forking in background

ssh -2 -f -c blowfish -C -N user@servername.textdrive.com -L 3370/127.0.0.1/3306


« Newer Snippets
Older Snippets »
5 total  XML / RSS feed