Skip to content

Instantly share code, notes, and snippets.

View mileskrell's full-sized avatar

Miles Krell mileskrell

View GitHub Profile
@mileskrell
mileskrell / autoplay_blocked_detector.html
Created March 6, 2020 08:16
Try to detect if autoplay on videos is blocked
<video id="vid" autoplay loop muted>
<source src="/vid.mp4" type="video/mp4" />
</video>
<script>
setTimeout(function() {
let vid = document.getElementById("vid");
if (vid.paused) {
let message = document.createElement("p");
message.innerHTML = "There's supposed to be a video here, but your browser either " +
@mileskrell
mileskrell / bootstrap_popover.html
Created March 3, 2020 07:16
Example of showing an image in a Bootstrap popover
<!-- You'll need to add all the Bootstrap stuff for this to work -->
<p>Click <a href="#" id="popover-link" data-toggle="popover">here</a> to see an image in a popover.</p>
<script>
window.onload = function () {
$("#popover-link").popover({
content: '<img src="https://via.placeholder.com/200x200" width="200" height="200" />',
trigger: "focus",
html: true
})
};
@mileskrell
mileskrell / WeekView_issue.patch
Last active January 14, 2020 18:41
Patch to reproduce WeekView issue
Index: example/lib/main.dart
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- example/lib/main.dart (revision ef4044b05eef89e3fcc85b18e81e2e9d00bcc946)
+++ example/lib/main.dart (date 1579027083000)
@@ -141,37 +141,13 @@
DateTime now = DateTime.now();
DateTime date = DateTime(now.year, now.month, now.day);
@mileskrell
mileskrell / scope_function_debugging.md
Created October 21, 2019 16:36
A note on being careful with scope functions

This is something I encountered during development of my project Text Torch, and I thought it was interesting enough to write it down here.

The following code snippets are both executed within the context of a fragment. There is a big difference between the following two code snippets. In the first, "fragmentManager" is a property on the fragment containing the whole code snippet. But in the second, it's a property on the newly-created SortTypeDialogFragment, and it actually ends up returning null!

tl;dr: always keep your context in mind when using Kotlin's scope functions, especially when the context inside the scope function is for an object of the same class as the context outside the scope function.

// This did what I wanted
val sortTypeDialogFragment = SortTypeDialogFragment(socialRecordsViewModel.sortType.radioButtonId, socialRecordsViewModel.reversed)
    .apply { setTargetFragment(this@StatsFragment, SortTypeDialogFragment.REQUEST_CODE) }
@mileskrell
mileskrell / dart_demo.dart
Created September 24, 2019 18:07
Small file demonstrating basic Dart language features. Made for a workshop I did about Flutter.
import 'dart:math';
class Person {
String firstName;
String lastName;
String _favoriteColor;
String hobby;
set favoriteColor(String newFavorite) {
print("My favorite color has changed from $_favoriteColor to $newFavorite");
@mileskrell
mileskrell / stripe_container.dart
Created August 14, 2019 14:43
A Flutter widget that displays diagonal stripes on top of its child
import 'package:flutter/material.dart';
class StripeContainer extends StatelessWidget {
final Widget child;
StripeContainer({@required this.child});
@override
Widget build(BuildContext context) {
return Container(
@mileskrell
mileskrell / build.gradle.kts
Created April 19, 2019 04:26
Example of declaring Android signing configs using Gradle Kotlin DSL
android {
signingConfigs {
getByName("debug") {
keyAlias = "debug"
keyPassword = "my debug key password"
storeFile = file("/home/miles/keystore.jks")
storePassword = "my keystore password"
}
create("release") {
keyAlias = "release"
@mileskrell
mileskrell / gradle_extra_props.kt
Created April 11, 2019 17:29
Using Gradle's "extra properties" to share Android dependency versions (with Gradle Kotlin DSL)
// In project-level build.gradle
val navigationVersion by extra("2.0.0")
// In app-level build.gradle
val navigationVersion: String by rootProject.extra
@mileskrell
mileskrell / FixedAppBarLayoutBehavior.java
Created February 26, 2019 20:01
An AppBarLayout.Behavior that ignores dragging on the AppBarLayout
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.util.AttributeSet;
/**
* When used as the LayoutBehavior of an AppBarLayout, prevents
* scrolling by dragging on the AppBarLayout itself
*
* From https://stackoverflow.com/a/46120228
@mileskrell
mileskrell / Android Studio config setup.md
Created February 21, 2019 15:44
HOWTO set up nice Android Studio run configurations

Make a script like this:

#!/bin/bash

sh -c "$1 $2 $3 $4 $5 $6 $7"

if [ $? != "0" ]; then
    printf "Clearing data failed! Running anyway..."
fi