Skip to content

Instantly share code, notes, and snippets.

View d-led's full-sized avatar

Dmitry Ledentsov d-led

View GitHub Profile
% exercise: https://www.futurelearn.com/courses/concurrent-programming-erlang/3/steps/488334
-module(palindrome_server).
-export([server/0, server/1, demo/0, demo_client/2]).
-import(timer, [sleep/1]).
server({check,Sentence}) ->
case (palindrome_check(Sentence)) of
true -> {result, Sentence ++ " is a palindrome"};
false -> {result, Sentence ++ " is not a palindrome"}
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
{
# Relaunch as an elevated process:
Start-Process powershell.exe "-File",('"{0}"' -f $MyInvocation.MyCommand.Path) -Verb RunAs
exit
}
Write-Host "Fixing the docker share problem"
Set-NetConnectionProfile -interfacealias "vEthernet (DockerNAT)" -NetworkCategory Private
Set-SmbServerConfiguration -EncryptData 0 -Force
# https://ideone.com/w49bT4
# https://gist.github.com/d-led/e1b18377bbe2cc5dd92cdb54e2183b1b
# inpired by https://andrealeopardi.com/posts/connection-managers-with-gen_statem/
defmodule Counter do
@moduledoc """
This is an example gen_statem based Counter.
The counter enters an invalid state, when decremented at state 0.
To recover from the invalid state, reset it via Counter.reset
"""
  • Official Docs: C Nodes point to the old erl_connect interface, which might put someone off writing a C Node (memory management, etc)
  • Official docs: ei_connect seems to be the preferred way to write C Nodes as of now
    • erl_connect will be removed in OTP 23
  • There's a pure java implementation of C Nodes: github.com/appulse-projects/encon-java
  • Notes
    • C Nodes connect as hidden nodes (cannot be seen in Node.list())
    • there's probably much more to learn: e.g. how to correctly handle certain types of messages sent to the C nodes by OTP
    • after some time with ei_connect, writin C Nodes doesn't look scary anymore
  • now one can e.g. export expensive or specialized computations into external proc
// groovy groovy_vlingo.groovy
package github.dled
@Grapes([
@Grab("io.vlingo:vlingo-actors:0.7.0"),
])
import groovy.transform.CompileStatic
import io.vlingo.actors.*
# created with sonic pi
live_loop :shots do
with_fx :reverb, amp: rrand(0.1, 1.5) do
with_fx :pan, pan: rrand(-1,1) do
sample :bd_haus, rate: 0.5
end
end
sleep rrand(0.1,0.2)
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#https://ideone.com/fJZczA
tasks =
for i <- 1..10 do
Task.async(fn ->
Process.sleep(:rand.uniform(1000))
i
end)
end
Task.yield_many(tasks, 500)
package org.geepawhill.contentment.flow;
import static org.geepawhill.contentment.utility.JfxUtility.color;
import java.util.HashMap;
import java.util.Map;
import org.geepawhill.contentment.format.Format;
import org.geepawhill.contentment.style.Frames;
import org.geepawhill.contentment.style.TypeFace;
import java.util.stream.*;
import java.util.concurrent.*;
public class NoExhaust {
public static void main(String []args){
ExecutorService executor = Executors.newFixedThreadPool(8);
Runnable ticker = () -> {
IntStream.range(1, 150)