Skip to content

Instantly share code, notes, and snippets.

View DawnImpulse's full-sized avatar

Saksham Khurana DawnImpulse

View GitHub Profile
@DawnImpulse
DawnImpulse / saveImage.kt
Created January 29, 2019 11:15
Save bitmap in internal storage
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 December 17, 2018 09:34
All storage devices on Android
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 December 12, 2018 10:04
Custom dialog box
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 November 28, 2018 15:00
json array > gson
Gson().fromJson("", Array<ClassName>::class.java))
@DawnImpulse
DawnImpulse / babel-rewire.js
Last active October 5, 2018 16:02
ES6 + Babel + Sinon
// 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 October 5, 2018 05:33
list all files in a directory recursively
// 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 September 23, 2018 07:21
android transition animations
<?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 September 20, 2018 05:14
sort custom collections
// 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
}
@DawnImpulse
DawnImpulse / tag.xml
Created September 20, 2018 05:12
tag layout
// creating a layout which wrap image view based on text width
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txt"
@DawnImpulse
DawnImpulse / caps.kt
Created September 8, 2018 14:54
first letter capital
fun capWord(string: String): String {
val result = StringBuilder(string.length)
val words = string.split("\\ ".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
for (i in words.indices) {
result.append(Character.toUpperCase(words[i][0])).append(words[i].substring(1)).append(" ")
}
return result.toString()
}