Skip to content

Instantly share code, notes, and snippets.

View teyyihan's full-sized avatar
🙃

Teyyihan Aksu teyyihan

🙃
View GitHub Profile
const mongoose = require('mongoose')
const UserSchema = mongoose.Schema({
_id: String,
name: String,
age: Number
})
module.exports = mongoose.model('Users',UserSchema)
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
mongoose.connect('mongodb://localhost:27017/realtimeProject',{useNewUrlParser:true},
function(err){
if(err){
throw err
}
console.log('Database connected')
})
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"}
Users.watch().on('change',(change)=>{
console.log('Something has changed')
io.to(change.fullDocument._id).emit('changes',change.fullDocument)
})
Dao{
@Query("SELECT * FROM users WHERE label LIKE :query")
fun pagingSource(query: String): PagingSource<Int, User>
}
ViewModel{
Pager(
config = PagingConfig(
pageSize = NETWORK_PAGE_SIZE,
),
suspend fun <T> Task<T>.awaitTask(): T? = suspendCoroutine { continuation ->
this.addOnCompleteListener { task ->
if (task.isSuccessful) {
continuation.resume(task.result)
} else {
continuation.resumeWithException(task.exception!!)
}
}
}
@teyyihan
teyyihan / fib.go
Last active December 9, 2020 10:02
func fib(num int) int {
if num <= 1 {return 0}
if num == 2 {return 1}
return fib(num-1) + fib(num-2)
}
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]
}
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")
}