Skip to content

Instantly share code, notes, and snippets.

View ch8n's full-sized avatar
💻
Always on to writing my next article.

Chetan Gupta ch8n

💻
Always on to writing my next article.
View GitHub Profile
@ch8n
ch8n / transpose.py
Created August 19, 2017 18:25
Transpose of a matrix in python
def trans(m):
numRows = len(m)
numCols = len(m[0])
tMatrix = [[0 for x in range(numRows)] for y in range(numCols)]
for i in range(0,numCols):
for j in range(0,numRows):
tMatrix[i][j] = m[j][i]
return tMatrix
print(trans([[1,3,5],[2,4,6]]))
. - Any Character Except New Line
\d - Digit (0-9)
\D - Not a Digit (0-9)
\w - Word Character (a-z, A-Z, 0-9, _)
\W - Not a Word Character
\s - Whitespace (space, tab, newline)
\S - Not Whitespace (space, tab, newline)
\b - Word Boundary
@ch8n
ch8n / AlertDialogAndroidkotlinExtension.kt
Last active October 3, 2023 12:18
Android alert dialog kotlin Extension
//Utils - Declaration
object PromptUtils {
fun alertDialog(context: Context, @StyleRes style: Int, dialogBuilder: AlertDialog.Builder.() -> Unit): Dialog {
val builder = AlertDialog.Builder(context, style).also {
it.setCancelable(false)
it.dialogBuilder()
}
return builder.create()
}
@ch8n
ch8n / bottomSheet.xml
Created October 15, 2018 07:24
Android bottom sheet behaviour fix after androidx migration
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
@ch8n
ch8n / ScreenShotActivity.kt
Created October 19, 2018 05:42
ScreenShotCapture using media projection
package ch8n.project.magniffect.main.home
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.PixelFormat
import android.hardware.display.DisplayManager
import android.hardware.display.VirtualDisplay
import android.media.ImageReader
@ch8n
ch8n / AlertDialogWidthStyle.xml
Created October 24, 2018 07:04
Change alert box with using styles
<!--In style.xml -->
<style name="CustomDialog" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">@color/accent_color</item>
<item name="android:windowMinWidthMajor">@dimen/dialog_min_width_major</item>
<item name="android:windowMinWidthMinor">@dimen/dialog_min_width_minor</item>
<item name="android:windowBackground">@color/transparent</item>
</style>
<!--In dimesn.xml -->
@ch8n
ch8n / Single.kt
Created November 17, 2018 09:54
Single instance n kotlin java way
class Single private constructor(){
companion object{
@Volatile private var instance: Single? = null
fun getInstance() = instance?: synchronized(lock=this){
instance?: Single().also{
instance = it
}
}
}
@ch8n
ch8n / todo-sample.kt
Last active March 30, 2019 08:12
Medium - Kotlin do or die - TODO example
onClick(view:view) = when(view.id){
R.id.button_action1->actionOneClicked()
R.id.button_action2->actionTwoClicked()
R.id.button_action3->TODO("action 3 is work in progress!")
}
@ch8n
ch8n / todo-timebomb.kt
Created March 30, 2019 06:28
Using kotlin TODO function to time deadlines
if(Date().after(date)){
TODO("Has to complted before : $date")
}
@ch8n
ch8n / safeCommit.kt
Last active March 30, 2019 06:46
Safe todo for production and testing
fun SAFE_TODO(reason:String){
if (BuildConfig.DEBUG) {
TODO(reason)
}else{
Toast.makeText(context,"NOT_IMPLEMENYTED:$reason",Toast.LENGTH_SHORT).show()
}
}