Friday, September 27, 2013

Adding char to string in C++

I work with Eclipse & Arduino.

I want to add a char to a string. I tried to use append,insert ( yet these can not be resolved)
I tried to use += yet when i print the string it always have one char.Basically i deletes the string & writes only the new char i want to add in.
I tried moreover concat & it does the same thing.Also strcat gives me headache with the operands cause it needs a const char pointer & i want to add a char that changes.

while (theSettings.available()) {character = theSettings.read();if(character == '/')         {    // Comment - ignore this line    while(character != '\n'){        character = theSettings.read();    }} else if(isalnum(character)){  // Add a character to the description    Serial.println(character);    description +=character;    //description.concat(character);    Serial.println(description);}

It sounds like what you want (for convenience) is the String object class available with the Arduino library.
http://arduino.cc/en/Reference/StringObject

Thursday, September 26, 2013

WordPress mobile theme: WPTouch

Download: http://prefiles.com/x9lxgihalqsy/BraveNewCode.WPTouch.Pro.v3.0.8.for.WordPress.rar

Remember: this is a PLUGIN, not a theme.
Install: put extracted wptouch-pro-3 folder under plugins folder.

Tuesday, July 9, 2013

Install 64GB SD Card on Samsung Galaxy Tablet II P311x

Samsung Galaxy Tablet II P311X only support maximum 32GB external SD Card, Here is the solution that I make it support 64GB SDCard to store media & game files into external SD Card.

First of all the device must be rooted,

Download Paragon exFAT, NTFS & HFS+ from https://play.google.com/store/apps/details?id=com.paragon.mounter&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5wYXJhZ29uLm1vdW50ZXIiXQ..

, & format your sdcard with it as HFS, note: after format, this sdcard will no longer accessable by windows operation system with card reader directly.
Do NOT format this sdcard with the application in Android settings -> storage as this will format the sdcard into extfat format again.

After format, set the mount point & tick the auto-mount on boot.

Then install  “FolderMount”,
https://play.google.com/store/apps/details?id=com.devasque.fmount&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5kZXZhc3F1ZS5mbW91bnQiXQ..
I recommend you to go pro version as it can setup as many as mount point you want, the free version can only set 3 of them.

Then you can move any application/game folders which require large space with folder mount to safe the space of your internal SDCard

Wednesday, June 26, 2013

Nginx Reverse SSL Proxy with PHP

This trick introduce the way of creating nginx reverse SSL proxy that works with PHP in load balancing environment.

Example network structure

nginx_reverse_proxy

1. Nginx proxy config file for ssl connection
define upsteam in nginx.conf

upstream example.com{        ip_hash;        server 192.168.0.1:8000 max_fails=3 fail_timeout=8;        server 192.168.0.2:8000 max_fails=3 fail_timeout=8;        server 192.168.0.3:8000 max_fails=3 fail_timeout=8;}

define the example.com.conf

server {    listen       443;    server_name  example.com;    index  index.php index.html index.htm;    ssl                  on;    ssl_certificate      /etc/ssl/example.com/example.com.crt;    ssl_certificate_key  /etc/ssl/example.com/example.com.key;    ssl_protocols       SSLv3 TLSv1 TLSv1.1 TLSv1.2;    ssl_ciphers HIGH:!ADH:!MD5:!aNULL:!eNULL:!MEDIUM:!LOW:!EXP:!kEDH;    ssl_session_timeout  10m;    ssl_prefer_server_ciphers   on;    proxy_set_header Cookie $http_cookie;    location / {        proxy_pass http://example.com; #here is the upstreams that defined in upsteam block        proxy_next_upstream     error timeout invalid_header http_500;        proxy_connect_timeout   2;        proxy_set_header        Host $host;        proxy_set_header  X-Real-IP  $remote_addr;        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;        proxy_set_header        X-Forwarded-Proto https;        add_header              Front-End-Https   on;    }}

2. Web server behind the proxy
2.1. Install pecl_http extension with pecl install pecl_http. (This extension allow you to obtain headers from cgi mode, ideally for php-fpm)

2.2. In PHP script, use

if($_SERVER['HTTP_X_FORWARDED_PROTO']=='https' || (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off')){    //SSL detected}

To check if the request is from https

Friday, June 14, 2013

Get PHP function body as string

This piece of code can return the method body from a class

public static function getFunctionString($class, $function){  $func = new ReflectionMethod($class,$function);   $filename = $func->getFileName();   $start_line = $func->getStartLine();  $end_line = $func->getEndLine()-1;  $length = $end_line - $start_line;  $source = file($filename);  $body = implode("", array_slice($source, $start_line, $length));  return $body;}

When to use:

Extract the function details & execute in other another class when the function contains self::func();

Eg:

class A{   private static $var_a = 1;  public static function a(){     self::func();  }  public static function func(){     echo self::$var_a;  }}

In class B, we need to call function a from Class A

class B{   private static $var_a=2;  public static function b(){     eval(getFunctionString('A', 'a'));  }}B::b();//will output 2

Thursday, March 14, 2013

Install OSX Mountain Lion 10.8.2 on Dell Inspiron 3520 with SSD. Windows 8/OSX UEFI dual boot. 99% Working, NO DSDT REQURED!!!

About this article

This article is a complete guide of installing OSX Mountain Lion 10.8.2 on Dell Inspiron 3520 (Purchased in Jan 2013) for experimental purpose only, before read this tutorial, you would need some basic knowledge as below:

1. Bios settings
2. OSX shell
3. Encourage & Patient
4. If you received kernel panic, don’t worry, just reboot couple of times.

I do not take any responsibility for any damage may occurred to your device, & you may be out of warranty if you replace the hardware  by yourself. So please use it at your own risk. 

Hardware Specification:

Intel i5 3210M  2.5GHz 3M

6GB DDR 3 1600MHZ

1TB SATA Hard Drive

8 x DVD Writer

Intel HD 4000 Graphic

Dell 1703 mini adapter

I bought some component for upgrade

Purchased components for upgrade (Optional):

1 x 4GB DDR 3 1600 memory
http://www.amazon.co.uk/gp/product/B004ZBAP64/ref=oh_details_o01_s00_i00?ie=UTF8&psc=1

1x SATA Caddy bay to replace DVD rom +
http://www.ebay.co.uk/itm/220940775746?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

1 x Sandisk SATA III SSD
http://www.ebuyer.com/288065-sandisk-120gb-ultra-ssd-sdssdh-120g-g25

1x Atheros 9285 wifi mini card.
http://www.ebay.co.uk/itm/300708415248?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

This model of Dell 3520 is very effortless to replace components, you do not need to remove any screws on the back, all you need to do is use a flat screw driver to open the 4 holes on the top of the keyboard pad. Note: moreover you don’t have to remove the keyboard pad completely, all you need to do is replace the memory & wifi card & replace the cadday bay by remove 3 screws under the keyboard pad. I did not made a video for this section as I found this video on Youtube. NOTE: you do NOT have to add any memory, harddrive, or wifi mini card, you can use an OSX compatible USB wireless card if you wish.

http://www.youtube.com/watch?v=Nw8uptGzrTg

1. Prepare Installation Media

Buy OSX mountain lion from Mac store. Install the Unibeast to your USB driver which has storage more than 8 GB.
You probably need a working Mac OS / OSX system to complete this step.

2. Installation

Reboot after installation is complete, press F2 on Boot & switch off the “Safe boot” option, save & exit then press F12 on boot  and in legacy boot section & select boot from USB drive.

After boot from the USB with Legacy USB Disk, use disk utility to format SSD drive, install OSX on the SSD disk. The installation should be no error as Dell 3520 has a very satisfactory compatibility for OSX.

3. Install Multibeast

Use this configuration

multibeast

The reason  to install Chameleon is  Chameleon is much more easier to configure & if you did anything wrong in Clover configuration, you can easily boot up from Chameleon with legacy option.

Please do NOT install any audio/video driver from Multibeast, they are a bit outdated, download the driver  as below.

4. Install Audio/Network Drivers

There are only a few kext needs to be installed, you can install them use Kext Utility. You can download them from here:

Audio Driver: Download

Wifi Driver: OSX has native support with Atheros 9285 mini wifi card. However you do need to rollback to this IO80211Family.Kext

Battery & PS2 Controller: Download

Restart your laptop after install these Kext

If you have experience with Chameleon, you can inject the device code for video in /Extras/org.chameleon.Boot.plist, & use PCIROOT=1 to enable Lan. This will make your Graphic card, App Store work, yet Team Viewer & iMessage will not work we use Clover.

This is my version of org.chameleon.Boot.plist

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>EthernetBuiltIn</key><string>Yes</string><key>GenerateCStates</key><string>Yes</string><key>GeneratePStates</key><string>Yes</string><key>GraphicsEnabler</key><string>Yes</string><key>Graphics Mode</key><string>1366x768x32</string><key>Kernel</key><string>mach_kernel</string><key>Kernel Flags</key><string>darkwake=0 PCIRootUID=1</string><key>Legacy Logo</key><string>Yes</string><key>Timeout</key><string>2</string><key>UseKernelCache</key><string>Yes</string><key>device-properties</key><string>7f0000000100000001000000730000000200000002010c00d041030a000000000101060000027fff04002c0000004100410050004c002c00690067002d0070006c006100740066006f0072006d002d006900640000000800000003006601140000006800640061002d0067006600780000000d0000006f6e626f6172642d31</string></dict></plist>

NOTE: DO NOT USE GraphicsEnabler=Yes before you put the inject the device code, otherwise you will obtain a black screen after reboot

So far, you should have a working OSX installed, graphic card, network access, audios works etc.

Next we will need to install Clover & enable dual boot

5. Install Clover

Download Clover from http://sourceforge.net/projects/cloverefiboot/ and install as “Unpack” to your OSX disk.
Next you need to mount the EFI drive to a folder.

Open Application->Utilities->Terminal & input

mkdir ~/efisudo mount_msdos /dev/disk0s1 /Users/saga/eficp -R /EFI ~/efi/

modify ~/efi/EFI/config.plist with text editor
This is my config.plist file

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>ACPI</key><dict><key>DsdtName</key><string>dsdt.aml</string></dict><key>Graphics</key><dict><key>CustomEDID</key><string>00FFFFFFFFFFFF0030E4DC020000000000140104902213780A09159D5F599B2719505400000001010101010101010101010101010101B01D56C650002A302430350058C210000019EC1356C650002E302430350058C210000019000000FE00394858584A803135365748340A0000000000004131960100000001010A202000F7</string><key>GraphicsInjector</key><string>Yes</string><key>InjectEDID</key><string>Yes</string><key>VRAM</key><string>512</string></dict><key>PCI</key><dict><key>DeviceProperties</key><string>7f0000000100000001000000730000000200000002010c00d041030a000000000101060000027fff04002c0000004100410050004c002c00690067002d0070006c006100740066006f0072006d002d006900640000000800000003006601140000006800640061002d0067006600780000000d0000006f6e626f6172642d31</string><key>HDAInjection</key><string>No</string><key>LpcTune</key><string>No</string><key>PCIRootUID</key><string>1</string><key>StringInjector</key><string>Yes</string><key>USBInjection</key><string>No</string></dict><key>SMBIOS</key><dict><key>BiosVendor</key><string>Apple Inc.</string><key>BiosVersion</key><string>CHANGEME</string><key>Board-ID</key><string>CHANGEME</string><key>Family</key><string>MacBook Pro</string><key>ProductName</key><string>MacBookPro6,2</string><key>SerialNumber</key><string>CHANGEME</string></dict><key>SystemParameters</key><dict><key>DefaultBootVolume</key><string>CHANGEME</string><key>InjectSystemID</key><string>Yes</string><key>LegacyBoot</key><string>PBR</string><key>boot-args</key><string>npci=0x2000 slide=0 darkwake=0 PCIRootUID=1</string><key>prev-lang:kbd</key><string>en:0</string></dict></dict></plist>
you need to alter DefaultBootVolume to the volume of your OSX.Also you need to obtain the legal information for the OSX such as bios version or serial number, you can use other software to generate it.

IMPORTANT For Dual BOOT

Download these files & copy them to ~/efi/EFI/drivers64/ , This contains HFS & NTFS driver for clover, they are not included in Clover installer by default.

http://adfoc.us/1350271

Open ~/efi/EFI/BOOT/refit.conf

this is my configure file

## refit.conf# Configuration file for the rEFIt boot menu## Set desired screen resolution if enabledscreen_resolution 1366x768# Timeout in seconds for the main menu screen.# Commenting the timeout option or setting it to -1# disables automatic booting (i.e., no timeout).# Setting it to 0 enables direct boot to default volume.# timeout 5 - enter menu & wait for 5 sec to boot default Volume# timeout 0 - boot into default volume without GUI# timeout -1 - enter GUI without default booting#timeout 5# Mouse pointer settings:# Set mousespeed to adjust mouse cursor sensitivity.# Common values are between 2-8.# To disable mouse, set mousespeed to 0.mousespeed 0#mousemirrordblclick 500# Disable menu options for increased security. These are intended for a lab# environment where the administrator doesn't want users to mess with the# operating system. List the names for the options you want to hide from# the boot menu. Currently supported:#  shell       - remove the EFI shell#  tools       - remove all EFI tools (shell & gptsync)#  optical     - no booting from optical drives#  external    - no booting from external disks or USB flash drives#  internal    - no booting from internal disks; this setting is not#                 recommended because it locks you out of all operating#                 systems installed on the internal complex disks.#  singleuser  - remove the submenu options to boot Mac OS X in single-user#                 or verbose modes#  hwtest      - remove the submenu option to run Apple Hardware Test#  all         - all of the above, except for 'internal'##disable external optical shell singleuser# THEME SET#theme metaltheme mrengles# Hide volumes. Moved here from config.plist# Available options:#  hidevolumes osx osxinstall recovery duplicate#		windowsefi opticaluefi internaluefi externaluefi legacy#		grub gentoo redhat ubuntu mint fedora suse# It is moreover possible to hide volumes by device path, GUID, or# any subtring found in device path# Look into your boot.log to find a string like that:#  hidevolumes HD(1,MBR,0x223EE178,0x1,0x6689F)# be sure the string is unique#hidevolumes fedorahidevolumes legacyhidevolumes duplicatehidevolumes recoveryhidevolumes internaluefihidevolumes externaluefi# Disable display of text-mode output when in graphics mode. This# option is unnecessary on Macs, yet without this option, UEFI-based# PCs tend to display text-mode messages relating to boot loader probing# over the GUI display.#quiet# Enable the use of the log file (for debug purpose)# This will make boot process much slower, so it should be stay disabled in most cases.# Log will be outputted to /EFI/misc/# Make sure /EFI/misc/ directory exists when enabling this.#systemlog# List legacy options first. When enabled, legacy BIOS based boot options# (e.g. Windows, Linux via LILO or GRUB) will be listed first. This is# intended as a quick fix to alter the default boot choice until full# configurability arrives.##legacyfirst# EOF

6. Change Bios Setting to add UEFI option & boot from Clover

In Dell 3520 bios , you are able to add additional UEFI boot file without using EFI Shell, which you can add Clover to your bios boot list easily. Simply select add UEFI boot file in bios setting & select the SSD disk -> /EFI/BOOT/CLOVERX64.efi, donate it a name “Clover UEFI” or whatever, alter the boot sequence in UEFI boot section, make it on the top of the list, save & exit. You will find on your next boot you will find the Clover boot loader screen & your OSX driver is selected as default boot device.

Finally you received a 99% working OSX working on DELL inspiron 3520, the only thing not working is the sleep, however you may resolve it with DSDT yet this will not be introduced in this tutorial.

Saturday, February 2, 2013

Phonegap Sqlite (android)

Below Android environment use Phonegap operates Sqlite, code sees accessory.

(function(){$('#main').live('pageshow',function(){$('#createBtn').bind('click',function(){create('test','1.0','testDb',1000000);});$('#DropBtn').bind('click',function(){dropTable('DEMO','test','1.0','testDb',1000000);});$('#selectBtn').bind('click',function(){select('test','1.0','testDb',1000000);});$('#insertBtn').bind('click',function(){$('#addWindow').popup('open');});$('#saveBtn').bind('click',onSaveBtnClick);$('#deleteBtn').bind('click',onDeleteBtnClick);});function onSaveBtnClick(){var id = $('#idfield').val();var data = $('#datafield').val();if(id!=''&& data!=''){var db = getDb('test','1.0','testDb',1000000);db.transaction(function(tx){tx.executeSql('INSERT INTO DEMO (id, data) VALUES (?, ?)', [id,data]);}, errorCB, function(){$('#addWindow').popup('close');Alert(' adds successful'); newly$('#selectBtn').trigger('click');$('#msgdiv').empty();$('#idfield').val('');$('#datafield').val('');});}else{$('#msgdiv').text(' inputs Idand Data please! ! ');}}function onDeleteBtnClick(){var db = getDb('test','1.0','testDb',1000000);db.transaction(function(tx){tx.executeSql('DELETE FROM DEMO');}, errorCB, function(){Alert(' deletes overall recordsuccessfully! ');$('#resultList > tbody').empty();});}function getDb(dbName,dbVersion,dbDisplayname,dbSize){return window.openDatabase(dbName, dbVersion,dbDisplayname, dbSize);}function select(dbName,dbVersion,dbDisplayname,dbSize){var db = getDb(dbName,dbVersion,dbDisplayname,dbSize);db.transaction(queryDB, errorCB);}function dropTable(tableName,dbName,dbVersion,dbDisplayname,dbSize){var db = getDb(dbName,dbVersion,dbDisplayname,dbSize);db.transaction(function(tx){tx.executeSql('DROP TABLE IF EXISTS '+tableName);}, errorCB,function(){Alert(' deletes a success,tableName='+tableName);$('#resultList > tbody').empty();});}function queryDB(tx) {$('#resultList > tbody').empty();tx.executeSql('SELECT * FROM DEMO', [], function (tx, results) {var len = results.rows.length;var html = [];for (var i=0; i tbody').append($(html.join('')));},errorCB);}function create(dbName,dbVersion,dbDisplayname,dbSize){var db = getDb(dbName,dbVersion,dbDisplayname,dbSize);db.transaction(function(tx){tx.executeSql('DROP TABLE IF EXISTS DEMO');tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');Tx.executeSql('INSERTINTO DEMO (Id, data) VALUES (3, "Phonegap Sqlitechecks ")'); } , errorCB, function(){Alert(' establishs asuccess, dbName='+dbName);$('#selectBtn').trigger('click');});}function errorCB(err) {alert("Error processing SQL: "+err.code);}})();