Skip to content

Instantly share code, notes, and snippets.

@umarov
umarov / isDefined.ts
Created April 18, 2019 18:47
TypeScript hacks
function isDefined<T>(x: T | undefined): x is T {
return typeof x !== undefined;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Tanks</title>
<style>
body {
margin: 0;
overflow: hidden;
@umarov
umarov / dbsetup.js
Last active February 23, 2019 16:55
Create db and migrations for Node and TypeORM
const util = require("util");
const { Pool } = require("pg");
const { username: user, host, password, port, database } = require("./ormconfig");
const exec = util.promisify(require("child_process").exec);
const baseDatabaseName = process.env.PG_DB;
// This requires an existing DB to exist. That's why `postgres` is being used as the DB
const pool = new Pool({
user,
@umarov
umarov / setup.md
Last active November 25, 2018 16:28
mysql 5.7 setup
$ sudo mysql -u root # I had to use "sudo" since is new installation
mysql> USE mysql;
mysql> CREATE USER 'YOUR_SYSTEM_USER'@'localhost' IDENTIFIED BY ''; # replace YOUR_SYSTEM_USER with your username
mysql> GRANT ALL PRIVILEGES ON *.* TO 'YOUR_SYSTEM_USER'@'localhost'; # replace YOUR_SYSTEM_USER with your username
mysql> UPDATE user SET plugin='auth_socket' WHERE User='YOUR_SYSTEM_USER'; # replace YOUR_SYSTEM_USER with your username
mysql> FLUSH PRIVILEGES;
# this is the password you need to add to in congfig/database.yml
@umarov
umarov / npm-it.js
Last active October 13, 2018 00:21
const path = require('path')
const { promisify } = require('util')
const fs = require('fs')
function getApps() {
return promisify(fs.readdir)('app')
}
const defaultManifest = {
bower: [],
@umarov
umarov / Stacktrace
Created March 12, 2018 15:26
Npm ci prefix error
0 info it worked if it ends with ok
1 verbose cli [ '/home/mumarov/.nvm/versions/node/v9.7.1/bin/node',
1 verbose cli '/home/mumarov/.nvm/versions/node/v9.7.1/bin/npm',
1 verbose cli 'ci',
1 verbose cli '--prefix',
1 verbose cli './node_modules',
1 verbose cli '--userconfig',
1 verbose cli '../../.npmrc' ]
2 info using npm@5.7.1
3 info using node@v9.7.1
viewModel.createTodoList("Groceries") {
// Update some view
}
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()
}
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)
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)