Share Coding

Tutorials, Problems, Stuffs …

ACR122U FeliCa Reader with Raspberry Pi

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

 

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

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);
	}
});

[joda time] Convert timestamp into “Posted 3 minutes ago”

DateTimeZone.setDefault(DateTimeZone.UTC);
DateTime myBirthDate = new DateTime(comment.getTime()*1000);
DateTime now = new DateTime();
Period period = new Period(myBirthDate, now);
Log.d("period",period.toString());

PeriodFormatterBuilder builder = new PeriodFormatterBuilder();
if(period.getYears() != 0) {
	builder.appendYears().appendSuffix(" years ago\n");
} else if(period.getMonths() != 0) {
	builder.appendMonths().appendSuffix(" months ago\n");
} else if(period.getDays() != 0) {
	builder.appendDays().appendSuffix(" days ago\n");
} else if(period.getHours() != 0) {
	builder.appendHours().appendSuffix(" hours ago\n");
} else if(period.getMinutes() != 0) {
	builder.appendMinutes().appendSuffix(" minutes ago\n");
} else if(period.getSeconds() != 0) {
	builder.appendSeconds().appendSuffix(" seconds ago\n");
}
PeriodFormatter formatter = builder.printZeroNever().toFormatter();
String elapsed = formatter.print(period);

TextView txtComment_time = (TextView) comment_list_item.findViewById(R.id.txtComment_time);
txtComment_time.setText(elapsed);

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;
	}
}
Follow

Get every new post delivered to your Inbox.