Skip to content

Instantly share code, notes, and snippets.

View yossan's full-sized avatar

Kosuke Yoshimoto yossan

  • Nagoya, Aichi, Japan
View GitHub Profile
@yossan
yossan / pom.xml
Created April 30, 2019 09:22
pom.xml for quickstart
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Sample</groupId>
<artifactId>quickstart</artifactId>
<version>1.0-SNAPSHOT</version>
@yossan
yossan / .vimrc
Last active April 13, 2019 16:53
vimrc
filetype plugin on " required
filetype indent on " required
" {{{ minpac memo
" プラグイン管理
" プラグインの更新 :minpac#update()
" プラグインの削除 :minpac#clean()
" }}}
packadd minpac
call minpac#init()
filetype plugin on " required
filetype indent on " required
let g:ale_completion_enabled = 1
" {{{ minpac memo
" プラグイン管理
" プラグインの更新 :minpac#update()
" プラグインの削除 :minpac#clean()
" }}}
packadd minpac
@yossan
yossan / _vimrc.vim
Created February 26, 2019 15:37
vimrc
filetype plugin on " required
filetype indent on " required
let g:ale_completion_enabled = 1
" {{{ minpac memo
" プラグイン管理
" プラグインの更新 :minpac#update()
" プラグインの削除 :minpac#clean()
" }}}
packadd minpac
@yossan
yossan / queue_with_array.swift
Created November 18, 2018 13:14
Queue with Array
struct Queue <Element> {
var head: Int = 0
var tail: Int = 0
var size: Int = 0
let data:UnsafeMutableBufferPointer<Element>
init(size: Int) {
self.data = UnsafeMutableBufferPointer<Element>.allocate(capacity: size+1)
self.size = size + 1
}
@yossan
yossan / commit_message_example.md
Created July 25, 2018 05:46 — forked from mono0926/commit_message_example.md
[転載] gitにおけるコミットログ/メッセージ例文集100

gitにおけるコミットログ/メッセージ例文集100の転載


gitにおけるコミットログ/メッセージ例文集100

私はコミットログの書き方に悩む英語の苦手な人間である。実際、似たような人は世の中に結構いるようで、頻出単語を集計したりまとめたものは既にあって役に立つのだけれど、これらはあくまで単語の話であり、具体的な文を構成する過程でやっぱり困る部分がかなりあった。

要するに、どういう時にどういう文が使われているのか、ということを示した例文集が欲しいのである。ググると他にも「例文集があればいいのに」みたいな声はあるくせして、しかし誰も作ろうとしない。何なんだお前ら。それじゃ私が楽できないじゃないか。

@yossan
yossan / making_glyph_with_ctfont.swift
Last active September 28, 2021 06:43
Making CGlyph of an extended grapheme cluster.
// CTFontGetGlyphsForCharacters(_:_:_:_:)
// [UniChar] → [CGGlyph]
import Foundation
func makeUnichars(from str: NSString) -> [UInt16] {
let range = NSRange(location:0, length: str.length)
let encoding = String.Encoding.utf16.rawValue
let maxLength = str.maximumLengthOfBytes(using: encoding)
@yossan
yossan / string2cstring.swift
Last active July 12, 2018 05:33
Making UnsafeMutablePointer<UInt8> from String without Foundation.
// String → UTF8View → UnsafeMutablePointer<UInt8>
// Note: UTF8View.Element == UInt8
// Note: utf8CString: ContigiousArray<Int8>
func makeCString(from str: String) -> UnsafeMutablePointer<UInt8> {
var utf8 = Array(str.utf8)
utf8.append(0) // adds null character
let count = utf8.count
let result = UnsafeMutableBufferPointer<UInt8>.allocate(capacity: count)
_ = result.initialize(from: utf8)
@yossan
yossan / string2cstring.swift
Last active May 20, 2022 12:47
Making UnsafeMutablePointer<Int8> from String
// Method 1
// String → UnsafePointer<Int8> → UnsafeMutablePointer<Int8>
// Note: func withCString<Result>(_ body: (UnsafePointer<Int8>) throws -> Result) rethrows -> Result
// Note: String.UTF8View doesn't include null character.
func makeCString(from str: String) -> UnsafeMutablePointer<Int8> {
let count = str.utf8.count + 1
let result = UnsafeMutablePointer<Int8>.allocate(capacity: count)
str.withCString { (baseAddress) in
// func initialize(from: UnsafePointer<Pointee>, count: Int)
@yossan
yossan / calculate_bearing.swift
Created May 15, 2018 14:26
Calculates bearing between two points
import Foundation
import CoreLocation
/*
θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )
where φ1,λ1 is the start point, φ2,λ2 the end point (Δλ is the difference in longitude)
*/
func calculateBearing(from: CLLocationCoordinate2D, to: CLLocationCoordinate2D) -> Double {
let x1 = from.longitude * (Double.pi / 180.0)