Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
<100 subscribers
Uvicorn & Gunicorn
Uvicorn and GunicornUvicorn and Gunicorn are important concepts when developing applications in Python. However, there are many concepts to be aware of in order to fully understand Uvicorn and Gunicorn. The following is a brief summary of the necessary concepts, and the details will be dealt with separately later.Necessary ConceptsStarletteStarlette is a Web application server that can run asynchronously. Starlette runs on top of Uvicorn.FastAPIFastAPI provides many features on top of Starlet...
Gas optimization in Solidity, Ethereum
I’m sorry but my English is terrible. I hope you understand that generously.Recently, I was developing a toy project named Blind Market. It’s a simple P2P trading application using smart contract. I was making a contract using Solidity, and the trade stage proceeded in the order of pending, shipping, and done. The problem was appeared in done phase. The problem was that when I tried to close the transaction by paying the price raised by the seller in msg.value, the following error occurred.Pe...
P2WPKH
P2WPKHP2WPKH란 비트코인 내에서 가장 일반적인 스크립트 형식으로 비트코인 프로토콜에 대한 지불 거래 유형이다. 주소는 1로 시작하는데, 세그윗을 지원하는 새로운 주소 3 또는 bc1로 시작하는 주소보다 훨씬 비싸다. https://mirror.xyz/0xA1d9f681B25C14C1eE7B87f1CF102E73cA3ad4d9/egjhNVklgy_LgZmcTXXAOTBa6ePBqO3Ja9ZSoDIad-8 즉, 비트코인 주소가 1로 시작하면 P2PKH 주소를 사용하고 있는 것이다. 공개키의 간단한 해시이며, 이 해시를 주소로 사용하는 것이다. 이것은 원래 비트코인 주소 형식이었으며 오늘까지도 충실히 작동한다. 레거시 주소는 세그윗과 호환되지 않지만, 여전히 문제없이 P2PKH 주소에서 세그윗 주소로 BTC를 보낼 수 있다. 그러나 레거시 주소 트랜잭션이 더 크기 때문에 P2PKH 주소에서 전송하는 평균 속도는 세그윗 주소에서 전송할 때보다 더 높은 요금이 발생할 수 있다....
Share Dialog
Share Dialog
golang에는 빌트인으로 사용할 수 있는 container package가 있다.
개발을 하다보면, 자료구조를 사용할 일이 꽤 생긴다.
go에서는 container 패키지에서 기본 자료구조를 제공해주므로 꽤나 편리하게 사용할 수 있다.
패키지에서 제공하는 자료구조는 다음과 같다.
Linked list
Heap
Ring (Circular list)
container 패키지를 이용해서 간단한 자료구조를 구현해보자.
package main
import (
"container/list"
"log"
)
func main() {
lst := list.New()
lst.PushBack(1)
lst.PushBack(2)
lst.PushBack(3)
log.Println(lst.Len())
}
위와 같이 container/list 패키지를 import하면, 손쉽게 linked list를 사용할 수 있다.
개발을 하면서 linked list를 사용해야 한다면, 꽤나 시간을 단축시킬 수 있을 것이다.
list를 순회하고 싶다면 아래와 같은 방법도 가능하다.
package main
import (
"container/list"
"fmt"
"log"
)
func main() {
lst := list.New()
lst.PushBack(1)
lst.PushBack(2)
lst.PushBack(3)
log.Println(lst.Len())
for e := lst.Front(); e != nil; e = e.Next() { // 연결 리스트의 맨 앞부터 끝까지 순회
fmt.Println(e.Value)
}
}
다음은 heap 패키지이다. 필자는 최근 회사에서 체결엔진/오더북을 구현하면서 min heap과 max heap을 구현할 일이 있었는데,
container/heap 패키지를 통해 간단하게 구현할 수 있었다.
heap 패키지에서는 기본적으로 다음과 같은 인터페이스가 필요하다.
package heap
type Interface interface {
Len() int
Less(i, j int) bool
Swap(i, j int)
Push(x any)
Pop() any
}
한 번 구현해서 사용해보자. 예제에서는 min heap을 구현해본다.
package main
import (
"container/heap"
"log"
)
type IMinHeap interface {
heap.Interface
}
type MinHeap struct {
heap []uint
}
func (m *MinHeap) Len() int {
return len(m.heap)
}
func (m *MinHeap) Less(i, j int) bool {
return m.heap[i] < m.heap[j]
}
func (m *MinHeap) Swap(i, j int) {
m.heap[i], m.heap[j] = m.heap[j], m.heap[i]
}
func (m *MinHeap) Push(x any) {
m.heap = append(m.heap, x.(uint))
}
func (m *MinHeap) Pop() any {
old := m.heap
n := len(old)
element := old[n-1]
m.heap = old[0 : n-1]
return element
}
func main() {
minHeap := &MinHeap{heap: []uint{}}
heap.Init(minHeap)
heap.Push(minHeap, uint(10))
heap.Push(minHeap, uint(20))
heap.Push(minHeap, uint(50))
heap.Push(minHeap, uint(5))
log.Println(heap.Pop(minHeap)) // 5
log.Println(heap.Pop(minHeap)) // 10
log.Println(heap.Pop(minHeap)) // 20
log.Println(heap.Pop(minHeap)) // 50
}
Less 조건의 부호만 반대로 바꿔줘도 max heap으로 바꾸어 사용할 수 있어 편하다.
다음은 ring이다. ring은 비교적 사용할 일이 많이 없는 듯 보이지만, 알아두면 때때로 도움이 될 수도 있다.
개인적으로는 list를 쓰는 편이긴 하다.
package main
import (
"container/ring"
"fmt"
)
func main() {
data := []string{"Maria", "John", "Andrew", "James"}
r := ring.New(len(data)) // 노드의 개수를 지정하여 링 생성
for i := 0; i < r.Len(); i++ { // 링 노드 개수만큼 반복
r.Value = data[i] // 링의 노드에 값 넣기
r = r.Next() // 다음 노드로 이동
}
r.Do(func(x interface{}) { // 링의 모든 노드 순회
fmt.Println(x)
})
// "Maria"
// "John"
// "Andrew"
// "James"
}
두 개의 ring을 연결하는 것도 물론 가능하다.
package main
import (
"container/ring"
"fmt"
)
func main() {
data := []string{"Maria", "John", "Andrew", "James"}
r := ring.New(len(data)) // 노드의 개수를 지정하여 링 생성
for i := 0; i < r.Len(); i++ { // 링 노드 개수만큼 반복
r.Value = data[i] // 링의 노드에 값 넣기
r = r.Next() // 다음 노드로 이동
}
r.Do(func(x interface{}) { // 링의 모든 노드 순회
fmt.Println(x)
})
// "Maria"
// "John"
// "Andrew"
// "James"
newData := []uint{1, 2, 3, 4}
r2 := ring.New(len(newData))
for i := 0; i < r2.Len(); i++ { // 링 노드 개수만큼 반복
r2.Value = newData[i] // 링의 노드에 값 넣기
r2 = r2.Next() // 다음 노드로 이동
}
r3 := r.Link(r2)
r3.Do(func(x interface{}) { // 링의 모든 노드 순회
fmt.Println(x)
})
// John
// Andrew
// James
// Maria
// 1
// 2
// 3
// 4
}
golang에는 빌트인으로 사용할 수 있는 container package가 있다.
개발을 하다보면, 자료구조를 사용할 일이 꽤 생긴다.
go에서는 container 패키지에서 기본 자료구조를 제공해주므로 꽤나 편리하게 사용할 수 있다.
패키지에서 제공하는 자료구조는 다음과 같다.
Linked list
Heap
Ring (Circular list)
container 패키지를 이용해서 간단한 자료구조를 구현해보자.
package main
import (
"container/list"
"log"
)
func main() {
lst := list.New()
lst.PushBack(1)
lst.PushBack(2)
lst.PushBack(3)
log.Println(lst.Len())
}
위와 같이 container/list 패키지를 import하면, 손쉽게 linked list를 사용할 수 있다.
개발을 하면서 linked list를 사용해야 한다면, 꽤나 시간을 단축시킬 수 있을 것이다.
list를 순회하고 싶다면 아래와 같은 방법도 가능하다.
package main
import (
"container/list"
"fmt"
"log"
)
func main() {
lst := list.New()
lst.PushBack(1)
lst.PushBack(2)
lst.PushBack(3)
log.Println(lst.Len())
for e := lst.Front(); e != nil; e = e.Next() { // 연결 리스트의 맨 앞부터 끝까지 순회
fmt.Println(e.Value)
}
}
다음은 heap 패키지이다. 필자는 최근 회사에서 체결엔진/오더북을 구현하면서 min heap과 max heap을 구현할 일이 있었는데,
container/heap 패키지를 통해 간단하게 구현할 수 있었다.
heap 패키지에서는 기본적으로 다음과 같은 인터페이스가 필요하다.
package heap
type Interface interface {
Len() int
Less(i, j int) bool
Swap(i, j int)
Push(x any)
Pop() any
}
한 번 구현해서 사용해보자. 예제에서는 min heap을 구현해본다.
package main
import (
"container/heap"
"log"
)
type IMinHeap interface {
heap.Interface
}
type MinHeap struct {
heap []uint
}
func (m *MinHeap) Len() int {
return len(m.heap)
}
func (m *MinHeap) Less(i, j int) bool {
return m.heap[i] < m.heap[j]
}
func (m *MinHeap) Swap(i, j int) {
m.heap[i], m.heap[j] = m.heap[j], m.heap[i]
}
func (m *MinHeap) Push(x any) {
m.heap = append(m.heap, x.(uint))
}
func (m *MinHeap) Pop() any {
old := m.heap
n := len(old)
element := old[n-1]
m.heap = old[0 : n-1]
return element
}
func main() {
minHeap := &MinHeap{heap: []uint{}}
heap.Init(minHeap)
heap.Push(minHeap, uint(10))
heap.Push(minHeap, uint(20))
heap.Push(minHeap, uint(50))
heap.Push(minHeap, uint(5))
log.Println(heap.Pop(minHeap)) // 5
log.Println(heap.Pop(minHeap)) // 10
log.Println(heap.Pop(minHeap)) // 20
log.Println(heap.Pop(minHeap)) // 50
}
Less 조건의 부호만 반대로 바꿔줘도 max heap으로 바꾸어 사용할 수 있어 편하다.
다음은 ring이다. ring은 비교적 사용할 일이 많이 없는 듯 보이지만, 알아두면 때때로 도움이 될 수도 있다.
개인적으로는 list를 쓰는 편이긴 하다.
package main
import (
"container/ring"
"fmt"
)
func main() {
data := []string{"Maria", "John", "Andrew", "James"}
r := ring.New(len(data)) // 노드의 개수를 지정하여 링 생성
for i := 0; i < r.Len(); i++ { // 링 노드 개수만큼 반복
r.Value = data[i] // 링의 노드에 값 넣기
r = r.Next() // 다음 노드로 이동
}
r.Do(func(x interface{}) { // 링의 모든 노드 순회
fmt.Println(x)
})
// "Maria"
// "John"
// "Andrew"
// "James"
}
두 개의 ring을 연결하는 것도 물론 가능하다.
package main
import (
"container/ring"
"fmt"
)
func main() {
data := []string{"Maria", "John", "Andrew", "James"}
r := ring.New(len(data)) // 노드의 개수를 지정하여 링 생성
for i := 0; i < r.Len(); i++ { // 링 노드 개수만큼 반복
r.Value = data[i] // 링의 노드에 값 넣기
r = r.Next() // 다음 노드로 이동
}
r.Do(func(x interface{}) { // 링의 모든 노드 순회
fmt.Println(x)
})
// "Maria"
// "John"
// "Andrew"
// "James"
newData := []uint{1, 2, 3, 4}
r2 := ring.New(len(newData))
for i := 0; i < r2.Len(); i++ { // 링 노드 개수만큼 반복
r2.Value = newData[i] // 링의 노드에 값 넣기
r2 = r2.Next() // 다음 노드로 이동
}
r3 := r.Link(r2)
r3.Do(func(x interface{}) { // 링의 모든 노드 순회
fmt.Println(x)
})
// John
// Andrew
// James
// Maria
// 1
// 2
// 3
// 4
}
No comments yet