Skip to content

Instantly share code, notes, and snippets.

View WeRockStar's full-sized avatar

Kotchaphan Muangsan WeRockStar

View GitHub Profile
@WeRockStar
WeRockStar / publickey
Last active February 2, 2022 15:45 — forked from pollux-/publickey
Extract the public key from a certificate
Generate public key + sha256 rely on X.509
1. openssl s_client -connect api.github.com:443 | openssl x509 -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64
2. openssl x509 -noout -in certificate.pem -pubkey | openssl asn1parse -noout -inform pem -out public.key openssl dgst -sha256 -binary public.key | openssl enc -base64
3. openssl rsa -in my-rsa-key-file.key -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64
4. openssl req -in my-signing-request.csr -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64
5. openssl x509 -in my-certificate.crt -pubkey -noout | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64
Covert PEM to DER
openssl x509 -outform der -in certificate.pem -out certificate.der
@WeRockStar
WeRockStar / create-keys-and-certificates.kts
Created January 14, 2021 14:20 — forked from fschutte/create-keys-and-certificates.kts
Kotlin script for creating keys and certificates
import sun.security.x509.*
import java.io.File
import java.math.BigInteger
import java.security.*
import java.security.cert.X509Certificate
import java.util.*
/**
* Simple script for generating keys and certificates as needed to connect to the ING API.
@WeRockStar
WeRockStar / AlamofireSessionManagerBuilder.swift
Created January 12, 2021 15:06 — forked from RodrigoLGuimaraes/AlamofireSessionManagerBuilder.swift
Creation of a Moya provider with SSL pinning
// 1 - provider creation
let provider = MoyaProvider<MyRouter>(
manager: AlamofireSessionManagerBuilder().build()
)
// 2 - session manager builder
class AlamofireSessionManagerBuilder {
var policies: [String: ServerTrustPolicy]?
var configuration = URLSessionConfiguration.default
@WeRockStar
WeRockStar / StateMachine.swift
Created July 16, 2020 08:43 — forked from khanlou/StateMachine.swift
A state machine where invalid transitions can't compile
protocol State {}
struct Transition<From: State, To: State> {
let transition: () -> To
}
struct Machine<CurrentState: State> {
var state: CurrentState
@WeRockStar
WeRockStar / TaskConcurrencyManifesto.md
Created November 19, 2019 04:12 — forked from lattner/TaskConcurrencyManifesto.md
Swift Concurrency Manifesto
@WeRockStar
WeRockStar / async_swift_proposal.md
Created November 19, 2019 04:07 — forked from lattner/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

@WeRockStar
WeRockStar / ObservableType+compose.swift
Created November 14, 2019 06:22 — forked from sgr-ksmt/ObservableType+compose.swift
compose operator for RxSwift
struct ComposeTransformer<T, R> {
let transformer: (Observable<T>) -> Observable<R>
init(transformer: @escaping (Observable<T>) -> Observable<R>) {
self.transformer = transformer
}
func call(_ observable: Observable<T>) -> Observable<R> {
return transformer(observable)
}
}
@WeRockStar
WeRockStar / latency.txt
Created June 10, 2019 02:45 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@WeRockStar
WeRockStar / openssl_commands.md
Created March 18, 2019 13:53 — forked from p3t3r67x0/openssl_commands.md
Some list of openssl commands for check and verify your keys

openssl

Install

Install the OpenSSL on Debian based systems

sudo apt-get install openssl