Skip to content

Instantly share code, notes, and snippets.

@arusu0629
arusu0629 / init.el
Last active March 30, 2020 03:54
~/.emacs.d/init.el
;; init.el
;; show line number
(require 'linum)
(global-linum-mode)
;; show and hide line number with F9
(global-set-key [f9] 'linum-mode)
;; Language
@arusu0629
arusu0629 / enum.swift
Last active August 29, 2015 14:18
列挙型について
// 列挙型
enum Direction: Int {
// 実数値をそれぞれの定数に設定(Up = 0, Right = 1, ...)
case Up = 0, Right, Down, Left
// タイププロパティ
static var defaultDirection = Direction.Up
// イニシャライザ
init() {
self = Direction.defaultDirection
}
@arusu0629
arusu0629 / computedProperty.swift
Created April 2, 2015 11:15
Computed Property
struct Ounce {
var mL: Double = 0.0
static let ounceUS = 29.5735 // 1オンス(アメリカ)
init(ounce: Double) {
self.ounce = ounce
}
var ounce: Double {
get {
return mL / Ounce.ounceUS
}
@arusu0629
arusu0629 / subscript.swift
Last active August 29, 2015 14:18
Subscript
// 構造体
struct FruitsMenu {
let menu = ["apple", "orange", "grape"] // 変更不可
var submenu = ["banana", "peach", "pineapple"] // 変更可能
let count = 6
subscript (i: Int) -> String {
get {
return i < 3 ? menu[i] ] submenu[i - 3]
}
set {
<?php
//POSTされた生データ(JSON)を取得
$json_string = file_get_contents('php://input');
//JSONを、PHPで扱える配列(元がNSDictionaryなので連想配列)に変換
$obj = json_decode($json_string);
//連想配列して入っているデータをそれぞれ変数に格納
$id = $obj -> {'id'};
func sendData() {
// 今回はDictionary(Map)としてPHP側にデータをPOSTする
var submitDic = NSMutableDictionary()
submitDic.setObject("1", forKey: "id")
submitDic.setObject("hoge", forKey: "name")
// DictionaryをNSData型に変換してRequestに付与する
var submitData = NSJSONSerialization.dataWithJSONObject(submitDic, options: NSJSONWritingOptions.PrettyPrinted, error: &error)
if (error != nil) {
println(error?.localizedDescription)
@arusu0629
arusu0629 / receive_device_token.php
Created November 17, 2014 14:18
デバイストークンを受け取るphpのコード
<?php
$device_token = $_POST['DeviceToken']; // POSTの中の"DeviceToken"はあらかじめ送る方のコード(Swift)と統一しないといけない
echo "$device_token";
?>
@arusu0629
arusu0629 / SendToken.swift
Created November 17, 2014 14:14
サーバにデバイストークンを送信する
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
/* get device token */
var characterSet = NSCharacterSet(charactersInString: "<>") // <>と" "(空白)を取る
var deviceTokenString = (deviceToken.description as NSString).stringByTrimmingCharactersInSet(characterSet).stringByReplacingOccurrencesOfString(" ", withString: "") as String
sendToken(deviceTokenString)
}
func sendToken(var token: String) {
@arusu0629
arusu0629 / AppDelegate.swift
Last active August 29, 2015 14:07
AppDelegate
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
// After iOS8, must call registerUserNotificationSettings first
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound | UIUserNotificationType.Alert | UIUserNotificationType.Badge, categories: nil))
return true
}
/* フォアグラウンド(アプリが起動中)の場合ローカル通知が来ないので、アラートを出すなりする */
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
@arusu0629
arusu0629 / Notification.swift
Last active August 29, 2015 14:07
local notification with swift
/* 基本的にはObjective-cと同じ構文 */
func registerNotification() {
var localNotification = UILocalNotification()
localNotification.fireDate = self.myPicker?.todoDate
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.alertBody = "TODO : " + inputText! + "の時間ですよ"
localNotification.alertAction = "OK"
localNotification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)