Skip to content

Instantly share code, notes, and snippets.

@roothybrid7
roothybrid7 / machine.js
Created April 14, 2020 12:43
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@roothybrid7
roothybrid7 / file0.txt
Created March 7, 2017 23:59
try! Swift Tokyo 2017 に参加した&リンク集 ref: http://qiita.com/roothybrid7/items/267ad11df4f87765588c
struct Environment {
let apiService: ServiceProtocol
let cookieStorage: HTTPCookieStorageProtocol
let currentUser: User?
let dataType: DateProtocol.Type
...
let mainBundle: BundleProtocol
let scheduler: SchedulerProtocol // Reactive.Scheduler
let reachability: ReachabilityProtocol // 通信状態のシグナルはグローバル
let userDefaults: UserDefaultsProtocol
@roothybrid7
roothybrid7 / model.go
Last active October 15, 2016 12:48
Golangのgormで、PrimaryKeyにXIDを使う ref: http://qiita.com/roothybrid7/items/2db3ccbf46f2bdb9cd00
// Model is a base model that defines a primary key and timestamp on operation.
type Model struct {
XID T.XID `gorm:"type:varchar(20);primary_key" json:"id"` // XXX: XID on create callback.
CreatedAt T.ResourceTime `json:"createdAt"`
UpdatedAt T.ResourceTime `json:"updatedAt"`
}
// SoftModel is a base model to delete a record.
type SoftModel struct {
XID T.XID `gorm:"type:varchar(20);primary_key" json:"id"` // XXX: XID on create callback.
@roothybrid7
roothybrid7 / consumer_entrypoint.sh
Last active October 15, 2016 12:47
開発用GolangアプリケーションDockerfile ref: http://qiita.com/roothybrid7/items/18a56245944ddc0b59d3
#!/bin/bash -
set -o nounset # Treat unset variables as an error
set -x
env | grep ON_WATCH >/dev/null
if [ $? -eq 0 ]; then
godo server --watch
else
go install
go_app runConsumer
@roothybrid7
roothybrid7 / file0.go
Last active December 6, 2015 02:06
Golangのgormで、カスタマイズしたtime.Timeに差し変える ref: http://qiita.com/roothybrid7/items/52623bedb45ff0c26a8a
// gorm.Model
type Model struct {
ID uint64 `gorm:"primary_key"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
}
@roothybrid7
roothybrid7 / file0.txt
Last active December 6, 2015 02:05
Golangのgormで、PrimaryKeyにUUIDを使う ref: http://qiita.com/roothybrid7/items/dc58bae01f941e1a72be
// gorm.Model
//type Model struct {
// ID uint64 `gorm:"primary_key"`
// CreatedAt time.Time
// UpdatedAt time.Time
// DeletedAt *time.Time
//}
type User struct {
gorm.Model
// MARK: UICollectionViewDelegateFlowLayout
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {
return UIEdgeInsetsZero
}
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
return 2.0
}
@roothybrid7
roothybrid7 / server.go
Last active December 6, 2015 02:05
Golangで、ResponseWriterを使ってHTTPレスポンスを組み立てる際にハマったこと ref: http://qiita.com/roothybrid7/items/34578037d883c9a99ca8
// A ResponseWriter interface is used by an HTTP handler to
// construct an HTTP response.
type ResponseWriter interface {
// Header returns the header map that will be sent by WriteHeader.
// Changing the header after a call to WriteHeader (or Write) has
// no effect.
Header() Header
// Write writes the data to the connection as part of an HTTP reply.
// If WriteHeader has not yet been called, Write calls WriteHeader(http.StatusOK)
@roothybrid7
roothybrid7 / file0.txt
Created February 1, 2015 23:12
SDWebImageのダウンロード処理を、ネットワークのステータスに応じて制御する ref: http://qiita.com/roothybrid7/items/da1b78a63662e389624d
@implementation APIManager
/*!
@note ネットワーク状況によって、画像ダウンロード処理の停止・再開を行う
*/
+ (void)initialize {
[[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusReachableViaWWAN:
case AFNetworkReachabilityStatusReachableViaWiFi: