Skip to content

Instantly share code, notes, and snippets.

View ryanamaral's full-sized avatar

Ryan Amaral ryanamaral

View GitHub Profile
import { BitBuilder, BitReader, Cell, beginCell } from "@ton/ton";
const OFFCHAIN_CONTENT_PREFIX = 0x01;
export function encodeOffChainContent(content: string) {
let data = Buffer.from(content);
let offChainPrefix = Buffer.from([OFFCHAIN_CONTENT_PREFIX]);
data = Buffer.concat([offChainPrefix, data]);
return makeSnakeCell(data);
}
@stevdza-san
stevdza-san / StopwatchAnimation.kt
Created June 29, 2022 18:54
Create a Stopwatch Animation on a Text with Jetpack Compose
import androidx.compose.animation.*
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
@fergusonm
fergusonm / gist:b8cb267a1319b25e11c0d73613f956c4
Created October 21, 2021 21:06
Flow with lifecycle extension functions
inline fun <reified T> Flow<T>.observeWithLifecycle(
lifecycleOwner: LifecycleOwner,
minActiveState: Lifecycle.State = Lifecycle.State.STARTED,
noinline action: suspend (T) -> Unit
): Job = lifecycleOwner.lifecycleScope.launch {
flowWithLifecycle(lifecycleOwner.lifecycle, minActiveState).collect(action)
}
inline fun <reified T> Flow<T>.observeWithLifecycle(
fragment: Fragment,
@dnburgess
dnburgess / gist:94e08122ce9dfcf6c3cd416aa94e8be0
Created August 3, 2021 21:21
FireFox Connecting to VPN Docker Container
---
version: "2.1"
volumes:
firefox:
services:
firefox:
image: ghcr.io/linuxserver/firefox
container_name: firefox
@tkuenneth
tkuenneth / MainActivity.kt
Created May 29, 2021 10:07
How to display an adaptive icon in Jetpack Compose
package com.thomaskuenneth.sandbox
import android.graphics.Bitmap
import android.graphics.Canvas
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.MaterialTheme
#https://twitter.com/officialmcafee/status/1397568860082122752
#https://twitter.com/ahakcil/status/1397888724936105987
import random
import copy
RST = '\033[0m'
def rand_data(size):
d = []
class LocationActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Listen to one flow in a lifecycle-aware manner using flowWithLifecycle
lifecycleScope.launch {
locationProvider.locationFlow()
.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
.collect {
// New location! Update the map
@gmk57
gmk57 / Sending events to UI.kt
Last active September 26, 2024 17:17
Sending events to UI with Channel/Flow + custom collector (see my first comment for reasons behind it)
/**
* Starts collecting a flow when the lifecycle is started, and **cancels** the collection on stop.
* This is different from `lifecycleScope.launchWhenStarted { flow.collect{...} }`, in which case
* the coroutine is just suspended on stop.
*/
inline fun <reified T> Flow<T>.collectWhileStarted(
lifecycleOwner: LifecycleOwner,
noinline action: suspend (T) -> Unit
) {
object : DefaultLifecycleObserver {
@geerlingguy
geerlingguy / mariadb.yml
Last active January 29, 2024 19:43
Wordpress in Kubernetes K3s on Raspberry Pi
# This manifest assumes 'wordpress' namespace is already present:
#
# kubectl create namespace wordpress
#
# Apply the manifest with:
#
# kubectl apply -f mariadb.yml
---
apiVersion: v1
kind: Secret
@productinfo
productinfo / MacOS Homebrew Install Java.md
Created April 27, 2020 14:38 — forked from gwpantazes/How to Install JDK MacOS Homebrew.md
How to install different Java Versions with Homebrew on MacOS

We will install OpenJDK for anything Java 8 and later. Anything prior is probably Oracle JDK.

Prerequisite: Install Homebrew.

Remember to update your formulas.

$ brew update

Latest OpenJDK Feature Release (Java 12, 13, 14, etc...)