Skip to content

Instantly share code, notes, and snippets.

View cketti's full-sized avatar

cketti cketti

View GitHub Profile
@pervognsen
pervognsen / shift_dfa.md
Last active January 27, 2024 19:54
Shift-based DFAs

A traditional table-based DFA implementation looks like this:

uint8_t table[NUM_STATES][256]

uint8_t run(const uint8_t *start, const uint8_t *end, uint8_t state) {
    for (const uint8_t *s = start; s != end; s++)
        state = table[state][*s];
    return state;
}
@ErikHellman
ErikHellman / WebViewServer.kt
Last active September 12, 2023 16:10
This class is no longer needed now that Google provides WebViewAssetLoader (see https://developer.android.com/reference/kotlin/androidx/webkit/WebViewAssetLoader)
/*
MIT License
Copyright (c) 2019 Erik Hellman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@rock3r
rock3r / DividerItemDecorator.kt
Created September 4, 2018 11:25
A simple yet fully featured RecyclerView ItemDecorator that draws a divider line between items. Only works with vertical LinearLayoutManagers!
package me.seebrock3r.common.widget
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.view.View
import androidx.annotation.ColorInt
import androidx.annotation.Px
import androidx.core.graphics.withTranslation
import androidx.core.view.children
#!/usr/bin/env bash
set -euo pipefail
##########
# Config #
##########
readonly GIT_BRANCH='android-8.0.0_r4'
readonly API_LEVEL='26'
fun main(args: Array<String>) {
if (args[0] == "start") {
launch(CommonPool) {
println("Launching")
SerialisationHelper.test()
println("Finished")
}
}
@edenman
edenman / LazyMainThread.kt
Created February 24, 2017 01:56
Kotlin lazy delegate that enforces single-initialization by ensuring callers are on the main thread
package my.package.foo
/**
* This method is just a modification of the kotlin stdlib lazy initializer, which by default uses a
* synchronized block to ensure no double-running of the initializer. Synchronized blocks are not
* particularly fast on Android so we try to avoid them when possible: in all of our cases, the
* lazy property is being accessed on the main thread, so it's easier to just check that we're on
* the main thread as a way to ensure no double-running of the initializer.
*/
fun <T> lazyMainThread(initializer: () -> T): Lazy<T> = LazyMainThreadImpl(initializer)
@rock3r
rock3r / avd_flush_anim.xml
Last active January 20, 2017 13:20
Standardised Japanese Toilet 🚽 Big Flush 🌀 pictogram - as Animated Vector Drawable
<!-- All copyright to the original owners. The AVD version is free to use; please give attribution if you redistribute/modify -->
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="693dp"
android:height="693dp"
android:viewportWidth="693"
@daj
daj / BaseStatelessBlackBoxEspressoTest.java
Last active December 20, 2018 09:44 — forked from xrigau/AndroidManifest.xml
The set of changes required to disable animations any time Espresso tests run. These instructions will only work on emulators and on rooted devices. This is based on the instructions in: https://code.google.com/p/android-test-kit/wiki/DisablingAnimations
public abstract class BaseStatelessBlackBoxEspressoTest<T extends Activity> extends ActivityInstrumentationTestCase2<T> {
private SystemAnimations mSystemAnimations;
public BaseStatelessBlackBoxEspressoTest(Class clazz) {
super(clazz);
}
@Override
protected void setUp() throws Exception {
@dlew
dlew / themes-debug.xml
Last active March 1, 2024 15:46
With the new theming in AppCompat, a lot of assets are tinted automatically for you via theme attributes. That has often led me to wonder "where the hell did this color come from?" You can replace your normal theme with this debug theme to help figure out the source of that color.
<!-- You can change the parent around to whatever you normally use -->
<style name="DebugColors" parent="Theme.AppCompat">
<!-- System colors -->
<item name="android:windowBackground">@color/__debugWindowBackground</item>
<item name="android:colorPressedHighlight">#FF4400</item>
<item name="android:colorLongPressedHighlight">#FF0044</item>
<item name="android:colorFocusedHighlight">#44FF00</item>
<item name="android:colorActivatedHighlight">#00FF44</item>
@devisnik
devisnik / build.gradle
Last active September 5, 2017 16:05
Shrink Guava using Gradle
apply plugin: 'base'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:4.11'
}
}