Skip to content

Instantly share code, notes, and snippets.

View kylpo's full-sized avatar

Kyle Poole kylpo

View GitHub Profile
@Rich-Harris
Rich-Harris / prepack-svelte.md
Last active May 19, 2022 11:02
Is Prepack like Svelte?

Note: I'm not involved in Prepack in any way — please correct me if I say anything incorrect below!

A few people have asked me if Prepack and Svelte are similar projects with similar goals. The answer is 'no, they're not', but let's take a moment to explore why.

What is Prepack?

Prepack describes itself as a 'partial evaluator for JavaScript'. What that means is that it will run your code in a specialised interpreter that, rather than having some effect on the world (like printing a message to the console), will track the effects that would have happened and express them more directly.

So for example if you give it this code...

@rharter
rharter / SharedPreferenceLiveData.kt
Last active March 19, 2023 08:15
Creates LiveData objects that observe a value in SharedPreferences while they have active listeners.
import android.arch.lifecycle.LiveData
import android.content.SharedPreferences
abstract class SharedPreferenceLiveData<T>(val sharedPrefs: SharedPreferences,
val key: String,
val defValue: T) : LiveData<T>() {
private val preferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
if (key == this.key) {
value = getValueFromPreferences(key, defValue)
/*
* Copyright (C) 2017 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
#!/usr/bin/env bash
set -e
addEntries() {
# check if universal access / custom menu key exists
if defaults read com.apple.universalaccess com.apple.custommenu.apps > /dev/null 2>&1; then
defaults delete com.apple.universalaccess com.apple.custommenu.apps
fi
@ArthurNagy
ArthurNagy / RoundedBottomSheetDialogFragment.kt
Last active May 10, 2024 09:22
Rounded modal bottom sheet as seen in new Google products(Tasks, News, etc.), described in this article: https://medium.com/halcyon-mobile/implementing-googles-refreshed-modal-bottom-sheet-4e76cb5de65b
package com.your.package
import android.app.Dialog
import android.os.Bundle
import com.your.package.R
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
/**
* BottomSheetDialog fragment that uses a custom
@matsumurae
matsumurae / anki-dracula-card.md
Last active November 30, 2021 11:07
Dracula theme inspired Anki cards

## 👋

I've created Dracula inspired theme for Anki Cards. You're going to find Basic and Cloze cards. You can see theme here.

Basic

Cloze

@dlaub3
dlaub3 / husky.ignore.sh
Created August 24, 2021 22:55
Better Husky Pre-Commit
#!/usr/bin/env sh
#
# This script lints files for a Husky pre-commit hook
#
# run with `git commit -m "foo" 2>&1 | tee husky-errors.ignore.txt`
# to save the errors to a file.
#
# {
# "hooks": {
@BrentMifsud
BrentMifsud / PreviewDevice+Devices.swift
Last active October 31, 2022 18:50
Extension on PreviewDevice that includes all available devices
import SwiftUI
/// Static properties for all preview devices.
///
/// Usage:
///
/// ```swift
/// struct TestView_Previews: PreviewProvider {
/// static var previews: some View {
/// Group {
@Puppo
Puppo / NotEmptyArray.ts
Last active February 23, 2022 15:40
NotEmptyArray definition
export interface NonEmptyArray<A> extends ReadonlyArray<A> {
// tslint:disable-next-line: readonly-keyword
0: A;
}
type ReadOnlyNotEmptyArray<T> = Readonly<NotEmptyArray<T>>;
function isNotEmptyArray<T>(as: T[]): as is NotEmptyArray<T> {
return as.length > 0;
}