APNs Certiticate Flow
何度やっても毎回手間取るので未来の俺へメモ。
PyAPNS使用時のCert(PEM)ファイル生成。
iOS Certificates (Production)を
https://developer.apple.com/からつくる
ダウンロードしたCertificateをダブルクリックしてキーチェーンへ登録。
キーチェーンへ登録済みのCertificateを証明書と秘密鍵を同時に書き出す。
別々でもいいが2つのファイルからそれぞれPEMファイルをつくることになるので前者が便利。
書き出すときにパスフレーズも設定できるが、設定した場合は(cert.pem|key.pem)ファイルつくるときに入力必要。
path=$1 dirname="${path%/*}/" basename=${path##*/} filename=${basename%.*} extension=${basename##*.} pemcertfile="${dirname}${filename}-cert.pem" pemkeyfile="${dirname}${filename}-key.pem" pemkeynoencfile="${dirname}${filename}-key-noenc.pem" pemfile="${dirname}${filename}.pem" echo "Crate cert" openssl pkcs12 -clcerts -nokeys -out $pemcertfile -in $path #Input import password if necessary echo "Crate privatekey" openssl pkcs12 -nocerts -out $pemkeyfile -in $path #Input import password if necessary #Input PEM password echo "Write RSA key" openssl rsa -out $pemkeynoencfile -in $pemkeyfile #Input PEM password you input echo "Concat key and cert" cat $pemcertfile $pemkeynoencfile > $pemfile
iOS No Automatic Reference counting compile flag
- fno-objc-arc
Car AI Calculate torque and steer with waypoints in C#
using UnityEngine; using System.Collections; using System.Collections.Generic; public class CarAI : MonoBehaviour { public Transform CarTransform; public WheelCollider WCFrontLeft; public WheelCollider WCFrontRight; public WheelCollider WCRearLeft; public WheelCollider WCRearRight; public float EnginePower = 50.0f; public float MaxSteerAngle = 20.0f; public List<Vector3> Waypoints; public int CurrentWaypointIndex = 0; void Update() { Vector3 waypoint = Waypoints[CurrentWaypointIndex]; Vector3 relativeWaypointPosition = CarTransform.InverseTransformPoint( new Vector3(waypoint.x, CarTransform.position.y, waypoint.z ) ); float steerRatio = relativeWaypointPosition.x / relativeWaypointPosition.magnitude; float torqueRatio; if (Mathf.Abs(steerRatio) < 0.5f) { torqueRatio = relativeWaypointPosition.z / relativeWaypointPosition.magnitude - Mathf.Abs(steerRatio); } else { torqueRatio = 0.0f; } float motorTorque = EnginePower * torqueRatio; float steerAngle = MaxSteerAngle * steerRatio; WCFrontLeft.motorTorque = WCFrontLeft.isGrounded ? motorTorque : 0.0f; WCFrontRight.motorTorque = WCFrontRight.isGrounded ? motorTorque : 0.0f; WCRearLeft.motorTorque = WCRearLeft.isGrounded ? motorTorque : 0.0f; WCRearRight.motorTorque = WCRearRight.isGrounded ? motorTorque : 0.0f; WCFrontLeft.steerAngle = steerAngle; WCFrontRight.steerAngle = steerAngle; } }
Unity Serialization
using UnityEngine; using System; using System.IO; using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; public class BinarySerializer { public static byte[] Serialize(object serializableObject) { MemoryStream memoryStream = new MemoryStream(); try { IFormatter formatterEncode = new BinaryFormatter(); formatterEncode.Binder = new VersionDeserializationBinder(); formatterEncode.Serialize(memoryStream, serializableObject); return memoryStream.ToArray(); } catch (Exception e) { Debug.LogError(e + "Exception caught in encoding"); } return null; } public static string SerializeToBase64String(object serializableObject) { byte[] byteArray = Serialize(serializableObject); return System.Convert.ToBase64String(byteArray); } public static object Deserialize(byte[] serializedBinary) { try { MemoryStream memoryStream = new MemoryStream(serializedBinary); IFormatter formatterDecode = new BinaryFormatter(); formatterDecode.Binder = new VersionDeserializationBinder(); memoryStream.Position = 0; return formatterDecode.Deserialize(memoryStream); } catch (Exception e) { Debug.LogError(e + "Exception caught in Decoding"); } return null; } public static object DeserializeFromBase64String(string serializedBase64String) { byte[] byteArray = System.Convert.FromBase64String(serializedBase64String); return Deserialize(byteArray); } }
using System; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Reflection; public sealed class VersionDeserializationBinder : SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { if (!string.IsNullOrEmpty(assemblyName) && !string.IsNullOrEmpty(typeName)) { Type typeToDeserialize = null; assemblyName = Assembly.GetExecutingAssembly().FullName; // The following line of code returns the type. typeToDeserialize = Type.GetType(String.Format("{0}, {1}", typeName, assemblyName)); return typeToDeserialize; } return null; } }
using System.Runtime.Serialization; using System.Security.Permissions; [System.Serializable] public class PositionEntity : ISerializable { public float positionX; public float positionY; public float positionZ; public PositionEntity() { } protected PositionEntity(SerializationInfo info, StreamingContext context) { if (info == null) { throw new System.ArgumentNullException("info"); } positionX = (float)info.GetValue("PositionX", typeof(float)); positionY = (float)info.GetValue("PositionY", typeof(float)); positionZ = (float)info.GetValue("PositionZ", typeof(float)); } [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)] public virtual void GetObjectData( SerializationInfo info, StreamingContext context) { if (info == null) { throw new System.ArgumentNullException("info"); } info.AddValue("PositionX", positionX); info.AddValue("PositionY", positionY); info.AddValue("PositionZ", positionZ); } }
マクロ 識別子の結合
#define CC_PROPERTY(varType, varName, funName)\ protected: varType varName;\ public: virtual varType get##funName(void);\ public: virtual void set##funName(varType var);
iOS6 Interface Orientation
//less than iOS5 is OK [self.window addSubview:rootViewController.view]; // greater than iOS6 is OK self.window.rootViewController = rootViewController;
IIS7.5 SSLv2が有効か確認
SSLv2には脆弱性があるので無効化した方がいい。
SSLv2が有効か確認。
( echo -e "GET / HTTP/1.0\n" ; sleep 2 ) | openssl s_client -connect $DOMAINorIPADDRESS:443 -ssl2
有効
New, SSLv2, Cipher is DES-CBC3-MD5
無効
write:errno=54
無効化
IIS7.5 Windows Server 2008 R2
C:\Users\Administrator>reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Server" /v "Enabled" /t "REG_DWORD" /d "0x0"
再起動