Skip to content

Instantly share code, notes, and snippets.

View zeroFruit's full-sized avatar
🎯
Focusing

JooHyung Kim zeroFruit

🎯
Focusing
View GitHub Profile
@zeroFruit
zeroFruit / swch.go
Created October 31, 2020 12:24
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Switch
type ForwardEntry struct {
// Incoming is port id attached to switch
Incoming Id
// Addr is destination node address
Addr types.HwAddr
// Time is timestamp when this entry is created
Time time.Time
}
@zeroFruit
zeroFruit / host.go
Last active October 31, 2020 12:22
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Host, Interface
package link
type Transmitter interface {
Transmit(frame []byte) error
}
type Interface interface {
Transmitter
EndPoint
Address() types.HwAddr
@zeroFruit
zeroFruit / addr.go
Created October 31, 2020 12:21
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: MAC address
package link
type Addr string
@zeroFruit
zeroFruit / host.go
Created October 31, 2020 12:19
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Network Topology
package link
type Link struct {
cost uint
ep1 EndPoint
ep2 EndPoint
}
func (l *Link) AttachEndpoint(ep EndPoint) error {
...
@zeroFruit
zeroFruit / comm.go
Last active October 31, 2020 12:18
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Network Adapter
package na
// Card is abstracted network adapter part to simulate bytes transport on
// physical cable. Node's interface uses this interface to send frame
// between nodes.
type Card interface {
Send(buf []byte, addr string) (time.Time, error)
Recv() <-chan *FrameData
}
@zeroFruit
zeroFruit / addr.go
Created October 31, 2020 12:13
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet
package link
type Addr string
@zeroFruit
zeroFruit / testnet_btc_example.go
Created July 30, 2020 15:41
Testnet BTC create address, createRawTransaction example
package main
import (
"bytes"
"encoding/hex"
"fmt"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
@zeroFruit
zeroFruit / allGood.js
Created July 5, 2018 09:24
All good & One good
let allGood = true;
proposalResponses.forEach((pr) => {
let oneGood = false;
if (pr.response && pr.response.status === 200) {
oneGood = true;
logger.info('install proposal was good');
} else {
logger.error('install proposal was bad');
}
@zeroFruit
zeroFruit / channel1.go
Created June 30, 2018 03:53
basic channel
package main
import (
"sync"
"fmt"
)
var wg = sync.WaitGroup{}
func main() {
@zeroFruit
zeroFruit / MinHeap.java
Created May 28, 2018 16:12
Min Heap using Generic
/*
* referenced
* 1. http://www.techiedelight.com/min-heap-max-heap-implementation-in-java/
* 2. https://gist.github.com/flexelem/70b120ac9bf2965f419f
* */
class MinHeap<E extends Comparable<E>> {
private ArrayList<E> heap;
MinHeap() {
heap = new ArrayList<>();