certutil -d sql:$HOME/.pki/nssdb -L -h "Builtin Object Token"
Friday, October 15, 2010
How to show the list of CA Root Certificates in Google Chrome in Ubuntu Linux
certutil -d sql:$HOME/.pki/nssdb -L -h "Builtin Object Token"
Monday, September 27, 2010
PHP CURLOPT_CERTINFO
if($fp = tmpfile())
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://www.digicert.com/");
curl_setopt($ch, CURLOPT_STDERR, $fp);
curl_setopt($ch, CURLOPT_CERTINFO, 1);//certinfo goes to STDERR when CURLOPT_VERBOSE is set
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
$result = curl_exec($ch);
curl_errno($ch)==0 or die("Error:" . curl_errno($ch) . " Message:" . curl_error($ch));
fseek($fp, 0);//rewind
$str='';
while(strlen($str.=fread($fp,8192))==8192);
echo $str;
fclose($fp);
}
?>
Wednesday, August 25, 2010
nice sanitized mysql insert sample php
$row["firstname"]="Billy";
$row["lastname"]="O'Leary";
$row["create_date"]=date("Y-m-d H:i:s");
$row["status"]="1";
$escaped = array_map(create_function('$a', 'return is_null($a) ? NULL : mysql_real_escape_string($a);'),$row);
$quoted = array_map(create_function('$a', 'return is_null($a) ? "NULL" : "\x27".$a."\x27";'),$escaped);
echo "INSERT INTO `employees`(`".implode("`,`",array_keys($escaped))."`) VALUES(".implode(",",array_values($quoted)).");"."\n";
it generates the sanitized insert query
Sunday, August 01, 2010
Sunday, July 18, 2010
sed strip unicode out of file
Tuesday, July 13, 2010
mysql union
+---+
| a |
+---+
| a |
+---+
1 row in set (0.00 sec)
mysql> (select 'a') union all (select 'a');
+---+
| a |
+---+
| a |
| a |
+---+
2 rows in set (0.00 sec)
mysql> (select 'a') union distinct (select 'a');
+---+
| a |
+---+
| a |
+---+
1 rows in set (0.00 sec)
Wednesday, June 30, 2010
maximum upload size in php
<?php
function max_upload_size()
{
preg_match('/^([0-9]+)([PTGMK]?)$/i', strtoupper( ini_get('post_max_size') ), $p );
preg_match('/^([0-9]+)([PTGMK]?)$/i', strtoupper( ini_get('upload_max_filesize') ), $u );
$arr = array('P'=>50,'T'=>40,'G'=>30,'M'=>20,'K'=>10);
return min( $p[1] * pow(2,$arr[$p[2]]), $u[1] * pow(2,$arr[$u[2]]) )/(1024*1024)."MB";
}
?>
Monday, May 31, 2010
utf8 in php5
utf8_encode() and utf8_decode() are awful, because they only operate in the ISO-8859-1 (latin1) charset portion of utf8. Also, for reference U+ff01, the ff01 is called the code point.
Lets say I have a unicode character U+4f60 or 你, and I want to echo it in php.
http://www.fileformat.info/info/unicode/char/4f60/index.htm
PHP is not very utf8 friendly, in order to get to work, you have to be using a computer with the right language packs installed, edit the source file in utf8, make sure every page sends out header('Content-type: text/html; charset=utf-8'); and you may still need to echo the utf8 meta tag. And for good measure make sure the file is saved with a utf8 byte order mark. But how do you echo unicode if your source file can only be in the latin1 character set?
One way is to echo the code point. In java "\u4f60" represents the character 你. Not so in php. The best you can do is these:
<?php echo json_decode('"\u4f60"');?>
<?php echo html_entity_decode("你",ENT_QUOTES,"UTF-8");?>
<?php echo "\xE4\xBD\xA0";?> //already encoded in utf8
but there is another way, with 2 basic functions:
function utf8($num)
{
if($num<=0x7F) return chr($num);
if($num<=0x7FF) return chr(($num>>6)+192).chr(($num&63)+128);
if($num<=0xFFFF) return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
if($num<=0x1FFFF) return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128).chr(($num&63)+128);
return '';
}
function uniord($c)
{
$ord0 = ord($c{0}); if ($ord0>=0 && $ord0<=127) return $ord0;
$ord1 = ord($c{1}); if ($ord0>=192 && $ord0<=223) return ($ord0-192)*64 + ($ord1-128);
$ord2 = ord($c{2}); if ($ord0>=224 && $ord0<=239) return ($ord0-224)*4096 + ($ord1-128)*64 + ($ord2-128);
$ord3 = ord($c{3}); if ($ord0>=240 && $ord0<=247) return ($ord0-240)*262144 + ($ord1-128)*4096 + ($ord2-128)*64 + ($ord3-128);
return false;
}
<?php echo utf8(0x4f60);?>
你
or you can convert back
<?php echo dechex(uniord(utf8(0x4f60)));?>
4f60
Also helpful:
function is_utf8($string)
{
// From http://w3.org/International/questions/qa-forms-utf-8.html
return preg_match('%^(?:
[\x09\x0A\x0D\x20-\x7E] # ASCII
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
)*$%xs', $string);
}
Sunday, May 09, 2010
VirtualBox fullscreen
VBoxSDL -fullscreen -vm XP_mini
Saturday, April 03, 2010
php upload script
<?php
if ($_SERVER['REQUEST_METHOD']=='POST')
{
//echo ini_get('post_max_size');
//echo ini_get('upload_max_filesize');
//echo ini_get('max_input_time');
//echo ini_get('max_execution_time');
//echo ini_get('max_file_uploads');
//echo ini_get('file_uploads');
$errors = array(
UPLOAD_ERR_OK =>'There is no error, the file uploaded with success.',
UPLOAD_ERR_INI_SIZE =>'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
UPLOAD_ERR_FORM_SIZE =>'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
UPLOAD_ERR_PARTIAL =>'The uploaded file was only partially uploaded.',
UPLOAD_ERR_NO_FILE =>'No file was uploaded.',
UPLOAD_ERR_NO_TMP_DIR =>'Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.',
UPLOAD_ERR_CANT_WRITE =>'Failed to write file to disk. Introduced in PHP 5.1.0.',
UPLOAD_ERR_EXTENSION =>'A PHP extension stopped the file upload',
);
if ($_FILES['userfile']['error']==UPLOAD_ERR_OK)
{
$uploads_dir = '/srv/www/htdocs/files/';
$tmp_name = $_FILES["userfile"]["tmp_name"];
$name = $_FILES["userfile"]["name"];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
die("complete");
}
else
{
die($errors[$_FILES['userfile']['error']]);
}
}
?>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo 200*1024*1024;?>" />
<input name="userfile" type="file" />
<input type="submit" value="Upload" />
</form>
Friday, April 02, 2010
php header for xml utf8
header('Content-Type: text/xml; charset=UTF-8');
source(s): http://www.source.com
Tuesday, March 23, 2010
List Installed Packages (with file sizes) - Ubuntu
dpkg --get-selections | awk '{printf("echo \"%s:\"`sudo aptitude show %s |grep \"Uncompressed Size:\"` \n", $1, $1 );}' >output.sh
sh output.sh| awk -F: '{printf("%s:%s\n",$1,$3);}' >list.txt
rm output.sh
Monday, February 22, 2010
ubuntu hamachi
1. Go to http://code.google.com/p/quamachi/
2. download hamachi and quamachi, ex:
http://quamachi.googlecode.com/files/quamachi-0.4.1-1.package
http://quamachi.googlecode.com/files/hamachi-0.9.9.9-20.package
3. sudo apt-get install python libqt4-core python-qt4 pyqt4-dev-tools upx-ucl grep bash make
4. chmod 777 hamachi-0.9.9.9-20.package
5. chmod 777 quamachi-0.4.1-1.package
6. sudo ./hamachi-0.9.9.9-20.package
7. sudo ./quamachi-0.4.1-1.package
Monday, January 25, 2010
VirtualBox - Start up Virtual Machine without gui
VBoxManage startvm "windows xp" --type headless
VBoxManage controlvm "windows xp" poweroff
Tuesday, January 19, 2010
virtualbox - convert img file to vdi
VBoxManage convertfromraw -format VDI [filename].img [filename].vdi
source(s): http://mdm-adph.blogspot.com/2009/05/using-img-files-with-virtualbox-to-test.html
Monday, January 18, 2010
mysql - get rid of pipe delimiter, and auto escaping
> select '\\';
\\
When using IO redirection, mysql commandline automatically enters --silent or --batch mode, and auto escapes the output. -r (--raw) is the fix.
mysql -r --silent
> select '\\';
\
mysql -r -D digicert_com < somequery.txt > Desktop/r-queries.txt
source(s): http://bugs.mysql.com/bug.php?id=35122
Tuesday, January 12, 2010
VirtualBox copy harddrive to new uuid
source(s): http://www.brianjester.us/blog/index.php?entry=entry080720-165143
Saturday, November 28, 2009
wxWidgets ubuntu linux compile unicode
sudo apt-get install wx-headers libwxbase2.8-0 libwxbase2.8-dev
g++ main.cpp `wx-config --libs` `wx-config --cxxflags`
Friday, November 27, 2009
wxWidgets Sample vcproj file | Unicode
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="utf8_basic"
ProjectGUID="{2FA27B9E-AB18-4225-BF22-3D6042C2D6B6}"
RootNamespace="utf8_basic"
Keyword="Win32Proj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories=""C:\Server\wxWidgets-2.8.10\include\msvc";"C:\Server\wxWidgets-2.8.10\include""
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;WINVER=0x0400;__WXMSW__ ;_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib rpcrt4.lib winmm.lib advapi32.lib wsock32.lib wxbase28ud.lib wxmsw28ud_core.lib"
LinkIncremental="2"
AdditionalLibraryDirectories=""C:\Server\wxWidgets-2.8.10\lib\vc_lib""
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories=""C:\Server\wxWidgets-2.8.10\include\msvc";"C:\Server\wxWidgets-2.8.10\include""
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;WINVER=0x0400;__WXMSW__ ;_WINDOWS"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="comctl32.lib rpcrt4.lib winmm.lib advapi32.lib wsock32.lib wxbase28u.lib wxmsw28u_core.lib"
LinkIncremental="1"
AdditionalLibraryDirectories=""C:\Server\wxWidgets-2.8.10\lib\vc_lib""
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\main.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>
wxWidgets | Hello World | Unicode | Visual Studio Express 2008
//Project Properties:
//http://wiki.wxwidgets.org/Microsoft_Visual_CPP_Guide
//General>Charset: Use Unicode Character Set (or ansi:not set)
//Include: "C:\Server\wxWidgets-2.8.10\include\msvc";"C:\Server\wxWidgets-2.8.10\include"
//Library: "C:\Server\wxWidgets-2.8.10\lib\vc_lib"
//[preprocessor defines:] WINVER=0x0400;__WXMSW__ ;_WINDOWS
//[linker system subsystem:] Windows (/SUBSYSTEM:WINDOWS)
//[linker libraries (all ):] comctl32.lib rpcrt4.lib winmm.lib advapi32.lib wsock32.lib
//[linker libraries (debug ):] wxbase28ud.lib wxmsw28ud_core.lib
//[linker libraries (release):] wxbase28u.lib wxmsw28u_core.lib
//File > Advanced Save Options > UTF8 with signature, CRLF
#include <wx/wx.h>
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
wxFrame *simple = new wxFrame(NULL, wxID_ANY, wxT("你好"), wxDefaultPosition, wxSize(250, 150));
simple->Centre();
simple->Show(true);
return true;
}
