This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose') | |
const UserSchema = mongoose.Schema({ | |
_id: String, | |
name: String, | |
age: Number | |
}) | |
module.exports = mongoose.model('Users',UserSchema) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const app = express() | |
const bodyParser = require('body-parser') | |
const io = require('socket.io')(3100) | |
const mongoose = require('mongoose') | |
// body-parser | |
app.use(bodyParser.json()) | |
// collections |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongoose.connect('mongodb://localhost:27017/realtimeProject',{useNewUrlParser:true}, | |
function(err){ | |
if(err){ | |
throw err | |
} | |
console.log('Database connected') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mongoose.connect('mongodb://localhost:27017/realtimeProject',{useNewUrlParser:true}, | |
function(err){ | |
if(err){ | |
throw err | |
} | |
console.log('Database connected') | |
io.on('connection',(socket)=>{ | |
console.log('user connected') | |
socket.on('joinRoom',(data)=>{ // data will look like => {myID: "123123"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Users.watch().on('change',(change)=>{ | |
console.log('Something has changed') | |
io.to(change.fullDocument._id).emit('changes',change.fullDocument) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dao{ | |
@Query("SELECT * FROM users WHERE label LIKE :query") | |
fun pagingSource(query: String): PagingSource<Int, User> | |
} | |
ViewModel{ | |
Pager( | |
config = PagingConfig( | |
pageSize = NETWORK_PAGE_SIZE, | |
), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
suspend fun <T> Task<T>.awaitTask(): T? = suspendCoroutine { continuation -> | |
this.addOnCompleteListener { task -> | |
if (task.isSuccessful) { | |
continuation.resume(task.result) | |
} else { | |
continuation.resumeWithException(task.exception!!) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func fib(num int) int { | |
if num <= 1 {return 0} | |
if num == 2 {return 1} | |
return fib(num-1) + fib(num-2) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func memoFib(num int, d map[int]int) int { | |
if num <= 1 {return 0} | |
if num == 2 {return 1} | |
if val, ok := d[num]; ok { | |
return val | |
} | |
d[num] = memoFib(num-1,d)+memoFib(num-2,d) | |
return d[num] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
d := make(map[int]int) | |
t0 := time.Now() | |
fmt.Println(fib(40)) | |
t1 := time.Now() | |
fmt.Println(memoFib(40,d)) | |
t2 := time.Now() | |
fmt.Println("It took ",t1.Sub(t0).Nanoseconds()," nanoseconds to calculate without memoization") | |
fmt.Println("It took ",t2.Sub(t1).Nanoseconds()," nanoseconds to calculate with memoization") | |
} |
OlderNewer