Skip to content

Instantly share code, notes, and snippets.

View DawnImpulse's full-sized avatar

Saksham Khurana DawnImpulse

View GitHub Profile
{
	"rest" : {
		"query: {
			"lang" : "",
			"map" : "",
			"name" : "",
			"age" : 2
		}
	}
@DawnImpulse
DawnImpulse / mutablelivedata.kt
Created March 7, 2020 14:51
init mutable live data by lazy
private val randomImages : MutableLiveData<List<ObjectImage>> by lazy {
MutableLiveData<List<ObjectImage>>().also {
GlobalScope.launch {
CtrlImage.random(limit)
}
}
}
@DawnImpulse
DawnImpulse / live.kt
Created March 7, 2020 14:16
a live variable of any type in kotlin which actively listens and propagates change to it
package com.dawnimpulse.wallup.utils.reusables
import kotlin.properties.Delegates
class Live<T>(private val value1: T) {
private lateinit var change: (T) -> Unit
var value: T by Delegates.observable(value1) { _, _, new ->
if (::change.isInitialized)
change(new)
@DawnImpulse
DawnImpulse / suspend.kt
Created February 28, 2020 05:46
suspending kotlin coroutine
suspend fun setValue(ref: DatabaseReference, value: Any) = suspendCoroutine<Boolean> { continuation ->
ref.setValue(value)
.addOnSuccessListener {
continuation.resume(true)
}
.addOnFailureListener {
continuation.resumeWithException(it)
}
}
@DawnImpulse
DawnImpulse / .mocharc.yaml
Created December 20, 2019 11:23
mocha config file
# This is an example Mocha config containing every Mocha option plus others
allow-uncaught: false
async-only: false
bail: false
check-leaks: false
color: true
delay: false
diff: true
exit: false # could be expressed as "no-exit: true"
extension:
@DawnImpulse
DawnImpulse / riteway.js
Created December 19, 2019 07:49
riteway + @hapi/joi
describe("uuid()", async (assert) => {
assert({
given: "nothing",
should: "generate a 32 chars alphanumeric string",
actual: validate(
generate.uuid(),
Joi.string()
.alphanum()
.length(32),
),
@DawnImpulse
DawnImpulse / location.kt
Created September 21, 2019 09:43
Get fine location android
locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10f, LocationListenerCallback)
} else if (F.isConnected(this)) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 10f, LocationListenerCallback)
} else
@DawnImpulse
DawnImpulse / encryption.js
Created July 15, 2019 17:53 — forked from vlucas/encryption.js
Stronger Encryption and Decryption in Node.js
'use strict';
const crypto = require('crypto');
const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bits (32 characters)
const IV_LENGTH = 16; // For AES, this is always 16
function encrypt(text) {
let iv = crypto.randomBytes(IV_LENGTH);
let cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(ENCRYPTION_KEY), iv);
@DawnImpulse
DawnImpulse / gradient_progress.xml
Last active November 23, 2020 03:06
Creating gradient drawable for progress bar in android
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="5dp"/>
<solid android:color="#fff"/>
</shape>
</item>
@DawnImpulse
DawnImpulse / dynamicHeight.kt
Created May 6, 2019 08:05
Calculate dynamic height for content on screen
// get height based on screen width
fun getDynamicHeight(context: Context, width: Int, height: Int): Int {
val point = displayDimensions(context)
val h = ((point.x - dpToPx(16, context)) * height) / width
return if (h > (point.y - dpToPx(48, context)))
point.y - dpToPx(48, context)
else
h
}