Skip to content

Instantly share code, notes, and snippets.

View Pavneet-Sing's full-sized avatar
🎯
Focusing | Open to remote work

Pavneet Singh Pavneet-Sing

🎯
Focusing | Open to remote work
View GitHub Profile
@Pavneet-Sing
Pavneet-Sing / App.js
Last active October 26, 2020 01:08
To efficiently implement the array update events in React
import React, { Component } from "react";
import "./style.css";
export default class App extends Component {
state = {
cart: ["Corn", "Potato"],
};
addNewItem = () => {
this.setState((prevState) => ({
<person version="1.0" encoding="utf-8">
<fname>Pavneet</fname>
<lname>Singh</lname>
<contacts>
<personal>
<phone>12345678900</phone>
</personal>
</contacts>
</person>
<?xml version="1.0" encoding="utf-8"?>
<person>
<fname>Pavneet</fname> <!--first name-->
<lname>Singh</lname> <!--last name-->
<contacts>
<personal>
<phone>12345678900</phone>
</personal>
</contacts>
</person>
{
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
@Pavneet-Sing
Pavneet-Sing / TimeStampClock.dart
Last active September 13, 2020 09:50
Clock TimeStamp recorder in flutter
import 'dart:async';
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MaterialApp(
theme: ThemeData.light().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
// Person class with occupation as nullable property using ?
data class Person(
@JsonProperty("name") val name: String,
@JsonProperty("occupation") val occupation: String? // nullable
)
// import com.fasterxml.jackson.module.kotlin.registerKotlinModule
// import com.fasterxml.jackson.databind.ObjectMapper
val mapper = ObjectMapper().registerKotlinModule()
println(mapper.readValue(dataJSONStr, Person::class.java))
// Simple kotlin class without data keyword
class Person{
lateinit var name: String
var occupation: String? = null
}
//JsonProperty to allow Jackson to use setters and getters
data class Person(
@JsonProperty("name") val name: String,
@JsonProperty("occupation") val occupation: String
)
@Pavneet-Sing
Pavneet-Sing / Person.kt
Last active May 6, 2020 17:47
Data class for Person object entity
data class Person(var name: String, var occupation: String)