Skip to content

Instantly share code, notes, and snippets.

View cybrox's full-sized avatar
☠️
Tinkering

Sven Gehring cybrox

☠️
Tinkering
View GitHub Profile
@cybrox
cybrox / main.dart
Created July 11, 2022 16:06
fuchsia-osmium-4706
import 'package:flutter/material.dart';
import 'dart:typed_data';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@cybrox
cybrox / main.dart
Last active March 9, 2022 09:32
Dart Timed Event Display
class HypotheticalService {
final _stack = <Event>[];
Event? _lastDisplayed;
void reportEvent(Event event) {
print("${DateTime.now()} Adding ${event.runtimeType} to stack");
_stack.add(event);
_outputLatest();
}
# [debug] frame time: 495ms, listeners: 1, changes: 14
[
<<175, 77, 79, 68, 69, 95, 70, 73, 88, 95, 83, 73, 78, 71, 76, 69, 9, 4, 1, 1,
0, 0, 147, 204, 255, 204, 255, 204, 255>>,
<<175, 77, 79, 68, 69, 95, 70, 73, 88, 95, 83, 73, 78, 71, 76, 69, 9, 5, 1, 1,
0, 0, 147, 204, 255, 204, 255, 204, 255>>,
<<175, 77, 79, 68, 69, 95, 70, 73, 88, 95, 83, 73, 78, 71, 76, 69, 9, 6, 1, 1,
0, 0, 147, 204, 255, 204, 255, 204, 255>>,
<<175, 77, 79, 68, 69, 95, 70, 73, 88, 95, 83, 73, 78, 71, 76, 69, 9, 7, 1, 1,
0, 0, 147, 204, 255, 204, 255, 204, 255>>,
@cybrox
cybrox / telegram.exs
Last active May 24, 2019 14:40
Elixir Telegram
use Bitwise
defmodule Telegram do
use Bitwise
@byte 8
@bloc_size 4 * @byte
def get_bloc(telegram, bloc_nr) do
<<bloc::size(32)>> = binary_part(telegram, 2 + (bloc_nr - 1) * 4, 4)
@cybrox
cybrox / ex-mag6.ex
Last active April 30, 2019 11:13
ex-mag6.ex
defmodule Pragmatic do
def supervisor(worker) do
spawn_link(fn ->
worker_pid = spawn_link(worker)
Process.register(worker_pid, :worker) # <- I added this so we can find our worker
Process.flag(:trap_exit, true)
receive do
{:EXIT, ^worker_pid, _} ->
supervisor(worker)
end
@cybrox
cybrox / ex-mag5.ex
Created April 30, 2019 11:03
ex-mag5.ex
defmodule Pragmatic do
def worker(state \\ nil) do
receive do
{:set, value} ->
worker(value)
{:get, from} ->
send(from, state)
worker(state)
end
@cybrox
cybrox / ex-mag4.ex
Last active April 30, 2019 11:37
ex-mag4.ex
worker_function = fn ->
:timer.sleep(1_000)
IO.puts("completed at #{:erlang.system_time()}")
end
Pragmatic.supervisor(worker_function)
#> completed at 1556621845035672000
#> completed at 1556621846038645599
#> completed at 1556621847039733259
@cybrox
cybrox / ex-mag3.ex
Created April 30, 2019 10:48
ex-mag3.ex
defmodule Pragmatic do
def supervisor(worker) do
spawn_link(fn ->
Process.flag(:trap_exit, true)
worker_pid = spawn_link(worker)
receive do
{:EXIT, ^worker_pid, _} ->
supervisor(worker)
end
end)
@cybrox
cybrox / ex-mag2.ex
Last active April 30, 2019 09:49
ex-mag2.ex
defmodule Recursive do
def function do
receive do
_ -> function()
end
end
end
@cybrox
cybrox / ex-mag1.ex
Created April 30, 2019 09:41
ex-mag1.ex
defmodule Recursive do
def function do
function()
end
end