Skip to content

Instantly share code, notes, and snippets.

View Debashis-Sinha's full-sized avatar

Debashis Sinha Debashis-Sinha

  • Kolkata, India
View GitHub Profile
private fun isOnline(context: Context): Boolean {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val n = cm.activeNetwork
if (n != null) {
val nc = cm.getNetworkCapabilities(n)
return nc!!.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) || nc.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
}
return false
}
@Debashis-Sinha
Debashis-Sinha / MyWebViewClient.java
Created February 27, 2019 06:19
Android open allowed link only
@SuppressWarnings("deprecation")
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Uri uri = Uri.parse(url);
if (uri.getHost() != null && uri.getHost().contains("example.com")) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
view.getContext().startActivity(intent);
@Debashis-Sinha
Debashis-Sinha / gist:36cfe44ce4ae92c56a39a59fdaa9cd27
Created August 27, 2018 02:09
Open new activity from notification action using intent
private void openNewActivity(String title, String description){
Intent testIntent = new Intent(this,TestActivity.class);
testIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent pen = PendingIntent.getActivity(this,15,testIntent,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle(title)
.setContentText(description)
.setSmallIcon(R.mipmap.ic_launcher)
.setOngoing(true)
.addAction(R.drawable.ic_play, "Test", pen)
@Debashis-Sinha
Debashis-Sinha / ShowNotification
Created August 12, 2018 06:07
Android show notification
private void sendNotification(String messageBody, String webUrl) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("targetLink",webUrl);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(getString(R.string.app_name))
@Debashis-Sinha
Debashis-Sinha / getYoutubeId.php
Created July 16, 2017 07:45
php get youtube video id from youtube video url
/**
* getYoutubeId
* @par string $video_url
*/
public function getYoutubeId( $url )
{
// http://stackoverflow.com/a/10315969/2252921
preg_match('/^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/', $url, $founded);
return !empty( $founded ) ? $founded[1] : '';
}
@Debashis-Sinha
Debashis-Sinha / getExtension.php
Created July 16, 2017 07:45
php get file extension name
/**
* Get file extension
* @param $filePath
* @return string
*/
public function getExtension( $filePath )
{
if( strpos( $filePath, '.' ) === false ){
return '';
}
@Debashis-Sinha
Debashis-Sinha / secondsToTime.php
Created July 16, 2017 07:43
php seconds to time
/**
* Seconds to time
* @param $sec
* @return string
*/
static function secondsToTime( $sec ){
if( !is_float( $sec ) ) $sec = floatval( $sec );
$hours = floor($sec / 3600);
$minutes = floor(($sec - ($hours * 3600)) / 60);
$seconds = $sec - ($hours * 3600) - ($minutes * 60);
@Debashis-Sinha
Debashis-Sinha / php _get_file_size_from_byte.php
Last active July 16, 2017 07:40
php get file size from byte
/**
* @param $bytes
* @param string $unit
* @param int $decimals
* @return string
*/
static function sizeFormat($bytes, $unit = "", $decimals = 2)
{
$units = array('B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4, 'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8);
$value = 0;
@Debashis-Sinha
Debashis-Sinha / pagination_config.php
Created June 12, 2016 09:55
Codeigniter pagination config settings for Twitter Bootstrap 3.3.6
$config['base_url'] = base_url() . 'controller/method/';
$config['total_rows'] = $this->Model->totalRowNoCount();// Total row count
$config['per_page'] = 2;
$config['prev_link'] = '«';
$config['next_link'] = '»';
$config['first_link'] = '';
$config['last_link'] = '';
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['prev_tag_open'] = '<li>';