Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

RaviGarbuja pfieffer

🏠
Working from home
  • Kathmandu, Nepal
View GitHub Profile
View ci-android.yml
name: Android Build
on: pull_request
jobs:
build:
runs-on: ubuntu-latest
@pfieffer
pfieffer / CoroutinesSplashActivity.kt
Created Mar 18, 2020
A Splash Screen based on Kotlin Co routine which can be cancelled by the user and it would not launch the HomeActivity
View CoroutinesSplashActivity.kt
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.coroutines.*
class CoroutinesSplashActivity : AppCompatActivity() {
val activityScope = CoroutineScope(Dispatchers.Main)
override fun onCreate(savedInstanceState: Bundle?) {
@pfieffer
pfieffer / Laptop.kt
Created Mar 5, 2020
Builder Pattern demo for a model class in Kotlin
View Laptop.kt
class Laptop(builder: Builder) {
private val processor: String = builder.processor
private val ram: String = builder.ram
private val battery: String = builder.battery
private val screenSize: String = builder.screenSize
// Builder class
class Builder(processor: String) {
var processor: String = processor // this is necessary
@pfieffer
pfieffer / Circle.java
Last active Mar 5, 2020
FacadePatternDemo.java
View Circle.java
public class Circle implements Shape {
@Override
public void draw() {
System.out.println("Circle::draw()");
}
}
@pfieffer
pfieffer / BuilderDemo.java
Last active Mar 5, 2020
Builder Pattern Demo
View BuilderDemo.java
// Java code to demonstrate Builder Pattern
// Server Side Code
final class Student {
// final instance fields
private final int id;
private final String name;
private final String address;
@pfieffer
pfieffer / change_owner_and_permissions.sh
Last active Nov 1, 2019
Change the owner and permsissions to troubleshoot issues with localhost on Linux
View change_owner_and_permissions.sh
$ ls -dl ~/files
drwx------ 9 root root 4096 2009-04-06 15:56 files
$ sudo chown grunt547:grunt547 ~/files
[sudo] password for grunt547:
$ chmod 755 ~/files
$ ls -dl ~/files
drwxr-xr-x 9 grunt547 grunt547 4096 2009-04-06 15:56 files
@pfieffer
pfieffer / FriendlyTimeExtension.kt
Created Oct 3, 2019
Get time in user friendly format. Extension function on top of Long class.
View FriendlyTimeExtension.kt
fun Long.getFriendlyTime(): String {
val dateTime = Date(this * 1000)
val sb = StringBuffer()
val current = Calendar.getInstance().time
var diffInSeconds = ((current.time - dateTime.time) / 1000).toInt()
val sec = if (diffInSeconds >= 60) (diffInSeconds % 60) else diffInSeconds
diffInSeconds /= 60
val min = if (diffInSeconds >= 60) (diffInSeconds % 60) else diffInSeconds
diffInSeconds /= 60
@pfieffer
pfieffer / NetworkHelper.java
Last active Nov 1, 2019
To find if the Android Device is connected to the internet or not
View NetworkHelper.java
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
public class NetworkHelper {
public static final boolean hasNetworkAccess(Context context){
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
try {
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
return networkInfo != null && networkInfo.isConnectedOrConnecting();
@pfieffer
pfieffer / Hex values according to percentage.txt
Last active Nov 1, 2019
ARGB where A = Alpha. Opacity levels according to percentage
View Hex values according to percentage.txt
E.g. for 50% white you'd use #80FFFFFF
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
View logout.php
<?php
//For connecting the database-->
$link = mysqli_connect("localhost","root","", "practise");
if (!$link) {
die("Connection failed: " . mysql_error());
}else{
mysqli_select_db ($link, 'practise') or die ("Could not select database.");
}
//Start session