Skip to content

Instantly share code, notes, and snippets.

View Jswizzy's full-sized avatar

Justin Smith Jswizzy

View GitHub Profile
@Jswizzy
Jswizzy / NavBackStackEntryExt.kt
Last active December 29, 2021 19:02
android utils
/**
* If the lifecycle is not resumed it means this NavBackStackEntry already processed a nav event.
*
* This is used to de-duplicate navigation events.
*/
private fun NavBackStackEntry.lifecycleIsResumed() =
this.lifecycle.currentState == Lifecycle.State.RESUMED
class MyRepository(private val externalScope: CoroutineScope) { /* ... */ }
class MyApplication : Application() {
// Application-scoped types that any class in the app could access
// using the applicationContext.
val applicationScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
val myRepository = MyRepository(applicationScope)
}
@Jswizzy
Jswizzy / InstallingSwift.md
Last active February 26, 2024 12:04
Swift Install Instruction 20.04

Installing Swift on Ubuntu 20.04

1. Install Depencies

“clang”[ˈklæŋ] is the compiler based on LLVM for C, C++, Objective-C, and Objective-C++. clang is needed to install in order to Swift. Run the following code in Ubuntu terminal.

Before installing swift “libpython2.7” and “libpython2.7-dev” are needed to get Swift running. Run the following code.

# Path to your oh-my-zsh installation.
export ZSH="/home/justinsmith/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="robbyrussell"
# Set list of themes to pick from when loading at random
env:
# TERM variable
#
# This value is used to set the `$TERM` environment variable for
# each instance of Alacritty. If it is not present, alacritty will
# check the local terminfo database and use `alacritty` if it is
# available, otherwise `xterm-256color` is used.
TERM: xterm-256color
# Background opacity
# -- general -------------------------------------------------------------------
set -g default-terminal "screen-256color" # colors!
setw -g xterm-keys on
set -s escape-time 10 # faster command sequences
set -sg repeat-time 600 # increase repeat timeout
set -s focus-events on
bind C-a send-prefix -2
{
"coc.preferences.colorSupport": true,
"coc.preferences.formatOnSaveFiletypes": [
"css",
"html",
"javascript",
"javascriptreact",
"json",
"liquid",
"scss"
@Jswizzy
Jswizzy / init.vim
Last active July 9, 2020 14:57 — forked from benawad/init.vim
filetype plugin indent on
" Specify a directory for plugins
call plug#begin('~/.vim/plugged')
Plug 'Yggdroot/indentLine'
Plug 'airblade/vim-gitgutter'
Plug 'christoomey/vim-sort-motion'
Plug 'editorconfig/editorconfig-vim'
@Jswizzy
Jswizzy / Memoize.kt
Created April 26, 2019 22:19
Caching results
import kotlin.reflect.KProperty
import kotlin.system.measureTimeMillis
class Memoize<T, R>(val fn: (T) -> R) {
private val cache = mutableMapOf<T, R>()
operator fun getValue(thisRef: Any?, property: KProperty<*>) =
{ arg: T -> cache.getOrPut(arg) { fn(arg) } }
}