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 / encryption.js
Created Jul 15, 2019 — forked from vlucas/encryption.js
Stronger Encryption and Decryption in Node.js
View encryption.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 / 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="">
<item android:id="@android:id/background">
<corners android:radius="5dp"/>
<solid android:color="#fff"/>
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)
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)
DawnImpulse /
Created Dec 17, 2018
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 / 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()
// anything you wish to do on views
deleteDialogView.findViewById( {
fun onClick(v:View) {
//your business logic
DawnImpulse / ToGson.kt
Created Nov 28, 2018
json array > gson
View ToGson.kt
Gson().fromJson("", Array<ClassName>
DawnImpulse / babel-rewire.js
Last active Oct 5, 2018
ES6 + Babel + Sinon
View babel-rewire.js
// credits -
// 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 / files.js
Created Oct 5, 2018
list all files in a directory recursively
View files.js
// credits -
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 / 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=""
android:fromXDelta="-100%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="0%"
You can’t perform that action at this time.