Skip to content

Instantly share code, notes, and snippets.

@mike-neko
mike-neko / UIImage+Grayscale.swift
Created April 24, 2017 14:50
UIImageをグレースケールに変換する
extension UIImage {
func rgb2GrayScale() -> UIImage? {
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
guard let context = CGContext(data: nil,
width: Int(size.width),
height: Int(size.height),
bitsPerComponent: 8,
bytesPerRow: 0,
space: CGColorSpaceCreateDeviceGray(),
bitmapInfo: CGImageAlphaInfo.none.rawValue),
@mike-neko
mike-neko / ViewController.swift
Last active September 22, 2022 12:00
Model I/Oでモデルをロードする
import MetalKit
struct FrameUniforms {
var projectionViewMatrinx: matrix_float4x4
var normalMatrinx: matrix_float3x3
}
class ViewController: NSViewController, MTKViewDelegate {
private let defaultCameraMatrix = Matrix.lookAt(eye: float3(0, 2, 6), center: float3(), up: float3(0, 1, 0))
@mike-neko
mike-neko / Shader.metal
Last active January 17, 2021 08:08
Model I/Oで立体図形のメッシュを生成する
#include <metal_stdlib>
using namespace metal;
#define lightDirection float3(1, -4, -5)
struct VertexInput {
float3 position [[ attribute(0) ]];
float3 normal [[ attribute(1) ]];
float2 texcoord [[ attribute(2) ]];
};
guard let url = Bundle.main.url(forResource: "embedded", withExtension: "mobileprovision") else {
return
}
guard let data = try? Data(contentsOf: url),
let start = "<?xml".data(using: .utf8),
let end = "</plist>".data(using: .utf8)
let startRange = data.range(of: start),
let endRange = data.range(of: end) else {
return
let CRLF = "\r\n"
let fileData = try! Data(contentsOf: URL(string: "ローカルのパス")!)
let filename = "test.txt" // ファイル名
let formName = "filename" // formでのファイルのname
let type = "text/plain" // ファイルのタイプ
let titleData = "hoge" // 入力されたタイトルデータ
let titleName = "title" // formでのタイトルのname
let boundary = String(format: "----iOSURLSessionBoundary.%08x%08x", arc4random(), arc4random())
<!DOCTYPE html>
<html lang="jp">
<head>
<meta charset="UTF-8">
<title>アップロード</title>
</head>
<body>
<form name="upload">
タイトル <input name="title">
<br>
import MultipeerConnectivity
class P2PConnectivity: NSObject, MCSessionDelegate,
MCNearbyServiceAdvertiserDelegate, MCNearbyServiceBrowserDelegate {
static let manager = P2PConnectivity()
var state = MCSessionState.notConnected {
didSet {
stateChangeHandler?(state)
@mike-neko
mike-neko / apns.php
Last active November 4, 2016 02:06
Guzzleを使ったAPNs同時配信
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Pool;
$tokenList = [
'a72d4aa72b3e506e8970f5d07feb95c4f7cb598c955115eca0b6132f38b5cb1e',
...
];
@mike-neko
mike-neko / guzzle.php
Last active October 29, 2016 14:43
非同期の並列リクエスト
use GuzzleHttp\Client;
use GuzzleHttp\Pool;
$urls = [
'https://example.com/1',
'https://example.com/2',
...
];
$client = new Client();
@mike-neko
mike-neko / NotificationCenter+enum.swift
Last active October 24, 2016 04:25
Swift3のNotificationCenter用extension
enum NotificationKey: String {
// ここで使いたい名前を一元管理
case ChangeStatus
}
extension NotificationCenter {
func post(key: NotificationKey, object: Any? = nil) {
post(Notification(key: key, object: object))
}