Skip to content

Instantly share code, notes, and snippets.

View PasanBhanu's full-sized avatar

Pasan Bhanu Guruge PasanBhanu

View GitHub Profile
@PasanBhanu
PasanBhanu / FCS.cs
Last active August 26, 2021 23:53
Frame Check Sequence Algorithm for DLMS Protocol (C# Code)
public class LECO_DLMS_FCS
{
static ushort[] fcstab = new ushort[256]
{
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
@PasanBhanu
PasanBhanu / CheckNetwork.java
Last active July 25, 2023 13:28
Check Internet Connection in Android (API Level 29) Using Network Callback
/*
You need to call the below method once. It register the callback and fire it when there is a change in network state.
Here I used a Global Static Variable, So I can use it to access the network state in anyware of the application.
*/
// You need to pass the context when creating the class
public CheckNetwork(Context context) {
this.context = context;
}
@PasanBhanu
PasanBhanu / AndroidDownloadImage.java
Created September 26, 2019 09:04
Download Image from URL and Added to Gallery - Android (Java)
/*
This method can be used to download an image from the internet using a url in Android. This use Android Download Manager to
download the file and added it to the Gallery. Downloaded image will be saved to "Pictures"
Folder in your internal storage
*/
private void downloadImageNew(String filename, String downloadUrlOfImage){
try{
DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
Uri downloadUri = Uri.parse(downloadUrlOfImage);
@PasanBhanu
PasanBhanu / SendSMS.php
Last active July 4, 2021 08:16
Send SMS in PHP Application with Newsletters.lk SMS API Sri Lanka
<?php
$client = new \GuzzleHttp\Client();
$url = "https://app.newsletters.lk/smsAPI?sendsms";
$body['apikey'] = "YOUR_API_KEY";
$body['apitoken'] = "YOUR_API_TOKEN";
$body['type'] = "sms";
$body['from'] = "My Sender ID";
$body['to'] = "94711234567"; // Receiver Mobile No with Country Code
$body['text'] = "Your SMS";