## Tuesday, March 07, 2023

### Bode plot of a simple pendulum

With a little assistance from ChatGPT,

A Bode plot is a graphical representation of the frequency response of a system, which shows how a system responds to input signals of different frequencies. To make a Bode plot of a pendulum, you first need to model the pendulum mathematically as a system that responds to input signals.

Assuming that the pendulum is a simple pendulum, you can model it as a second-order system with a transfer function of the form:

G(s) = K / (s^2 + 2ζωn s + ωn^2)

where K is the gain, ωn is the natural frequency of the pendulum, and ζ is the damping ratio.

To obtain the Bode plot, you can plot the magnitude and phase of the transfer function G(s) as a function of frequency, ranging from 0 to infinity. To do this, you can express the transfer function in terms of frequency by substituting s = jω, where j is the imaginary unit and ω is the frequency in radians per second.

Once you have obtained the transfer function in terms of frequency, you can plot the magnitude and phase of G(jω) as a function of log(ω). The magnitude plot shows how the amplitude of the pendulum's response varies with frequency, while the phase plot shows how the phase of the response varies with frequency.

The Bode plot of a pendulum can provide insights into the system's stability and performance, and can be useful in designing control systems to regulate the pendulum's motion.

python code that will compute the transfer function of a pendulum of a given length and mass. and displays a bode plot

import numpy as np
from scipy import signal
from control import matlab
import matplotlib.pyplot as plt
# Define pendulum parameters
l = 1.0   # length of pendulum in meters
m = 1.0   # mass of pendulum in kilograms
g = 9.81  # acceleration due to gravity in m/s^2
# Compute natural frequency and damping ratio
wn = np.sqrt(g / l)
zeta = 0.05
# Define transfer function
num = [1.0]
den = [1.0, 2*zeta*wn, wn**2]
G = signal.TransferFunction(num, den)
# Compute frequency response
w, mag, phase = signal.bode(G)

# Compute frequency response
# omega = np.logspace(-2, 2, 1000)
# mag, phase, omega = matlab.bode(G, omega)
# Display Bode plot
plt.figure()
plt.semilogx(w , mag)
plt.ylabel('Magnitude [dB]')
plt.title('Bode Plot')
plt.grid()
plt.show()

This code defines the length and mass of the pendulum, computes the natural frequency and damping ratio, and defines the transfer function using the `signal.TransferFunction` function. It then computes the frequency response using the `matlab.bode` function and displays the Bode plot using the `matplotlib` library. You can adjust the values of `l`, `m`, and `zeta` to see how they affect the Bode plot.

## Thursday, February 16, 2023

### OpenSCAD model of a Syringe

module syringe(pos=0){

%cylinder(r=29.3/2, h=132,\$fn=50);

translate([0,0,132])
cylinder(r=29.3/2, r2=9.3/2 ,h=6,\$fn=50);

translate([0,0,132+6])
cylinder(r=9.3/2 ,h=7,\$fn=50);

translate([0,0,132+6+7])
cylinder(r=4/2 ,h=2,\$fn=50);

//cube([50,33,2.3],true);
linear_extrude(2)
offset(+3)
hull(){
circle(r=33/2 -3);
square([50-6,16-6],true);
}

translate([0,0,-12-pos])
cylinder(r=31/2, h=1.7,true);

translate([0,0,-12-pos])  //120 is fully extended.
cylinder(r=17/2, h=140 );

}

syringe(pos=abs(120 - (\$t * 240))) ;

## Wednesday, February 15, 2023

### Lightning Talks @ Hacker Dojo - John Sokol

My talk about a a web3 architecture.

Funny how one guy is like Why not use Mastodon, And a minute later another is tell how he was Banned from Mastodon.

Mastodon, sorry looks like it's striking out.

Seems the biggest challenge these people have is trying to P2P or the illusion of it while still being a nanny state.

## browser tab storage

In a browser tab,   can store persistently across reboots 5MB based on the server address.

And SessionStorage, as long as a tab is kept open, is Limited only by system memory; it could be many Gigabytes.

How big can localStorage be?

LocalStorage and SessionStorage

Storage TypeMax Size

LocalStorage 5MB per app per browser. According to the HTML5 spec, this limit can be increased by the user when needed; however, only a few browsers support this

SessionStorage Limited only by system memory

SO we can choose to keep 5 MB permanently in your browser that the web site can access, (your keys,creditiats, boot code) and keep on the machine could be 100's of megabytes.

Within an open tab

Using a RAID-like redundancy scheme, the data can be  broken up into pieces, called stripes. With a little added redundancy that will tell me what data is missing and be able to reconstruct before we lose enough to become unrecoverable..

In raid,you can remove a hard drive, and replace it, it will begin to restore the missing data to the new drive based on redundant (extra copies) in the array

https://www.gwtproject.org/doc/latest/DevGuideHtml5Storage.html

# Use of WebRTC for P2P communications directly between browser tabs.

https://webrtc.github.io/samples/

RTCPeerConnection

https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection

The Strange Irony is all This originated from My 1997 video streaming company.

https://www.ecip.com/fwdoc.htm

https://johnsokol.blogspot.com/2006/12/how-skype-punches-holes-in-firewalls.html

## Ad-Hoc Hybrid star mesh topology

For this to work some users will need to run Node.js servers in the cloud to act as relays. in a Hybrid star mesh topology

black being HTML5 - browser Tabs, and white (node.js cloud instances) relays

A relay is most likely a Node.js instance that is used to establish webrtc links between tabs.

Between relays is a publish and subscribe communications message bus that forms the layer 1 one of communications coordination and initialization and signaling.

Also a Tab can enter a URL of another Relay and have its host relay establish a link. Bridging relays and allowing cross relay content searches, and its client tabs together into one larger network.

I see relays as being more Slaves devices responding to request and serving a database of local clients with assets.

All content addressed by relay name (URL or IP) will look like a normal website.

Relays may use standard username and password or cookies to control access. And charge access fees per month.

Relays may blacklist other relays or URL's???

Some relays may only be accessible through relays to gain credentials.

http://Relay/Hash

Such as https://relay.johnsokol.com:2222/dd5db37a4c79ea699c3a8084d5a74aef

For the most part a address here is indistinguishable from a normal URL intended for a browser and indeed, it will serve up some default HTML content. It's really intended to be connected to by websocket.

Externally when a user directly connects, they can  get one of only a few pieces of externally accessible content  This is a list of hashes or usl's -> hash defined in a config file loaded at startup. Whatever the admin has decided for them. Maybe a sign up page with payment.

Internally, on the bus the request is published.  A special Admin Tab, is keeping a database and subscribed, and furfulls  requests.

The Node will broadcast to all subscribing tabs the request and send the content to be sent as an HTML web page from the node.js relay.  For non-websocket basic http requests.

All other content requests from there are done using our internal messaging protocol over a websocket to the relay server to the tabs and p2p over webrtc directly between users tabs to avoid bandwidth consumption of the cloud relay.

For this to work there must be a significant javascript communications layer running in the users tab.

There should be some form of access control to the relay to prevent DOS attacks. Or maybe a way to put behind services such as cloudflare?

Some relays are only accessible by other relays and not openly available. Ie- websocket only interfaces. So HTTP content can be served from CDN.

# Basic Session flow

A Tab based javascript that manages the Relay, and its backend services,  keeping a database of users  and subscribes to messages, and furfulls  some requests.

Some login credentials are in the Node.js config file and entered for the first time a Admin accesses a relay with a new Browser, from this point these are stored in cookies.

## Normal Tab

Regular web users click links on social media. They are directed to the Node relay that messages its websock connected clients.

These Posting clients are subscribed to the relay for certain requests and respond with the  content. Ideally this is a JS Client, that then can present the content as fetched over WebRTC.

The receiving client Tab establishes a WEBRTC data transfer request, for decoded content. The initially needed Javascript and HTML needed to invoke it.

From this point the open webrtc request can be made to established tabs, or use the existing websocket ro the relay and query where to make the next webrtc connections to load the next pieces of content.

This is all Dynamic HTML , generated by Javascript internal to the browser.

We can send over js code , and run in the browser to produce APPS in a distributed computing platform.

For this application, it's to act as a file server.

# Still to work out

Rules for Security and Access control models, so what should I allow hosted into my Tab?

How to deal with Pigs, and bad actors?  Seems the initial responsibility is that of the relay/s.

What handles and tracking meta data do we want to keep on data?

Do we want Authorities and other investigators to be able to do forensics?

This is more of a design decision embedded in the javascript libraries.

Maybe using the 5MB local store to keep a persistence database , with user credentials , certs, and keys,  and boot javascript images. Configuration options, who gets to use up my memory and with what.

Creation of an internal VM in javascript to allow daemon processes to subscribe to client disconnect or content lost messages to trigger data reconstruction and backup into tabs with available storage.

Think storage should be block oriented. Databases , archive storage systems and such can be built on the top of this.

We may need external addition stun , turn and Ice servers for webRTC communications initiation in addition to the node relay.   (TBD)

# Other similar existing projects with working example code. Components that could be built upon.

## PeerJS

PeerServer: A server for PeerJS

PeerServer helps establish connections between PeerJS clients. Data is not proxied through the server.

https://peerjs.com

## PeerServer

PeerServer: A Server in the Browser with WebRTC

Croquet

https://croquet.io/docs/index.html

## OS-JS - Super cool.

I didn't realize the file system is remote and shared by everyone at first.
As such the demo site gets corrupted after a while.

https://demo.os-js.org/

https://www.os-js.org/

## CYFS is short for CYberFileSystem

Holly shit, nearly identical to what I was thinking. After a solid 2 weeks of researching I only found out about this because of an upcoming hackathon with a \$10,000 prize.

## Croquet

Instantaneous Shared Experiences is how we describe Croquet on our website

https://blog.codefrau.net/2021/08/what-is-croquet-anyways.html

https://croquet.io/docs/croquet/

# Part of Bluesky initiative.

## Gun DB.    - Mark Nadal  Gave talk in dojo in January.

https://gun.eco/

https://github.com/amark/gun

## Nostr

https://nostr.com/

https://github.com/nostr-protocol/nostr

### What is Nostr?

A decentralized network based on cryptographic keypairs and that is not peer-to-peer, it is super simple and scalable and therefore has a chance of working. Read more about the protocol. You can also reach us at our Telegram group (while we don't have a decent group chat application fully working on Nostr).

They now have a javascript port of IPFS  (a complete game changer for the Eth/IPFS model)

https://js.ipfs.tech/

DAG

https://docs.ipfs.tech/concepts/merkle-dag/

# Articles:

Erasure Codes:

Nodes are going to dethrone tech giants — from Apple to Google

Authors History:

Original Amorphous OS talk from 2000 at the ACCU.

https://www.johnsokol.com/~sokol/amorp/amorphous1_files/v3_document.htm

http://www.dnull.com/meshcast/meshcast/

Decash - crypto payment system 2004

https://web.archive.org/web/20040328083934/http://decash.com/

https://johnsokol.blogspot.com/2018/02/opensecret-unforgeable-proof-of.html

FileSharing P2P & SOA

Idea is to combine Peer to Peer and Server Oriented architecture. This will be especially useful for very large files (over 500 MB files).

Other things to see:

Full Linux on Intel X86 running in a webassembly based emulator in a browser tab.

https://churchofbsd.blogspot.com/2020/06/jslinux-pcx86-emulator-in-javascript.html

https://churchofbsd.blogspot.com/2020/06/a-browser-on-linux-with-x-windows-in.html

from my notes in Amorphous.  2012

File System

Like the URL scheme, but rather than point to a host and domain name. Instead we can point to a network file system object, there could be several. These too inherit their security permissions and preinstalled configs, appropriate version dependencies and base objects.

The intent is every application has a constructor or factory that builds its world before it executes. Version appropriate shared libraries will be loaded as needed.

Network, distributed Cache system. Built around git style version control and code distribution.

Could be based on the GIT Hash Abstraction layer.

Where files are mapped to a HashKey reference in a directory listing ( index )

Duplicates are automatically consolidated.

If a file system were based on this then rather than checkout a version, you mount a version and branch.

you can share back your changes, people check these in and out.

Changes from git, you can mount and build file systems for different apps. carefully quarantine programs.

Infinite granularity.

Directory entries in JSON or equivalent directory name value pairs. Recursive objects defined.

that finally point to actual files and the index directory file can have complete granularity in control and permissions.

File is actually pointed to as a hash key, within the hash key is an object who matches that hash or a placeholder object that references the location to fetch the real one.

Software install/upgrade/revert/remove is a git checkout for a sub-directory within a larger repo.

Applications are just a link to a directory entry. This intern starts the retrieval engine who will query it's upstream caches for instructions on how to fetch this data.

Files can be encrypted. can call other dependent objects to perform encryption or compression or other translation or interpretation.

File attributes include:

Ownership, license, URL, EMAIL, (TRACK, BACKTRACE, REPORT, UPDATE) Callback URL.

Permis