Friday, December 30, 2011

PHP on windows

PHP 5.3 (PHP 5.3.x VC9 x86 Thread Safe)

PHP 5.2 (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

mbstring.internal_encoding = UTF-8

sudo service apache2 restart

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

default-character-set = utf8


sudo service mysql restart


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

save this file:
to this folder:

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

or setup your ~/.hgrc
style = gward
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:

and when I go to the page:

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

But the link is a dead link that redirects to


Well I finally found out that javaee 5 uses servlet api 2.5 so this might work

But so might this:
Java Servlet Javadoc API

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"
* used tutorial
user@desktop:~/Servlet$ vim
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>" );

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" "">
<display-name>myServletWar, a first Web Application</display-name>
This is a simple web application containing a single servlet
of the "Hello, World" variety.

user@desktop:~/Servlet$ javac -cp ".:/usr/share/java/servlet-api-2.5.jar" -d myServletWar/WEB-INF/classes/
user@desktop:~/Servlet$ find
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

Wednesday, February 16, 2011

javac classpath - semicolon delimited

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

vim turn off indenting

:set noai
:set ai

:set paste
:set nopaste

Wednesday, January 19, 2011

install php from source on ubuntu 10.10
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 = ''; // 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);

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


Monday, January 10, 2011

preg_match reference links