Skip to content

Instantly share code, notes, and snippets.

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

Shintaro Morikawa morishin

🦍
ウホホ
View GitHub Profile
module Lib
( generatePoem
) where
import Prelude hiding (Word)
import Control.Monad (join)
import qualified Data.Map as Map
import System.Random (randomRIO)
import Data.Maybe (isNothing, fromMaybe, fromJust)
import Data.List (intercalate)
function peco-select-git-checkout() {
local selected_branch="$(git branch --sort=-committerdate | grep -v '^\*.*' | peco --query "$LBUFFER" | awk -F ' ' '{print $1}')"
if [ -n $selected_branch ]; then
BUFFER="git checkout $selected_branch"
CURSOR=$#BUFFER
zle accept-line
fi
}
zle -N peco-select-git-checkout
bindkey "^gc" peco-select-git-checkout

Slack Slash Command

API Gateway

Body Mapping Template for API Gateway (Slack Slash Command -> Lambda)

Slack Slash Command (application/x-www-form-urlencoded) -> API Gateway -> Lambda (application/json)

2017-01-09 12 27 45

@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
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) {
import Foundation
protocol EitherProtocol {
associatedtype Left
associatedtype Right
func either<Result>(ifLeft: (Left) -> Result, ifRight: (Right) -> Result) -> Result
}
extension EitherProtocol {
@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);
@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)
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
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