Skip to content

Instantly share code, notes, and snippets.

View teyyihan's full-sized avatar
🙃

Teyyihan Aksu teyyihan

🙃
View GitHub Profile
fun main() {
user {
name = "Teyyihan"
age = 22
tweet {
title = "Hi"
body = "body"
timestamp = 1231231L
}
@teyyihan
teyyihan / Dockerfile Args
Last active January 12, 2021 21:16
Dockerfile Arg
ARG JAR_FILE=foo/bar.jar
COPY ${JAR_FILE}
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")
}
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]
}
@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)
}
suspend fun <T> Task<T>.awaitTask(): T? = suspendCoroutine { continuation ->
this.addOnCompleteListener { task ->
if (task.isSuccessful) {
continuation.resume(task.result)
} else {
continuation.resumeWithException(task.exception!!)
}
}
}
Dao{
@Query("SELECT * FROM users WHERE label LIKE :query")
fun pagingSource(query: String): PagingSource<Int, User>
}
ViewModel{
Pager(
config = PagingConfig(
pageSize = NETWORK_PAGE_SIZE,
),
Users.watch().on('change',(change)=>{
console.log('Something has changed')
io.to(change.fullDocument._id).emit('changes',change.fullDocument)
})
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"}
mongoose.connect('mongodb://localhost:27017/realtimeProject',{useNewUrlParser:true},
function(err){
if(err){
throw err
}
console.log('Database connected')
})