Skip to content

Instantly share code, notes, and snippets.

View oozoofrog's full-sized avatar

oozoofrog oozoofrog

View GitHub Profile
Array has moveForMin.
It is find min from &lt;from&gt; index <br/>**- from was bad choice. i thought -**
<br/>and move to &lt;moveTo&gt;
```objc
extension Array where Element: Comparable{
mutating func moveForMin(offset: Int = 0, moveTo to: Int) {
let subArray = self[offset..<self.count]
guard let minValue = subArray.min(isOrderedBefore: <) else {
import UIKit
@IBDesignable
class CharacterView: UIView {
let pathLayer = CAShapeLayer()
override func didMoveToSuperview() {
if nil != superview {
if pathLayer.superlayer != self.layer {
self.layer.addSublayer(pathLayer)
func -<T: Equatable> (lhs: Array<T>, rhs: Array<T>) -> Array<T> {
return lhs.filter({ (lv) -> Bool in
return false == rhs.contains(lv)
})
}
func |<T: Equatable> (lhs: [T], rhs: [T]) -> [T] {
return lhs + rhs.filter({ (rv) -> Bool in
return false == lhs.contains(rv)
})
func -=<O: OptionSetType where O.RawValue == UInt32>(inout lhs: O, rhs: O) {
lhs = O(rawValue: lhs.rawValue ^ rhs.rawValue)
}
func +=<O: OptionSetType where O.RawValue == UInt32>(inout lhs: O, rhs: O) {
lhs = O(rawValue: lhs.rawValue | rhs.rawValue)
}
func +<O: OptionSetType where O.RawValue == UInt32>(lhs: O, rhs: O) -> O {
return O(rawValue: lhs.rawValue | rhs.rawValue)
}
func -<O: OptionSetType where O.RawValue == UInt32>(lhs: O, rhs: O) -> O {
protocol PatternComparable {}
struct Pattern<C: Comparable>: PatternComparable {
let op: (lhs: C, rhs: C) -> Bool
let to: C
func compare(from: C) -> Bool {
return op(lhs: from, rhs: to)
}
}
@oozoofrog
oozoofrog / Castable.swift
Last active August 20, 2016 12:03
freeing Unsafe<Mutable>Pointer casing
protocol Castable {}
protocol UnsafePointerProtocol: NilLiteralConvertible {
associatedtype Memory
init(nilLiteral: ())
init<Memory>(_ from: UnsafeMutablePointer<Memory>)
init<Memory>(_ from: UnsafePointer<Memory>)
var memory: Memory { get }
func mutable<M>() -> UnsafeMutablePointer<M>
@oozoofrog
oozoofrog / file0.swift
Last active September 4, 2016 07:08
FFmpeg 3.xで新しく追加されたAPIの分析。 ref: http://qiita.com/funcodes/items/20b7c78723c6d1c4a958
defer {
avcodec_send_packet(avctx, NULL)
while true {
if AVERROR_EOF == avcodec_receive_packet(avctx, frame) {
break
}
}
}
while 0 <= av_read_frame(avctx, packet) {
// avcodec_decode_video2[audio4](...)を下のコードに変更します。
@oozoofrog
oozoofrog / file0.txt
Last active September 4, 2016 07:25
AVFrameのtupleのデータをArrayで変換 ref: http://qiita.com/funcodes/items/7b91c6b740f42ea66a04
typedef struct AVFrame {
...
uint8_t *data[AV_NUM_DATA_POINTERS]; // AV_NUM_DATA_POINTERS = 8
...
@oozoofrog
oozoofrog / file0.txt
Last active September 5, 2016 03:08
FFmpeg->AVFrame(Audio)->AVAudioEngine再生のやり方。+ Accelerateフレームワークの能力も借ります。 ref: http://qiita.com/funcodes/items/87dc9981e74ba2b79b2b
let audioContext: UnsafeMutablePointer<AVCodecContext>
// プレイするサウンドの基本設定
let audioFormat: AVAudioFormat(
commonFormat: .pcmFormatFloat32,
sampleRate: Double(audioContext.pointee.sample_rate),
channels: 2, // サウンドシステムのoutputチャンネルを超えたらクラッシューが発生されます。
interleaved: false)
@oozoofrog
oozoofrog / convert.sh
Last active October 10, 2016 14:31
multiple codecs and formats convert script with ffmpeg
#!/bin/bash
abort()
{
echo >&2 ' ABORTED '
exit 1
}
trap 'abort' 0