Skip to content

Instantly share code, notes, and snippets.

View magicien's full-sized avatar
😴
Having a doze

magicien magicien

😴
Having a doze
View GitHub Profile
let url = URL(fileURLWithPath: pngFileName, relativeTo: directoryPath)
// let reddishImage = NSImage(contentsOf: url)
let cgDataProvider = CGDataProvider(url: url as CFURL)!
let cgImage = CGImage(pngDataProviderSource: cgDataProvider, decode: nil, shouldInterpolate: false, intent: CGColorRenderingIntent.defaultIntent)!
let imageSize = CGSize(width: cgImage.width, height: cgImage.height)
let correctImage = NSImage(cgImage: cgImage, size: imageSize)
@magicien
magicien / HerokuPassportGithub2.js
Last active September 13, 2017 20:23
Identifying Users for GitHub Apps at Heroku
const express = require('express')
const session = require('express-session')
const passport = require('passport')
const GitHubStrategy = require('passport-github2').Strategy
const clientId = process.env.GITHUB_APP_CLIENT_ID
const clientSecret = process.env.GITHUB_APP_CLIENT_SECRET
const domainName = process.env.DOMAIN_NAME
const app = express()
const jwt = require('jsonwebtoken')
const fetch = require('node-fetch')
const appId = process.env.GITHUB_APP_ID
const privateKey = process.env.GITHUB_APP_PRIVATE_KEY
const getRepositories = (token) => {
return fetch('https://api.github.com/installation/repositories', {
headers: {
Authorization: `token ${token}`,
// サーバ側のコード
const express = require('express')
const fetch = require('node-fetch')
const app = express()
app.get('/githubapi/repos/:owner/:repo/:ref', (req, res) => {
const owner = req.params.owner
const repo = req.params.repo
const ref = req.params.ref
async function getResult(request) {
const promise = new Promise((resolve, reject) => {
request.onsuccess = () => {
resolve(request.result)
}
request.onerror = () => {
reject(request.error)
}
})
return promise
import Foundation
let json = """
{
"nodes": [
{
"extensions": {
"KHR_materials_common": {
"light": 0
}
public func Cross(_ q1: SCNQuaternion, _ q2: SCNQuaternion) -> SCNQuaternion {
return SCNQuaternion(
q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y,
q1.w * q2.y - q1.x * q2.z + q1.y * q2.w + q1.z * q2.x,
q1.w * q2.z + q1.x * q2.y - q1.y * q2.x + q1.z * q2.w,
q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z
)
}
@magicien
magicien / commonprofile.metal
Created August 11, 2018 09:26 — forked from j-j-m/commonprofile.metal
Can't access GL Uniforms in Metal shader modifier? Apple docs for SCNShadable written in terms of GL? Pulling your hair out?... this will help.
////////////////////////////////////////////////
// CommonProfile Shader v2
#import <metal_stdlib>
using namespace metal;
#ifndef __SCNMetalDefines__
#define __SCNMetalDefines__
import Foundation
let json = """
{
"user_id": 1,
"user_name": "magicien",
"url": "http://darkhorse2.0spec.jp"
}
""".data(using: .utf8)!
import Foundation
let json = """
{
"user_id": 1,
"user_name": "magicien",
"friends": [
{
"user_id": 2,
"is_best_friend": true