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 / tsconfig.ts
Created May 12, 2019 19:21
Typescripyt config file
{ "compilerOptions": {
/* Basic Options */
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
@ch8n
ch8n / package.json
Created May 12, 2019 19:23
typescript script support
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "ts-node src/config/server.ts",
"dev": "nodemon -x ts-node src/config/server.ts"
},
@ch8n
ch8n / server.ts
Created May 12, 2019 19:25
simple typescript nodejs server
import express from 'express';
const app = express()
const port : string|number= process.env.PORT || 5000;
app.use("*",(req, res) =>{res.send("<h1>Welcome to your server!</h1>")})
//create a server object:
app.listen(port,() => console.log(`hosting @${port}`));
@ch8n
ch8n / gist:18dd9ee897b8f46ae800831dfaf3f8e4
Created May 12, 2019 19:32
commiting code using git
git init .
git add .
git commit -m "init/heroku"
object Mailer {
@SuppressLint("CheckResult")
fun sendMail(email: String, subject: String, message: String): Completable {
return Completable.create { emitter ->
//configure SMTP server
val props: Properties = Properties().also {
it.put("mail.smtp.host", "smtp.gmail.com")
it.put("mail.smtp.socketFactory.port", "465")
@ch8n
ch8n / noDestructure.kt
Created July 30, 2019 06:55
Destructuring an object : General way
//class
data class Person(val name:String,val age:Int)
//instantiate
val person = Person("ch8n", 25)
//access
val name = person.name
val age = person.age
@ch8n
ch8n / destructured.kt
Last active July 30, 2019 07:01
Destructuring an object : Kotlin Way
//class
data class Person(val name:String,val age:Int)
//instantiate
val developer = Person("Ch8n", 25)
//access
val (name,age) = developer
@ch8n
ch8n / allDestructuring.kt
Last active July 30, 2019 07:39
Possible destructing options in kotlin
//Data Class Destructuring
val person = Person(1, "Chetan", 25)
val(id, name, age) = person
//Collections Destructuring
//map
val map: HashMap<Int, Person> = HashMap()
map.put(1, person)
// Gotcha #1
data class Items(val one: String, val two: String)
val items= Items("1","2")
val (one, two, three) = items //Destructuring declaration initializer of type Items must have a 'component3()' function
@ch8n
ch8n / desctructureUnderHood.kt
Created July 30, 2019 09:39
Under the hood, Kotlin is actually calling the component function
//example
data class Items(val one: String, val two: String)
val items= Items("1","2")
val (one, two) = items
//converts to
val one = items.component1
val one = items.component2