Skip to content

Instantly share code, notes, and snippets.

View pablichjenkov's full-sized avatar

pablichjenkov pablichjenkov

View GitHub Profile
@fabiomsr
fabiomsr / ByteArray.kt
Last active July 18, 2023 10:53
ByteArray and String extension to add hexadecimal methods in Kotlin
private val HEX_CHARS = "0123456789ABCDEF".toCharArray()
fun ByteArray.toHex() : String{
val result = StringBuffer()
forEach {
val octet = it.toInt()
val firstIndex = (octet and 0xF0).ushr(4)
val secondIndex = octet and 0x0F
result.append(HEX_CHARS[firstIndex])
@andymatuschak
andymatuschak / States-v3.md
Last active April 12, 2024 16:06
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@swankjesse
swankjesse / QuotePreservingCookieJar.java
Created October 4, 2016 00:57
Like our JavaNetCookieJar, but preserve quote characters.
/*
* Copyright (C) 2016 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@patpohler
patpohler / Big List of Real Estate APIs.md
Last active April 21, 2024 16:02
Evolving list of Real Estate APIs by Category

Big List of Real Estate APIs

Listings / Property Data

####Rets Rabbit http://www.retsrabbit.com

Rets Rabbit removes the nightmare of importing thousands of real estate listings and photos from RETS or ListHub and gives you an easy to use import and Web API server so you can focus on building your listing search powered website or app.

@elye
elye / Kotlin Date Iterator
Last active July 15, 2021 22:10
Kotlin Date Iterator
class TestingClass {
fun testingFunction() {
for (everyday in this year 2017) {
// Do something with everyday
println(everyday.toString())
}
}
private infix fun year(year: Int): DateRange {
return Date(year, 1, 1)..Date(year, 12, 31)
@FavoRiteKK
FavoRiteKK / EndlessRecyclerScrollListener
Created October 27, 2017 04:55
[Android] Endless load more for RecyclerView
package com.estate.mrnx.tb.custom.refresharticle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
public abstract class EndlessRecyclerScrollListener extends RecyclerView.OnScrollListener {
// The minimum amount of items to have below your current scroll position
// before loading more.
@hameno
hameno / ExtendedFileProvider
Last active January 12, 2022 10:47
"Enhanced" FileProvider with support for external secondary paths (based on 27.0.2)
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ericwindmill
ericwindmill / form_page.dart
Created April 14, 2018 19:25
Flutter Simple inherited Widget Example
import 'package:flutter/material.dart';
import 'package:simple_inherit/state_container.dart';
class UpdateUserScreen extends StatelessWidget {
static final GlobalKey<FormState> formKey = new GlobalKey<FormState>();
static final GlobalKey<FormFieldState<String>> firstNameKey =
new GlobalKey<FormFieldState<String>>();
static final GlobalKey<FormFieldState<String>> lastNameKey =
new GlobalKey<FormFieldState<String>>();
static final GlobalKey<FormFieldState<String>> emailKey =
@gpeal
gpeal / SimpleDemo.kt
Last active August 28, 2018 17:54
Airbnb MvRx Early Look
data class SimpleDemoState(val listing: Async<Listing> = Uninitialized)
class SimpleDemoViewModel(override val initialState: SimpleDemoState) : MvRxViewModel<SimpleDemoState>() {
init {
fetchListing()
}
private fun fetchListing() {
// This automatically fires off a request and maps its response to Async<Listing>
// which is a sealed class and can be: Unitialized, Loading, Success, and Fail.
@y-polek
y-polek / doze_mode_adb_commands.sh
Last active April 20, 2024 09:36
adb commands to test Doze mode
#! /bin/zsh
# Buttery powered state
adb shell dumpsys battery | grep powered
# Unplug battery
adb shell dumpsys battery unplug
# Reset battery
adb shell dumpsys battery reset