Skip to content

Instantly share code, notes, and snippets.

View ya-s-u's full-sized avatar
🍺
Drinking

Yasuaki Goto ya-s-u

🍺
Drinking
View GitHub Profile
@1amageek
1amageek / firestore-hook.ts
Last active April 30, 2020 02:32
Cloud Firestore Collection Reference hooks for React
import { useEffect, useState } from 'react'
import firebase, { database } from "firebase"
import "firebase/firestore"
import "firebase/auth"
import { firestore, Doc, DocumentReference } from '@1amageek/ballcap'
export const useDocumentListen = <T extends Doc>(type: typeof Doc, documentReference?: DocumentReference, waiting: boolean = false): [T | undefined, boolean, Error?] => {
interface Prop {
data?: T
loading: boolean
@ksasao
ksasao / acc.py
Last active September 12, 2018 14:08
iPhoneで心拍を取るテスト。Pythonista 用。実行すると5秒後から5秒間測定を行います。仰向けになってiPhoneを胸の上に置き、息を止めてじっとしていてください。
'''This script records your device's orientation (accelerometer data) for 5 seconds, and then renders a simple plot of the gravity vector, using matplotlib.'''
import motion
import matplotlib.pyplot as plt
from time import sleep
import console
def main():
@ksasao
ksasao / detect_marker.py
Last active December 10, 2023 02:38
ZOZOSUITのマーカーのIDを読み取るコードです。公開されている画像を元に独自に解析しているので、公式ではこのように処理しているかどうかは不明です。仕様等については https://twitter.com/ksasao/status/990779583682170881 のスレッドも参照してください。全身を読み取るコード https://twitter.com/ksasao/status/989842844243279872 ライセンスは Apache License 2.0 です。
import numpy as np
import random
import math
import cv2
from PIL import Image
import sys
def detect_markers(im):
markers = []
# 輪郭線抽出のための二値化
@kishikawakatsumi
kishikawakatsumi / UIScrollView+UIPageControl.swift
Created April 29, 2018 15:21
UIScrollView + UIPageControl with RxSwift
import RxSwift
import RxCocoa
fileprivate extension Reactive where Base: UIScrollView {
fileprivate var currentPage: Observable<Int> {
return didEndDecelerating.map({
let pageWidth = self.base.frame.width
let page = floor((self.base.contentOffset.x - pageWidth / 2) / pageWidth) + 1
return Int(page)
})
@imbradbrown
imbradbrown / WKWebView Anchors.swift
Created April 25, 2018 12:23
WKWebView scroll to anchor location useful if having to add header/footers that scroll with it
@IBOutlet var scrollView: UIScrollView!
var webView: WKWebView!
/// container for the webView in the storyboard
@IBOutlet var webViewContainer: UIView!
/// height of the container
@IBOutlet var webViewHeightConstraint: NSLayoutConstraint!
override func viewDidLoad() {
module Fizz
def call(target, max, state)
if target % 3 == 0
state << "fizz"
end
super
end
end
module Buzz
@Marcocanc
Marcocanc / Label.swift
Last active September 3, 2023 09:14
A UILabel subclass that can hold attributes and apply them to text
import UIKit
/// A UILabel subclass that can hold attributes and apply them to text
@IBDesignable
final class Label: UILabel {
convenience init(attributes: [NSAttributedStringKey: Any]) {
self.init()
self.attributes = attributes
}
// MARK: Properties
@inamiy
inamiy / typed-error-poem.md
Last active November 8, 2018 13:58
Swift Poem: Why I prefer typed error (for https://github.com/apple/swift-evolution/pull/757)

Typed error can be useful in certain cases, especially when accompanied with NoError type.

For example, in reactive programming, https://github.com/ReactiveCocoa/ReactiveSwift (typed error) allows us to create UI bindings only if Error is NoError, i.e.:

static func <~ <Source: BindingSource> (provider: Self, source: Source) -> Disposable? 
    where Source.Value == Value, Source.Error == NoError { ... }
    
// example
let alphaSignal: Signal = ...
@sifue
sifue / 無料で読めるポール・グレアムの「ハッカーと画家」+αの日本語訳のみのまとめ.md
Last active July 23, 2024 08:10
無料で読めるポール・グレアムの「ハッカーと画家」+αの日本語訳のみのまとめ
// Swift's untyped errors are a goddam PiTA. Here's the pattern I use to try to work around this.
// The goal is basically to try to guarantee that every throwing function in the app throws an
// ApplicationError instead of some unknown error type. We can't actually enforce this statically
// But by following this convention we can simplify error handling
enum ApplicationError: Error, CustomStringConvertible {
// These are application-specific errors that may need special treatment
case specificError1
case specificError2(SomeType)