Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View cjbrooks12's full-sized avatar

Casey Brooks cjbrooks12

View GitHub Profile
@cjbrooks12
cjbrooks12 / FlowLayout.java
Last active August 29, 2015 14:14
Based on the code at https://nishantvnair.wordpress.com/2010/09/28/flowlayout-in-android/ and modified to be populated by an adapter
//https://nishantvnair.wordpress.com/2010/09/28/flowlayout-in-android/
public class FlowLayout extends ViewGroup {
public static final int DEFAULT_HORIZONTAL_SPACING = 5;
public static final int DEFAULT_VERTICAL_SPACING = 5;
private final int horizontalSpacing;
private final int verticalSpacing;
private final AdapterObserver observer = new AdapterObserver();
private List<RowMeasurement> currentRows = Collections.emptyList();
@cjbrooks12
cjbrooks12 / TimePreference.java
Last active August 29, 2015 14:14
based on answer t o SO question: http://stackoverflow.com/questions/5533078/timepicker-in-preferencescreen modified to correctly set the initial value in the local timezone given millis UTC
//based on answer t o SO question: http://stackoverflow.com/questions/5533078/timepicker-in-preferencescreen
//modified to correctly set the initial value in the local timezone given millis UTC
public class TimePreference extends DialogPreference {
private Calendar calendar;
private TimePicker picker = null;
private Context context;
public TimePreference(Context context) {
this(context, null);
@cjbrooks12
cjbrooks12 / generate-articles.py
Last active February 1, 2018 19:49 — forked from jaden/generate-articles.py
Generates 5000 posts to test performance of Orchid. Originally from the Hugo file, but changed generated filenames and a few properties to work better with Orchid
# Create specified number of articles for Hugo benchmarks
from datetime import datetime
import random
import string
from sys import argv
import os
def generateWord(min_length = 1, max_length = 10):
length = random.randint(min_length, max_length)
{
"_comments": {
"_backgroundColor": "#3C3F41",
"_backgroundColorLight": "#515658",
"_backgroundColorDark": "#3C3F41",
"_selectedBackgroundColor": "#0D293E",
"_emphasizedBackgroundColor": "#2F65CA",
"_dividerColor": "#282828",
"_secondaryDividerColor": "#4d535d",
"_controlColor": "#8C8C8C",
/*!
* Bootstrap v3.3.7 (https://getbootstrap.com)
* Copyright 2011-2018 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
/*!
* Generated using the Bootstrap Customizer (https://getbootstrap.com/docs/3.3/customize/?id=c78cd796ed3d630f903dec748e113244)
* Config saved to config.json and https://gist.github.com/c78cd796ed3d630f903dec748e113244
*/
@cjbrooks12
cjbrooks12 / MyModule.kt
Last active March 22, 2019 15:09
Dynamically Load Orchid Wiki Pages
package com.example
import com.eden.orchid.api.compilers.TemplateFunction
import com.eden.orchid.api.registration.OrchidModule
import com.example.ResourcesFunction
// in Orchid sourceroot: src/orchid/kotlin
class MyModule : OrchidModule() {
override fun configure() {
@cjbrooks12
cjbrooks12 / SpaghettiActivity.kt
Last active February 3, 2020 20:16
Spaghetti Screens
class MainActivity : AppCompatActivity() {
var username: String? = null
var passwordValue: String? = null
var passwordField: EditText? = null
val listener = object : TextWatcher {
override fun afterTextChanged(s: Editable?) {}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
username = s.toString()
@cjbrooks12
cjbrooks12 / LoginActivity.kt
Last active February 3, 2020 20:19
Lasagna Screens
class LoginActivity : AppCompatActivity(), LoginView {
val vm: LoginViewModel by lazy {
LoginViewModel(this, LoginService.getInstance(BuildConfig.DEBUG))
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
@cjbrooks12
cjbrooks12 / RouterWithCallbacks.kt
Created April 30, 2022 20:34
Ballast Simple Router
fun main() = singleWindowApplication {
MaterialTheme {
val applicationCoroutineScope = rememberCoroutineScope()
val router = remember(applicationCoroutineScope) { RouterViewModel(applicationCoroutineScope) }
val routerState by router.observeStates().collectAsState()
val handleNavigation = { input: RouterContract.Inputs -> router.trySend(input) }
when(routerState.currentPage) {
"/app/screen1" -> { Screen1(handleNavigation) }
@cjbrooks12
cjbrooks12 / ExampleViewModel.kt
Last active May 10, 2022 15:03
Android KMM Strategies
public class ExampleViewModel : ViewModel() {
private val state = mutableStateFlowOf(ExampleFragmentState())
public fun observeStates(): StateFlow<ExampleFragmentState> = state.asStateFlow()
public fun button1Clicked() = viewModelScope.launch {
// ...
}
public fun button2Clicked() = viewModelScope.launch {