Skip to content

Instantly share code, notes, and snippets.

Saksham Khurana DawnImpulse

Block or report user

Report or block DawnImpulse

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@DawnImpulse
DawnImpulse / gradient_progress.xml
Last active May 12, 2019
Creating gradient drawable for progress bar in android
View gradient_progress.xml
<?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
Calculate dynamic height for content on screen
View dynamicHeight.kt
// 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
}
@DawnImpulse
DawnImpulse / saveImage.kt
Created Jan 29, 2019
Save bitmap in internal storage
View saveImage.kt
fun storeImage(image: Bitmap): Uri? {
var pictureFile: File = File(Environment.getExternalStorageDirectory().path + "/Folder")
val timeStamp = SimpleDateFormat("yyyy-MM-dd_HHmm").format(Date())
val name = "$timeStamp.jpg"
pictureFile = File(pictureFile.path + File.separator + name)
try {
val fos = FileOutputStream(pictureFile)
image.compress(Bitmap.CompressFormat.JPEG, 90, fos)
fos.close()
@DawnImpulse
DawnImpulse / ExternalStorage.java
Created Dec 17, 2018
All storage devices on Android
View ExternalStorage.java
public class ExternalStorage {
public static final String SD_CARD = "sdCard";
public static final String EXTERNAL_SD_CARD = "externalSdCard";
/**
* @return True if the external storage is available. False otherwise.
*/
public static boolean isAvailable() {
String state = Environment.getExternalStorageState();
@DawnImpulse
DawnImpulse / dialog.kt
Created Dec 12, 2018
Custom dialog box
View dialog.kt
val factory = LayoutInflater.from(this)
val deleteDialogView = factory.inflate(R.layout.mylayout, null)
val deleteDialog = AlertDialog.Builder(this).create()
deleteDialog.setView(deleteDialogView)
// anything you wish to do on views
deleteDialogView.findViewById(R.id.yes).setOnClickListener(object:OnClickListener() {
fun onClick(v:View) {
//your business logic
deleteDialog.dismiss()
}
@DawnImpulse
DawnImpulse / ToGson.kt
Created Nov 28, 2018
json array > gson
View ToGson.kt
Gson().fromJson("", Array<ClassName>::class.java))
@DawnImpulse
DawnImpulse / babel-rewire.js
Last active Oct 5, 2018
ES6 + Babel + Sinon
View babel-rewire.js
// credits - https://github.com/sinonjs/sinon/issues/1358#issuecomment-288566305
// first install babel-plugin-rewire
// then add plugin to .babelrc as
// "plugins" : ["rewire"]
import token, {clientToken} from '../../../../app/util/token'
import * as esat from 'esat'
import * as proxyquire from 'proxyquire'
@DawnImpulse
DawnImpulse / files.js
Created Oct 5, 2018
list all files in a directory recursively
View files.js
// credits - https://www.codexpedia.com/node-js/node-js-getting-files-from-a-directory-including-sub-directories/
var fs = require('fs');
var path = require('path');
// Return a list of files of the specified fileTypes in the provided dir,
// with the file path relative to the given dir
// dir: path of the directory you want to search the files for
// fileTypes: array of file types you are search files, ex: ['.txt', '.jpg']
@DawnImpulse
DawnImpulse / enter_from_left.xml
Created Sep 23, 2018
android transition animations
View enter_from_left.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="200"/>
</set>
@DawnImpulse
DawnImpulse / collections.kt
Created Sep 20, 2018
sort custom collections
View collections.kt
// this will be a descending sort
fun sortLabels(labels: List<FirebaseVisionLabel>): List<FirebaseVisionLabel> {
Collections.sort(labels) { o1, o2 ->
o2.confidence.compareTo(o1.confidence)
}
return labels
}
You can’t perform that action at this time.