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
@Iksas
Iksas / bullseye-remote-upgrade.md
Last active February 2, 2025 22:41
Raspberry Pi: Remote upgrade from Buster to Bullseye (via WiFi)

Buster >> Bullseye - Remote upgrade

These instructions can be used to upgrade Raspberry Pi OS from Buster to Bullseye with only an SSH connection (no physical access). Some addidional steps are performed to make sure that the Pi automatically joins the WiFi network after upgrading. This is necessary if the Pi is located in a remote or hard to reach location.

Especially on older Pis, the upgrade will take several hours, so plan accordingly.

If you have physical access to the Pi, consider making a backup of the SD card with the SD Card Copier utility (red berry menu in the top left >> Accessories >> SD Card Copier). If the SD Card Copier is not in the menu, you can install it with sudo apt install piclone.

@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 March 3, 2025 15:45
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 April 6, 2025 07:22
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