Skip to content

Instantly share code, notes, and snippets.

@mike-neko
mike-neko / metal_buffer_access.m
Last active January 22, 2016 15:28
VertexBufferへのアクセス方法
VertexUniforms* p = (VertexUniforms*)[frameUniformBuffers[ren.activeBufferNumber] contents];
matrix_float4x4 mat = ren.cameraMatrix * modelMatrix;
p->projectionView = ren.projectionMatrix * mat;
p->normal = matrix_invert(matrix_transpose(modelViewMatrix));
@mike-neko
mike-neko / hugo-gist.html
Last active January 20, 2016 14:04
hugoでGist埋め込むコード layouts/shortcodes/gist.html {{< gist gist_sha1_hash >}}
<script type="text/javascript" src="https://gist.github.com/{{ .Get 0 }}.js"></script>
@mike-neko
mike-neko / hugo-deploy.sh
Last active January 21, 2016 14:57
Hugoのデプロイ用シェルスクリプト
#!/bin/bash
echo -e "\033[0;32mDeploying updates to GitHub...\033[0m"
hugo -t Hyde-X
cd public
git add -A
msg="hugo rebuilding site `date +%Y%m%d_%H-%M-%S`"
if [ $# -eq 1 ]
then msg="$1"
fi
git commit -m "$msg"
@mike-neko
mike-neko / xorshift32.metal
Last active February 15, 2016 14:14
xorshift(metal)
static uint xorshift32(const uint state) {
uint value = state;
value = value ^ (value << 13);
value = value ^ (value >> 17);
value = value ^ (value << 5);
return value;
}
// シェーダ内からの呼び出し
threadgroup uint rnd = 2463534242;
@mike-neko
mike-neko / SpriteOutline-VertexShader.glsl
Last active February 15, 2016 14:24
UnityのSpriteOutlineのVertexShader部分
struct appdata
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
v2f vert(appdata IN)
{
@mike-neko
mike-neko / img.html
Last active February 16, 2016 15:03
Hugoのshortcode
<figure>
<img src="/media/{{ dateFormat "2006-01-02" .Page.Date }}-{{ .Page.Slug }}/{{ .Get 0 }}" />
</figure>
@mike-neko
mike-neko / ObjC_Exception.h
Last active February 20, 2016 19:30
ObjC_Exception
@interface ObjC_Exception : NSObject
+ (void)objC_try:(nonnull void(^)())objC_try
objC_catch:(nonnull void(^)(NSException* _Nonnull))objC_catch
objC_finally:(nullable void(^)())objC_finally;
@end
kernel void particleCompute(device ParticleData* in [[ buffer(0) ]],
device LaminateData* laminate [[ buffer(1) ]],
device VertexInOut* out [[ buffer(2) ]],
uint2 id [[ thread_position_in_grid ]],
uint2 size [[ threads_per_grid ]]) {
uint pos = id.x + id.y * size.x;
ParticleData data = in[pos];
if (data.acc.y > 0) { // 落下中か判定
float height = data.position.y + data.acc.y; // 落下後の高さ
@mike-neko
mike-neko / CodePiece.swift
Created March 21, 2016 14:39
仕事してて気付いた空タプルの使い道。実際に使い道があるかは?だけど、こういう書き方ができるのはおもしろい #CodePiece
let りんご = 1
let ばなな = 2
switch () {
case _ where りんご > ばなな: print("りんごが多い")
case _ where りんご < ばなな: print("ばななが多い")
default: print("同じ")
}
// 上のswitch文と下のif文は等価
@mike-neko
mike-neko / CodePiece.swift
Last active May 16, 2016 01:09
デバイストークンの変換コード。よくあるdescriptionを使うのは好みじゃないので、本来のやり方をSwiftで書いたら、すっきり書けた😃 #CodePiece
func application(
application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken
deviceToken: NSData) {
var bytes = [UInt8](count: deviceToken.length,
repeatedValue: 0)
deviceToken.getBytes(&bytes, length: deviceToken.length)
let token = bytes.reduce("") {
$0 + String(format: "%02x", arguments: [$1])