Skip to content

Instantly share code, notes, and snippets.

@MohitSharma0101
MohitSharma0101 / content.jsx
Created May 9, 2024 14:38
Add React Component in html string using parser
import parse, { Element } from "html-react-parser";
import { TestCard } from "./test-card";
function addTestCard(html: string): string {
// Define a regular expression pattern to match [template id="some-id-in-number"]
const templateRegex = /\[template id="(\d+)"]/g;
const replacedHTML = html.replace(templateRegex, (match, id) => {
return `<div id="test_card" tag=${id} />`;
});
@MohitSharma0101
MohitSharma0101 / Material Input in Pure CSS.css
Created November 5, 2022 18:13
Animated Material Input in Pure CSS by ALGOPOINT
.input-wrapper {
--padding: 16px;
--focus-color: black;
position: relative;
display: flex;
align-items: center;
}
input {
padding: var(--padding);
@MohitSharma0101
MohitSharma0101 / Material Input.html
Last active November 5, 2022 15:32
HTML Structure of Material Input
<div class="input-wrapper">
<input type='text' id='input' required ></input>
<label
for='input'
class='placeholder'>
Username
</label>
</div>
//Make sure to handle read SMS permission before calling this function
fun getSmsCountByNumber(senderNumber:String) : Int{
var totalSMS = 0
val countryCode = "+91"
applicationContext.contentResolver.query(
Telephony.Sms.CONTENT_URI,
null,
null,
object Emoji {
val smiley = getEmojiByUnicode(0x1F60A)
val heart = getEmojiByUnicode(0x2764)
val loveFace = getEmojiByUnicode(0x1F60D)
val funnyFace = getEmojiByUnicode(0x1F602)
val yummyFace = getEmojiByUnicode(0x1F60B)
val claps = getEmojiByUnicode(0x1F44F)
val fire = getEmojiByUnicode(0x1F525)
val angryFace = getEmojiByUnicode(0x1F621)
fun getAllAudioFiles(): MutableList<String> {
val songs: MutableList<String> = ArrayList()
val selection = MediaStore.Audio.Media.IS_MUSIC + " != 0"
val projection = arrayOf(
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DURATION
@MohitSharma0101
MohitSharma0101 / tryAndCatch
Created June 26, 2021 15:26
A Clean Way to write Try and Catch in Kotlin
//Demo
fun demo(){
tryAndCatch {
// doSomething()
}
}
//Utility Function for Simple Try and Catch use
fun tryAndCatch(tryThis:(()->Unit)){
try{