Skip to content

Instantly share code, notes, and snippets.

View ggrell's full-sized avatar
:shipit:

Gyuri Grell ggrell

:shipit:
View GitHub Profile
# Convert from H264 to H265
ffmpeg -i in.mov -c:v libx265 -an -x265-params crf=20 output.mp4
# Tag as HVC instead of HEV1 so iOS can play it
ffmpeg -i output.mp4 -vcodec copy -acodec copy -tag:v hvc1 output2.mp4
# Bonus: it can take a second to play (no more than H264) so here's how to generate
# a thumbnail of the first frame to embed in your view as a placeholder.
ffmpeg -i output2.mp4 -vf "select=eq(n\,34)" -vframes 1 thumbnail.png
@ggrell
ggrell / SearchTweetUseCaseTest.kt
Created December 27, 2021 01:24 — forked from raulh82vlc/SearchTweetUseCaseTest.kt
SearchTweetUseCaseTest test cases for StateFlow resolution - only latest state is captured
/*
* Copyright (C) 2020 Raul Hernandez Lopez
*
* 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
import timber.log.Timber
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
class MyClass {
// This will automatically have the TAG "MyClass"
private val log by timber()
fun logSomething() {
log.i("Hello")
@ggrell
ggrell / uniqueObservable.kt
Created April 22, 2021 21:07 — forked from gpeal/uniqueObservable.kt
Unique Observable
/**
* Like Delegates.observable except it only calls the callback when the value actually changes.
*/
public inline fun <T> uniqueObservable(initialValue: T, emitInitial: Boolean = false, crossinline onChange: (value: T) -> Unit): ReadWriteProperty<Any?, T> {
if (emitInitial) onChange(initialValue)
return object : ObservableProperty<T>(initialValue) {
override fun afterChange(property: KProperty<*>, oldValue: T, newValue: T) {
if (oldValue != newValue) onChange(newValue)
}
}
@ggrell
ggrell / fadeTo.kt
Created April 22, 2021 21:04 — forked from gpeal/fadeTo.kt
Fade To
/**
* Fade a view to visible or gone. This function is idempotent - it can be called over and over again with the same
* value without affecting an in-progress animation.
*/
fun View.fadeTo(visible: Boolean, duration: Long = 500, startDelay: Long = 0, toAlpha: Float = 1f) {
// Make this idempotent.
val tagKey = "fadeTo".hashCode()
if (visible == isVisible && animation == null && getTag(tagKey) == null) return
if (getTag(tagKey) == visible) return
@ggrell
ggrell / FragmentA.kt
Created April 22, 2021 21:02 — forked from gpeal/FragmentA.kt
View Binding Delegates
class WifiNetworksFragment : TonalFragment(R.layout.wifi_networks_fragment) {
// This automatically creates and clears the binding in a lifecycle-aware way.
private val binding: WifiNetworksFragmentBinding by viewBinding()
...
}
class WifiNetworkView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
@ggrell
ggrell / ContentView.swift
Created February 12, 2021 22:16 — forked from Snowy1803/ContentView.swift
This code allows you to use matchedGeometryEffect in SwiftUI while keeping iOS 13 compatibility in your app.
//
// ContentView.swift
// Example of using matchedGeometryEffect in iOS 13 code
// matchedGeometryEffect example code taken and adapted from :
// https://sarunw.com/posts/a-first-look-at-matchedgeometryeffect/
//
// Created by Emil Pedersen on 16/10/2020.
//
struct ContentView: View {
@ggrell
ggrell / DaggerParentChildExample.kt
Created October 31, 2020 18:18 — forked from arkivanov/DaggerParentChildExample.kt
Dagger parent-child example
// Deps
interface Database
interface Network
// Child
interface ChildRepository
class Child(dependencies: Dependencies) {
@ggrell
ggrell / StateMachine.kt
Created April 26, 2020 02:11 — forked from brendanw/StateMachine.kt
StateMachine.kt is a 34-line implementation of a Mealy state machine tested for multi-threaded coroutines in kotlin multiplatform. SearchStateMachine.kt is an example usage of the state machine; Search.kt defines the input actions and set of states. For more background, read http://brendanweinstein.com/a-statemachine-for-multithreaded-coroutines…
import com.basebeta.utility.logging.kprint
import kotlinx.atomicfu.atomic
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.BroadcastChannel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
class StateWrapper<T>(var state: T)
/**
@ggrell
ggrell / ContentView.swift
Created February 28, 2020 17:43 — forked from Julioacarrettoni/ContentView.swift
Neumorphism in SwiftUI
/// This is a simple example of Neumorphism applied to buttons in SwiftUI
/// As seen on https://twitter.com/dev_jac/status/1228575575171723264
/// This should work straight out of the box, no other files are required
import SwiftUI
extension Color {
static let mainColor = Color(red: 224/255, green: 229/255, blue: 236/255)
static let mainColorActive = Color(red: 220/255, green: 225/255, blue: 232/255)
static let grayShadow = Color(red: 163/255, green: 177/255, blue: 198/255)