Skip to content

Instantly share code, notes, and snippets.

View ubuntudroid's full-sized avatar

Sven Bendel ubuntudroid

View GitHub Profile
@ubuntudroid
ubuntudroid / steps.md
Last active July 13, 2016 09:46 — forked from kattrali/steps.md
Configuring profanity.im for Hipchat on OS X

Configuring profanity.im for Hipchat on OS X

Installation

Easy

brew install profanity

  • The latest build available today via homebrew is 0.4.7, and it does not support desktop notifications.
@ubuntudroid
ubuntudroid / ProductsTableViewController.swift
Created March 24, 2017 17:07
Needed to change the height of the prototype cell on the storyboard for XCode to notice, that the "image-cell" actually exists and stop telling me about "unknown type names" and missing commas in that line. Somehow, it seems, Xcode thought that the image-cell1 part is not contained in a String, but executable code. WTF?
import UIKit
class ProductsTableViewController: UITableViewController {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ProductCell", for: indexPath)
@ubuntudroid
ubuntudroid / EditTaskViewModel.kt
Last active April 16, 2017 12:35
View model interface definition for adding/editing tasks
class EditTaskViewModel(val taskId: String? = null) {
/**
* Initialises this view model by loading the given task from the repository
* and binding it to the UI.
*/
fun loadTask() {}
/**
* Commits the modified or new task to the repository.
class EditTaskViewModel(val taskId: String? = null) : BaseObservable() {
@get:Bindable
var task: Task = Task()
set(value) {
field = value
notifyPropertyChanged(BR.task)
}
/**
class EditTaskViewModel(val taskId: String? = null,
private val repository: TaskRepository,
private val listener: EditTaskListener? = null,
private val logger: Logger? = null) : BaseObservable() {
@get:Bindable
var task: Task = Task() // setter left out for brevity
fun loadTask() {
if (taskId == null) {
interface EditTaskListener {
/**
* Called when the task has been comitted.
*/
fun onTaskCommitted()
/**
* Called when there was a non-recoverable error.
*
* Usually removing the view bound to this view model is the appropriate reaction.
fun commit() {
if (task.title.isBlank()) {
logger?.e("Trying to commit a task with an empty title.")
listener?.onFatalError(R.string.add_task_empty_title)
return
}
repository.commitTask(task, taskId)
listener?.onTaskCommitted()
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="com.ubuntudroid.toddler.tasks.edit.EditTaskViewModel" />
</data>
class SidebarPresenter(val userInfoRepository: UserInfoRepository) {
fun init() {
...
userInfoRepository
.getNameStateObservable()
.observeOn(AndroidSchedulers.mainThread())
.subscribe { userName -> userNameTextView.setText(userName) }
...
}
class SidebarPresenter(val userInfoRepository: UserInfoRepository) {
fun init() {
...
userInfoRepository
.getNameStateObservable()
.mergeWith(
Observable.from(arrayOf("Arthur Dent", "Genghis Temüjin Khan", "Know-Nothing Bozo the Non-Wonder Dog", ""))
.zipWith(
Observable.interval(5, TimeUnit.SECONDS),