Friday, December 30, 2011

PHP on windows


PHP 5.3
http://www.apachelounge.com/download/
http://windows.php.net/download/ (PHP 5.3.x VC9 x86 Thread Safe)

PHP 5.2
http://httpd.apache.org/
http://windows.php.net/download/ (PHP 5.2.x VC6 x86 Thread Safe)

Friday, December 09, 2011

Getting a LAMP install going with full UTF-8 (not necessary with gentoo, it already defaults to UTF-8 everywhere).

php config
sudo vim /etc/php5/apache2/php.ini

default_charset="utf-8"
mbstring.internal_encoding = UTF-8

sudo service apache2 restart

mysql config
sudo vim /etc/mysql/my.cnf

[client]
default-character-set = utf8

[mysqld]
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake

sudo service mysql restart






source(s): http://www.source.com

Wednesday, August 31, 2011

php unicode string

Have you ever wanted to express unicode code points in a php string

$string = "Hello World \u4f60\u597d\u4e16\u754c";
(which is...)
$string = "Hello World 你好世界";
Try this:
$string = ustring("Hello World \u4f60\u597d\u4e16\u754c");
function ustring($string)
{
return preg_replace_callback("/\\\\[Uu]([0-9A-Fa-f]{4})/",'matcheduchar', $str)."\n";
}
function matcheduchar($matches)
{
$num = hexdec($matches[1]);
if($num<=0x7F) return chr($num); if($num<=0x7FF) return chr(($num>>6)+192).chr(($num&63)+128);
if(0xd800<=$num && $num<=0xdfff) return '';//invalid block of utf8 if($num<=0xFFFF) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
if($num<=0x10FFFF) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128).chr(($num&63)+128);
return '';
}

Friday, May 20, 2011

Geany Find in Files Dialog

I opened the geany Find in Files Dialog and it kept defaulting to ISO-8859-1. It kept bugging me cause I wanted it to default to UTF-8

Turns out... in the source code of Geany 0.20 says this:
/* set the encoding of the current file */
if (doc != NULL)
    enc_idx = encodings_get_idx_from_charset(doc->encoding);
gtk_combo_box_set_active(GTK_COMBO_BOX(fif_dlg.encoding_combo), enc_idx);

So my problem was I had an ISO-8859-1 file open... then when I went todo CTRL-SHIFT-F, find in files, it defaulted to the charset of the file that was already open. All I had to do was change the encoding of my file (that was already open) to utf8 and the find in files defaulted correctly.

Wednesday, May 11, 2011

hg style file on linux

http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html#id417978
http://www.jaharmi.com/2008/11/30/list_changed_files_in_a_mercurial_repository_with_a_custom_output_style
http://mercurial.808500.n3.nabble.com/How-to-get-a-list-of-changed-files-td808109.html

save this file:

http://mercurial.808500.n3.nabble.com/attachment/808110/0/map-cmdline.gward
to this folder:
/usr/share/mercurial/templates/

now you can do:
hg log -r tip --style gward -v

or setup your ~/.hgrc
[ui]
style = gward
[defaults]
log = -v

now you can do:
hg log -r tip

Thursday, February 17, 2011

Java Servlet 2.5 API javadocs for Tomcat 6

Oh my goodness, I am starting to dislike oracle. When I google for "java servlet 2.5 api docs"

The first link is:
* http://www.oracle.com/technetwork/java/javaee/servlet/index.html

and when I go to the page:
* http://tomcat.apache.org/tomcat-6.0-doc/index.html

it has a link to
* Servlet API Javadocs - The Servlet 2.5 API Javadocs.

But the link is a dead link that redirects to
* http://www.oracle.com/technetwork/java/javaee/servlet/index.html

ug.

Well I finally found out that javaee 5 uses servlet api 2.5 so this might work
http://download.oracle.com/javaee/5/api/javax/servlet/package-summary.html

But so might this:
Java Servlet Javadoc API http://download.oracle.com/docs/cd/E17802_01/products/products/servlet/2.5/docs/servlet-2_5-mr2/

Java Servlet In Ubuntu with Tomcat 6

user@desktop:~/Servlet$ sudo apt-get install tomcat6
user@desktop:~/Servlet$ sudo service tomcat6 start
user@desktop:~/Servlet$ sudo service tomcat6 restart
user@desktop:~/Servlet$ sudo service tomcat6 stop
user@desktop:~/Servlet$ sudo service tomcat6 start
user@desktop:~/Servlet$ echo "* used tutorial http://content.hccfl.edu/pollock/ajava/war/myservletwar.htm"
* used tutorial http://content.hccfl.edu/pollock/ajava/war/myservletwar.htm
user@desktop:~/Servlet$ vim SampleServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SampleServlet extends HttpServlet
{
  public void doPost ( HttpServletRequest req, HttpServletResponse res ) throws IOException, ServletException
  {
    doGet( req, res );
  }

  public void doGet ( HttpServletRequest req, HttpServletResponse res ) throws IOException, ServletException
  {
    res.setContentType( "text/html" ); // Can also use "text/plain" or others.
    PrintWriter out = res.getWriter();

    String addr = req.getRemoteAddr();

    // Create output (the response):
    out.println( "<HTML><HEAD><TITLE>SampleServlet in     myServletWar</TITLE></HEAD>" );
    out.println( "<BODY><H1 ALIGN=\"CENTER\">" );
    out.println( "Hello " + addr + ", from SampleServlet in myServletWar!" );
    out.println( "</H1></BODY></HTML>" );
    out.close();
  }
}

user@desktop:~/Servlet$ mkdir myServletWar
user@desktop:~/Servlet$ mkdir myServletWar/META-INF
user@desktop:~/Servlet$ mkdir myServletWar/WEB-INF
user@desktop:~/Servlet$ mkdir myServletWar/WEB-INF/classes
user@desktop:~/Servlet$ vim myServletWar/WEB-INF/web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<display-name>myServletWar, a first Web Application</display-name>
<description>
This is a simple web application containing a single servlet
of the "Hello, World" variety.
</description>
<servlet>
<servlet-name>myHello</servlet-name>
<servlet-class>SampleServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myHello</servlet-name>
<url-pattern>/sample</url-pattern>
</servlet-mapping>
</web-app>

user@desktop:~/Servlet$ javac -cp ".:/usr/share/java/servlet-api-2.5.jar" -d myServletWar/WEB-INF/classes/ SampleServlet.java
user@desktop:~/Servlet$ find
.
./myServletWar
./myServletWar/WEB-INF
./myServletWar/WEB-INF/classes
./myServletWar/WEB-INF/classes/SampleServlet.class
./myServletWar/WEB-INF/web.xml
./myServletWar/META-INF
./SampleServlet.java
user@desktop:~/Servlet$ rm -f myServletWar.war
user@desktop:~/Servlet$ jar -cvf myServletWar.war -C myServletWar/ .
user@desktop:~/Servlet$ sudo cp myServletWar.war /var/lib/tomcat6/webapps/
user@desktop:~/Servlet$ curl http://127.0.0.1:8080/myServletWar/sample

Wednesday, February 16, 2011

javac classpath - semicolon delimited

after installing tomcat 6 for example:
javac -cp ".:/usr/share/java/servlet-api-2.5.jar" SampleServlet.java

vim turn off indenting


:set noai
:set ai



:set paste
:set nopaste

Wednesday, January 19, 2011

install php from source on ubuntu 10.10

http://www.php.net/manual/en/install.unix.apache2.php
http://httpd.apache.org/download.cgi
http://us2.php.net/downloads.php
sudo apt-get install g++
sudo apt-get install libssl-dev
tar -xjvf httpd-2.2.17.tar.bz2
cd httpd-2.2.17/
./configure --enable-so
sudo make
sudo make install
sudo /usr/local/apache2/bin/apachectl start
cd ..
tar -xjvf php-5.3.5.tar.bz2
cd php-5.3.5/
sudo apt-get install libxml2-dev
sudo apt-get install libmysqlclient-dev
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql
sudo make
sudo make install
cd ..

Wednesday, January 12, 2011

Fetch SSL Certificate - Public Key Details

$url = 'www.digicert.com'; // For example
$context = stream_context_create();
$res = stream_context_set_option($context, 'ssl', 'capture_peer_cert', true);
$res = stream_context_set_option($context, 'ssl', 'verify_host', true);
if ($socket = stream_socket_client("ssl://$url:443/", $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context)) {
if ($options = stream_context_get_options($context)) {
if (isset($options['ssl']) && isset($options['ssl']['peer_certificate'])) {
$x509_resource = $options['ssl']['peer_certificate'];
$cert_arr = openssl_x509_parse($x509_resource);
openssl_x509_export($x509_resource,$x509_string);

$public_key_res = openssl_pkey_get_public($x509_string);
$public_key_arr = openssl_pkey_get_details($public_key_res);

print_r($public_key_arr);
}
}
}

Monday, January 10, 2011

preg_match reference links

http://us.php.net/manual/en/reference.pcre.pattern.modifiers.php
http://us.php.net/manual/en/regexp.reference.meta.php
http://us.php.net/manual/en/regexp.reference.escape.php
http://us.php.net/manual/en/regexp.reference.unicode.php