Skip to content

Instantly share code, notes, and snippets.

View pfieffer's full-sized avatar
🦉
Working :/

Ravi Garbuja Pun pfieffer

🦉
Working :/
View GitHub Profile
@pfieffer
pfieffer / app_version.gradle
Created July 5, 2023 06:35 — forked from IlyaEremin/app_version.gradle
Npm version for gradle
def getVersionName = { getVersionProps()['appVersionName'] }
def getVersionProps() {
def versionPropsFile = file('gradle.properties')
if (!versionPropsFile.exists()) {
versionPropsFile.createNewFile()
}
def versionProps = new Properties()
versionProps.load(new FileInputStream(versionPropsFile))
return versionProps
name: Android Build
on: pull_request
jobs:
build:
runs-on: ubuntu-latest
@pfieffer
pfieffer / CoroutinesSplashActivity.kt
Created March 18, 2020 11:41
A Splash Screen based on Kotlin Co routine which can be cancelled by the user and it would not launch the HomeActivity
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 March 5, 2020 10:57
Builder Pattern demo for a model class in Kotlin
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 March 5, 2020 11:20
FacadePatternDemo.java
public class Circle implements Shape {
@Override
public void draw() {
System.out.println("Circle::draw()");
}
}
@pfieffer
pfieffer / BuilderDemo.java
Last active March 5, 2020 10:56
Builder Pattern Demo
// 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 November 1, 2019 06:52
Change the owner and permsissions to troubleshoot issues with localhost on Linux
$ 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 October 3, 2019 09:46
Get time in user friendly format. Extension function on top of Long class.
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 November 1, 2019 06:54
To find if the Android Device is connected to the internet or not
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 October 20, 2022 05:19
ARGB where A = Alpha. Opacity levels according to percentage
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