Skip to content

Instantly share code, notes, and snippets.

View kakajika's full-sized avatar
🏠
STAY HOME

Keita Kajiwara kakajika

🏠
STAY HOME
View GitHub Profile
@kakajika
kakajika / CurveHitTester.swift
Last active April 25, 2016 12:50
Point hit tester for lines, quadratic bezier curves, and cubic bezier curves in Swift.
import UIKit
public class CurveHitTester {
typealias CurvePointMapper = (t: CGFloat, u: CGFloat) -> (x: CGFloat, y: CGFloat)
public static func hitTestLine(point: CGPoint, p1: CGPoint, p2: CGPoint, segments: Int, lineWidth: CGFloat) -> Bool {
return hitTestPoints(point, segments: segments, lineWidth: lineWidth) { (t, u) in
let x = u * p1.x + t * p2.x
let y = u * p1.y + t * p2.y
@kakajika
kakajika / ExampleScript.swift
Last active March 31, 2016 08:50
Example script of PaperSwift
import PaperSwift
let ExampleScript1 = { (paper: PaperView) in
var center: CGPoint
var width: CGFloat
var height: CGFloat
var pathHeight: CGFloat
let points = 8
let path = paper.Path()
path.fillColor = UIColor.darkGrayColor()
@kakajika
kakajika / RecursiveEnumZundoko.swift
Last active April 10, 2016 07:49
Swiftの再帰的enumとパターンマッチでズンドコ
import Foundation
enum Zundoko: CustomStringConvertible {
case Start
indirect case Zun(Zundoko)
indirect case Doko(Zundoko)
indirect case Kiyoshi(Zundoko)
var description: String {
switch self {
case Start: return "スタート!"
@kakajika
kakajika / MaxLinearLayout.java
Last active June 7, 2022 18:09
Custom LinearLayout takes max measured width of all children for its width.
/**
* @author kakajika
* @since 2016/04/27
*/
public class MaxLinearLayout extends LinearLayout {
public MaxLinearLayout(Context context) {
super(context);
}
@kakajika
kakajika / mov2gif
Created May 16, 2016 11:07
Bash alias to convert .mov to .gif [ffmpeg is needed]
function mov2gif() {
command ffmpeg -i $1 -vf "scale=320:-1" -pix_fmt rgb24 -r 30 -f gif - | gifsicle --delay=3 --optimize=3 > $2
}
@kakajika
kakajika / HSLColorUtil.java
Created July 18, 2016 10:40
Utility class for HSL color in Android.
import android.graphics.Color;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Size;
public class ColorUtil {
public static @ColorInt int lighten(@ColorInt int color, float value) {
float[] hsl = colorToHSL(color);
hsl[2] += value / 100;
@kakajika
kakajika / hubot-ikku.coffee
Last active August 31, 2016 12:10
Detect ikku script for Hubot.
# ikku.coffee
#
# Description:
# Bot for detecting ikku pattern.
#
{tokenize} = require 'kuromojin'
{nfkc} = require 'unorm'
haiku_pattern = [5, 7, 5]
@kakajika
kakajika / hubot-kuromoji.coffee
Created September 1, 2016 11:14
Hubot script for showing result of kuromoji.
# kuromoji.coffee
#
# Description:
# Bot for detecting ikku pattern.
#
{tokenize} = require 'kuromojin'
{nfkc} = require 'unorm'
listit = require 'list-it'
@kakajika
kakajika / RxFirebaseDatabase.kt
Last active April 27, 2020 12:55
FirebaseDatabase events listener with RxKotlin
import com.google.firebase.database.*
import rx.Observable
import rx.lang.kotlin.add
import rx.lang.kotlin.observable
/**
* @author kakajika
* @since 2016/11/08
*/
class RxFirebaseDatabase {
export function RxAutoDispose<T extends React.ComponentClass<any>>(target: T): T {
target.prototype.disposer = new Rx.Subscription()
const originalMount = target.prototype.componentDidMount
Object.defineProperty(target.prototype, "componentDidMount", {
value: function() {
console.log("componentDidMount")
return originalMount.apply(this, arguments)
}
})