Skip to content

Instantly share code, notes, and snippets.

View KonstantinBerkow's full-sized avatar

KonstantinBerkow

  • Odessa, Ukraine
View GitHub Profile
//
// Created by Konstantin Berkow on 3/4/18.
//
#include "lookup_cache.h"
#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
fun BitmapFactory.Options.verboseToString(): String {
val builder = StringBuilder(1024)
.append("BitmapFactory.Options{")
.append("\"inBitmap\": ").append(inBitmap).append(", ")
.append("\"inDensity\": ").append(inDensity).append(", ")
.append("\"inJustDecodeBounds\": ").append(inJustDecodeBounds).append(", ")
.append("\"inMutable\": ").append(inMutable).append(", ")
.append("\"inPreferredConfig\": ").append(inPreferredConfig).append(", ")
.append("\"inSampleSize\": ").append(inSampleSize).append(", ")
.append("\"inScaled\": ").append(inScaled).append(", ")
@KonstantinBerkow
KonstantinBerkow / safeAnchors.swift
Created February 23, 2018 13:01
Main anchors template
let leadingAnchor: NSLayoutXAxisAnchor
let topAnchor: NSLayoutYAxisAnchor
let trailingAnchor: NSLayoutXAxisAnchor
let bottomAnchor: NSLayoutYAxisAnchor
let centerXAnchor: NSLayoutXAxisAnchor
let centerYAnchor: NSLayoutYAxisAnchor
if #available(iOS 11, *) {
let guide = rootView.safeAreaLayoutGuide
leadingAnchor = guide.leadingAnchor
topAnchor = guide.topAnchor
package me.berkow.playground;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Formatter;
import java.util.Iterator;
import java.util.Map;
class LoginInteractor(private val api: Api) {
fun login(email: String, password: String): Observable<LoginResult> {
return when {
!EMAIL_PATTERN.matcher(email).matches() -> Observable.just(LoginError(ErrorClass.INVALID_EMAIL))
password.length < 6 -> Observable.just(LoginError(ErrorClass.INVALID_PASSWORD) as LoginResult)
else -> api.login(Credentials(email, password))
.map { response -> LoginSuccess(response.token, response.info) as LoginResult }
.onErrorReturn { throwable ->
when (throwable) {
@KonstantinBerkow
KonstantinBerkow / LoginPresenter.kt
Created January 29, 2018 18:54
Presenter for login
@AuthScope
class LoginPresenter
@Inject constructor(private val interactor: LoginInteractor) : BasePresenter<LoginState, LoginEvent> {
private val resultsSubj = PublishSubject.create<LoginResult>().toSerialized()
private val stateObs: Observable<LoginState>
init {
val initial = LoginState()
stateObs = resultsSubj
@Singleton
class ImagePresentationPresenter
@Inject constructor(private val client: OkHttpClient) {
private val resultsRelay = PublishRelay.create<Result>().toSerialized()
private val states: Observable<UiState>
private val loadTransformer = ObservableTransformer<LoadImage, Result> {
it.flatMap { event ->
val url = event.url
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import json
import jwt
import time
from hyper import HTTPConnection
ALGORITHM = 'ES256'
let queueu = DispatchQueue.global(qos: DispatchQoS.background.qosClass)
Alamofire.request("\(apiURL)/params/pages").responseJSON(queue: queueu) {
response in
guard response.result.isSuccess,
let jsonArr = response.result.value as? [JSON] else {
return
}
var newPages: [String: String] = [:]
for obj in jsonArr {
if let key = obj["key"] as? String,
@KonstantinBerkow
KonstantinBerkow / BitmapFactoryOptionsToString.java
Last active December 11, 2017 09:13
Verbose toString for android.graphics.BitmapFactory.Options
import android.graphics.BitmapFactory;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
/**
* Created by konstantinberkow on 12/11/17.
*/
public final class BitmapFactoryOptionsToString {