Share Coding

Tutorials, Problems, Stuffs …

Cannot SSH while server connected VPN

Esxi 5.0 Server has a CentOS vm.
Once it connected outside VPN, it then cannot SSH because they are not the same gateway.
So we need to add route to whitelist our host IP to connect our gateway first.

Assume our gateway is 192.168.1.1, and we would like to allow all my subnetwork to pass through:

route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1

ACR122U FeliCa Reader with Raspberry Pi

apt-get install flex libpcsclite-dev libusb-dev checkinstall libusb-0.1-4 libpcsclite1 libccid pcscd pcsc-tools libcurl4-openssl-dev

 

wget http://www.acs.com.hk/drivers/eng/ACR122_Driver_Lnx_Mac10.5_10.6_10.7_104_P.zip
unzip ACR122_Driver_Lnx_Mac10.5_10.6_10.7_104_P.zip
cd ACR122_Driver_Lnx_Mac10.5_10.6_10.7_104_P
tar -jxvf acsccid-1.0.4.tar.bz2
cd acsccid-1.0.4
./configure
make
checkinstall -D -y –install

 

Download libnfc (1.7.1)
cd libnfc-1.7.1
./configure --prefix=/usr --sysconfdir=/etc --with-drivers=acr122_pcsc
make
make install
/sbin/ldconfig

 

reboot
pcsc_scan
nfc-list
nfc-poll

 


 

// If error message appear
No NFC device found.

 

// Use dmesg to check error
usb 2-1.2: usbfs: interface 0 claimed by pn533 while 'nfc-list' sets config #1

 

// Solution: Create /etc/modprobe.d/blacklist-libnfc.conf and type
blacklist pn533
blacklist nfc

 

// Save and run
modprobe -r pn533 nfc
reboot

Photobucket Album Downloader v2.0.1

To all who interested on my Photobucket Album Downloader Extension,

I am glad to introduce you the new Photobucket Album Downloader v2.0.1 extension.
Free version: http://goo.gl/2aGxLC
Unlimit version: http://goo.gl/1IFGwh

 

New features are listing below:
1. No longer rely on any server, no more SSL or speed issues.
2. No longer use popup dialog, it now embeds a “Download” button on photobucket website.
How to upgrade extension version:
1. Enter “chrome://extensions” on your chrome browser
2. Click “Update Extension” on the top right hand side
3. Done
Steps of downloading album: 
1. Go to any album, such as: http://s237.photobucket.com/user/bekadrk89/library/Photography
2. Find the Panel “Links to share this album” on the right and you can see a “Download” button
3. Click the “Download” button and you are now downloading photos

jQuery AJAX upload file

HTML form:

<form id="uploadForm">
	<input type="file" name="attachement" />
</form>

 

Javascript(jQuery):

$.ajax({
	type: "POST",
	url: "upload.php",
	data: new FormData($('#uploadForm')[0]),
	cache: false,
	contentType: false,
	processData: false,
	success: function (result) {
		console.log(result);
	}
});

Android WebView Upload Picture via Camera

When clicking an Input File button on webview,
we want to take a picture from camera and place the image to that input.

1. Declare instance variables

private final static int CAPTURE_RESULTCODE = 1;
private ValueCallback<Uri> mUploadMessage;
private String filePath;

2. Set custom webChromeClient to WebView

myWebView.setWebChromeClient(new WebChromeClient() {				
	@SuppressWarnings("unused")
	public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
		openFileChooser(uploadMsg);
	}

	@SuppressWarnings("unused")
	public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) {
		openFileChooser(uploadMsg);
	}

	public void openFileChooser(ValueCallback<Uri> uploadMsg) {
		this.mUploadMessage = uploadMsg;

		File imageStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "appName");
		this.filePath = imageStorageDir + File.separator + "IMG_" + String.valueOf(System.currentTimeMillis()) + ".jpg";
		File file = new File(this.filePath);

		Intent captureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
		captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
		MainActivity.this.startActivityForResult(captureIntent,  CAPTURE_RESULTCODE); 
	}
});

3. Apply onActivityResult to handle the picture after capture

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
	if (requestCode == CAPTURE_RESULTCODE) {
		if (null == this.mUploadMessage || (resultCode != RESULT_OK && !new File(filePath).exists())) {
			this.mUploadMessage.onReceiveValue(null);
		} else {
			ContentValues values = new ContentValues();
			values.put(MediaStore.Images.Media.DATA, this.filePath);
			this.mUploadMessage.onReceiveValue(this.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values));
		}
		this.mUploadMessage = null;
	}
}