Skip to content

Instantly share code, notes, and snippets.

View morishin's full-sized avatar
🦍
ウホホ

Shintaro Morikawa morishin

🦍
ウホホ
View GitHub Profile
@morishin
morishin / spv.md
Last active December 22, 2017 17:08

※図は Mastering Bitcoin (PDF) からの引用

SPV (Simplified Payment Verification) を支える技術

Bitcoin クライアントの種類

node_types

UTXO (Unspent Transaction Output)

  • ビットコインウォレットの残高は、ビットコインネットワークから自分のビットコインアドレスが output になっているトランザクションの情報 UTXO (Unspent Transaction Output) を集めて金額を合計したもの
  • ビットコインで支払うぞってなったら、集めて使おうとしてる UTXO が本当にまだ使われてないかをチェックする必要がある
  • UTXO が使われていないかどうかの検証は、そのトランザクションより下の全てのブロックに含まれる全てのトランザクションをチェックする
  • 全部集めるにはブロックチェーン全部をダウンロードして探索しないといけない?
@morishin
morishin / currency.1m.js
Last active January 30, 2018 03:35
BitBar Plugin - Show Crypt Currency Rates to JPY
#!/usr/bin/env /path/to/the/node/executable
const https = require('https')
const Currency = {
Bitcoin: 'btc',
Ethereum: 'eth',
EthereumClassic: 'etc',
Lisk: 'lsk',
Factom: 'fct',
@morishin
morishin / left-align-stack-view.png
Last active March 22, 2024 00:25
Align to Left the contents of UIStackView
left-align-stack-view.png
import UIKit
extension UIView {
func addBorderViews(top: Bool = false, left: Bool = false, bottom: Bool = false, right: Bool = false, color: UIColor = .black, width: CGFloat = 1.0) {
if top {
let borderView = UIView()
borderView.translatesAutoresizingMaskIntoConstraints = false
addSubview(borderView)
borderView.topAnchor.constraint(equalTo: topAnchor).isActive = true
borderView.leftAnchor.constraint(equalTo: leftAnchor).isActive = true
import Foundation
struct Hoge {
static var staticVar = Date()
static var staticComputedVar: Date { return Date() }
static let staticLet = Date()
static let staticLet2 = { return Date() }()
}
Hoge.staticVar == Hoge.staticVar // true
@morishin
morishin / 1_playground.swift
Last active February 26, 2021 10:27
Circular UIView with drop shadow (using UIBezierPath)
import UIKit
import PlaygroundSupport
let container = UIView(frame: CGRect(x: 0, y: 0, width: 500, height: 200))
container.backgroundColor = .lightGray
let buttonRadius: CGFloat = 50
let buttonSize = CGSize(width: buttonRadius * 2, height: buttonRadius * 2)
let buttonPath = UIBezierPath(arcCenter: CGPoint(x: buttonRadius, y: buttonRadius), radius: buttonRadius, startAngle: 0, endAngle: CGFloat.pi * 2, clockwise: true)
@morishin
morishin / lambda-proxy.js
Created March 19, 2017 05:21
Call Lambda function from Lambda function
exports.handler = function(event, context, callback) {
var aws = require('aws-sdk');
var lambda = new aws.Lambda();
lambda.invoke({
FunctionName: 'your-lambda-function-name',
Payload: JSON.stringify(event)
}, function(error, data) {
if (error) {
context.done('error', error);
import Foundation
protocol EitherProtocol {
associatedtype Left
associatedtype Right
func either<Result>(ifLeft: (Left) -> Result, ifRight: (Right) -> Result) -> Result
}
extension EitherProtocol {
import Foundation
import Runes
struct Recipe {
let imageURLString: String?
}
let recipe = Recipe(imageURLString: "http://hoge/image.png")
// default
if let imageURLString = recipe.imageURLString, let imageURL = URL(string: imageURLString) {
@morishin
morishin / 1-uistackview-in-uiscrollview.playground.swift
Last active October 24, 2024 03:37
Example: UIStackView in UIScrollView
import UIKit
import PlaygroundSupport
let scrollView = UIScrollView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
scrollView.backgroundColor = .red
let stackView = UIStackView(frame: CGRect(x: 0, y: 0, width: 1000, height: 100))
stackView.backgroundColor = .gray
stackView.axis = .horizontal
stackView.spacing = 10