Skip to content

Instantly share code, notes, and snippets.

@umarov
umarov / simple-js-examples.js
Last active June 21, 2017 04:39
Simple JS Examples
let cities = ['Alexandria', 'San Francisco', 'Los Angeles', 'New York', 'Toronto'];
function twoWordedWithForLoop(sentences) {
let twoWordedSentences = []
for(let index = 0; index < sentences.length; index++) {
let currentSentence = sentences[index]; // String
let splittedSentence = currentSentence.split(" "); // Array
let numberOfWords = splittedSentence.length // Number
if (numberOfWords === 2) {
@umarov
umarov / index.ts
Created December 3, 2017 19:02
Polymer 3 with Webpack and TypeScript
import { OTUser, OTUserProvider, OTUserDetails } from './ot-user/ot-user'
import { OTFooter } from './ot-footer/ot-footer'
import { OTTopNav, OTTopNavSection, OTTopNavSubSection } from './ot-top-nav/ot-top-nav'
customElements.define('ot-user', OTUser)
customElements.define('ot-user-provider', OTUserProvider)
customElements.define('ot-user-details', OTUserDetails)
customElements.define('ot-footer', OTFooter)
@umarov
umarov / Client.ts
Last active January 13, 2018 23:25
TypeORM issue
import { Entity, PrimaryGeneratedColumn, OneToMany, Column, CreateDateColumn, UpdateDateColumn } from "typeorm";
import { Order } from "./Order";
@Entity()
export class Client {
@PrimaryGeneratedColumn() id: number;
@Column('character varying') name: string;
@Column('character varying') location: string;
@OneToMany(type => Order, order => order.client)
@umarov
umarov / index.html
Last active January 25, 2018 23:17
How to get started with Kotlin Native and Web Assembly
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>WASM with Kotlin</title>
</head>
<body>
<h1>Welcome to WASM with Kotlin</h1>
@umarov
umarov / main.kt
Created January 25, 2018 23:18
How to get started with Kotlin Native and Web Assembly
fun main(args: Array<String>) {
println("Hello Kotlin/Native!")
}
@umarov
umarov / TodoListDetailAdapter.kt
Created January 25, 2018 23:19
TodoListDetailAdapter
class TodoListDetailAdapter(
val context: Context,
inline val onTodoItemAction: (todoItem: TodoItem, actionType: Int) -> Unit) {
fun createTodoItem(todoItem: TodoItem) {
onTodoItemAction(todoItem, TodoItem.CREATE)
}
fun updateTodoItem(todoItem: TodoItem) {
onTodoItemAction(todoItem, TodoItem.UPDATE)
}
fun deleteTodoItem(todoItem: TodoItem) {
TodoListDetailAdapter(context) { todoItem, actionType ->
when (actionType) {
TodoItem.CREATE -> todoListDetailViewModel.createTodoItem(todoItem)
TodoItem.UPDATE -> todoListDetailViewModel.updateTodoItem(todoItem)
TodoItem.DELETE -> todoListDetailViewModel.deleteTodoItem(todoItem)
}
}
fun onTodoItemAction(todoItem: TodoItem, actionType: Int) {
when (actionType) {
TodoItem.CREATE -> todoListDetailViewModel.createTodoItem(todoItem)
TodoItem.UPDATE -> todoListDetailViewModel.updateTodoItem(todoItem)
TodoItem.DELETE -> todoListDetailViewModel.deleteTodoItem(todoItem)
}
}
TodoListDetailAdapter(context, onTodoItemAction)
val onTodoItemAction = { todoItem: TodoItem, actionType: Int ->
when (actionType) {
TodoItem.CREATE -> todoListDetailViewModel.createTodoItem(todoItem)
TodoItem.UPDATE -> todoListDetailViewModel.updateTodoItem(todoItem)
TodoItem.DELETE -> todoListDetailViewModel.deleteTodoItem(todoItem)
}
}
TodoListDetailAdapter(context, onTodoItemAction)
inline fun createTodoList(name: String, crossinline afterCreate: (todoList: TodoList) -> Unit) {
Thread(Runnable {
val todoList = TodoList(name)
db.todoListDao().insertTodoList(todoList)
Handler(Looper.getMainLooper()).post { afterCreate(todoList) }
}).start()
}