Adsenseコード

2017-09-29

nmap を mac OS にインストールする

■Nmap のソースファイルをダウンロード

下記のURLのページ中の 「Latest stable Nmap release tarball: nmap-7.60.tar.bz2」 からダウンロードします https://nmap.org/download.html

■ソースファイルの解凍

下記を実行して、解凍します #ダウンロードディレクトリに移動 $ cd ~/Downloads/ #tar コマンドで解凍 $ tar xjvf nmap-7.60.tar.bz2

■インストール

下記を実行し、インストールします $ cd nmap-7.60 $ ./configure $ make $ sudo make install このコードではそれぞれ  環境を調査し、Makefileの作成  ソースコードのコンパイル  バイナリファイルのコピー(インストール) を行っています

■動作確認

下記を実行し、ホームディレクトリに移動し、 バージョン情報を確認して動作確認します $ cd ~/ $ nmap -V 参考 https://macperson.net/mac-nmap/

2017-09-28

mac OS から Ubuntu へリモートデスクトップで操作する

ローカル環境でUbuntuをリモートデスクトップで操作する方法になります。



■dconfエディター のインストール


Ubuntu 側で Ctrl + Alt + T でターミナルを起動し、
下記を入力し、dconf-toolsをインストールします。
sudo apt-get install dconf-tools



■Ubuntu側の設定


コンピューターを検索で「dconf-tools」と入力すると、
「dconfエディター」が表示されるので起動します。

dconf > org > gnome > desktop > remote-access と進み、
「enabled」にチェック
「require-encryption」のチェックをはずします。



■デスクトップの共有の設定


コンピューターを検索で「des」まで入力すると、
「デスクトップの共有」が表示されるので起動します。

以下にチェックし、パスワードを設定します。
「他のユーザーが自分のデスクトップを表示できる」
「他のユーザーがデスクトップを操作できる」
「パスワードの入力を要求する」

以下はチェックを外しておきます。
「このマシンへの接続を毎回確認する」



■IPアドレスの確認


Ubuntu 側で Ctrl + Alt + T でターミナルを起動し、
下記を入力して Ubuntu 側のIPアドレスを確認します。
$ ip route



■mac OS から Ubuntu へ接続


Finder で cmd + k で「サーバへ接続」を起動し、
先程確認したIPアドレスを下記のように入力して接続します。
vnc://IPアドレス



参考
https://wp.me/p9t947-ab
http://webnetforce.net/ubuntu-14-04%E3%81%A7%E3%83%87%E3%82%B9%E3%82%AF%E3%83%88%E3%83%83%E3%83%97%E5%85%B1%E6%9C%89%E3%82%92%E4%BD%BF%E3%81%84%E3%80%81mac%E3%81%8B%E3%82%89%E6%93%8D%E4%BD%9C%E3%81%99%E3%82%8B/
https://qiita.com/sharow/items/66d89136180884a2f7b7
http://tokixy56.hatenablog.com/entry/2016/03/13/204354



【Swift 3.1】プロジェクト作成テンプレート

・新規にプロジェクト作成から、シミュレーターで最初の画面を表示するまでです
・ストーリーボードは使いません


■新規のプロジェクト作成をします


■ストーリーボードを削除します


■プロジェクトプロパティの
General > Deployment Info > Main Interface
を空欄にします


■AppDelegate.swiftの編集
AppDelegate.swiftを下記のように編集します
```
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = ViewController()
        window?.makeKeyAndVisible()

        return true
    }
```



■おまけ(表示確認)
ViewController.swiftを下記のように編集します
背景の変更とテキスト入力欄を配置しています
```
    private var myTextField: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.view.backgroundColor = UIColor.white    // Viewの背景色を変更

        // UITextFieldの配置するx,yと幅と高さを設定.
        let tWidth: CGFloat = 200
        let tHeight: CGFloat = 30
        let posX: CGFloat = (self.view.bounds.width - tWidth)/2
        let posY: CGFloat = (self.view.bounds.height - tHeight)*2/10
        
        // UITextFieldを作成する.
        myTextField = UITextField(frame: CGRect(x: posX, y: posY, width: tWidth, height: tHeight))
        myTextField.text = "Hello TextField"        // 初期値
        myTextField.borderStyle = .roundedRect        // 枠を表示する.
        myTextField.clearButtonMode = .whileEditing        // クリアボタンを追加.
        self.view.addSubview(myTextField)        // Viewに追加する
        
    }
```






2017-09-27

iOSアプリの実機テストの方法

■前提

アプリの開発元として登録するApple ID(アップグレード済) ※ アップグレード済みとは、アカウントを発行してから、 下記のサイトにログインし、登録したメールアドレスの認証が 済んでいるアカウントのことをさします。 https://appleid.apple.com/#!&page=signin アップグレードが済んでいないと、 Team に Apple ID を登録するときにエラーが発生します

■デバイスをMacに接続する

■接続したPCを信頼するか選択肢が表示されるので、信頼する

■テスト実行

Xcodeの上部にデバイスを選択する場所があるので、そこから実機を選択する 以下がエラーとして発生している場合、 プロジェクトのプロパティで Team が設定されているかを確認します
Signing for *** requires a development team. Select a development team in the project editor. Code signing is required for product type 'Application' in SDK 'iOS 10.3'


■Team の設定

プロジェクトのプロパティで General > Signing にある Team を None から、 利用するApple ID を設定します この時エラーでアカウントを設定できないときは、 アカウントのアップグレードが済んでいるかを確認してください (■前提を参照)

■信頼済開発元の登録

テスト実行時に以下が表示された場合は、 実機テストするデバイス側の設定をします
Verify the Developer App certificate for your account is trusted on your device. Open Settings on KNのiPhone and navigate to General -> Device Management, then select your Developer App certificate to trust it.
デバイスの設定で
設定 > 一般 > デバイス管理 
から、Teamで登録した開発元を信頼します


参考
http://tech.pjin.jp/blog/2016/03/25/%E3%80%90xcode%E3%80%91%E8%AA%B0%E3%81%A7%E3%82%82%E3%82%8F%E3%81%8B%E3%82%8Biphone%E5%AE%9F%E6%A9%9F%E3%83%86%E3%82%B9%E3%83%88%E3%81%AE%E8%A8%AD%E5%AE%9A%E6%89%8B%E9%A0%86%E3%81%BE%E3%81%A8%E3%82%81/
http://yoichirowatanabe.hatenablog.com/entry/2016/10/19/180900






【Salesforce】サイトで公開したページが「構築中です。」と表示される場合

# トラブルシューティング

以下を確認する
1.サイトに対象のVFページを追加しているか。
2.サイトゲストユーザプロファイルに、
  VFページとApexコントローラの権限を与えているか
3.移動先のURLのドメインが、サイト用のドメインになっているか
4.少し待ってみる(30分程度)
   Salesforce の内部処理が終わってなくて、
   設定が反映されていないことがあります
5.コントローラで返しているURLはサイトドメインのURLか



# 補足

5について

次のページに遷移させる処理を記述する時、
グローバル変数で記述する Page.VF_NextPage は
コントローラのメソッドとして return する形式でないと
サイト用のドメインのURLに変換してURLを返してません。

上記とは別にコントローラに Page.VF_NextPage を
public な変数として置き、その変数を get する方法だと、
サイトドメインのURLを返さずに
組織内部のログインユーザ向けのURLをそのまま返します。
 こんな感じのやつ → /apex/VF_NextPage



サンプルコード(サイトドメインのURLに変換してくれない例)
(Apex)
public PageReference nextPage {
  get {
    return Page.VF_NextPage;
  }
  set;
}

(Visualforce)
```<a href="{! nextPage}">次ページ</a>```



サンプルコード(サイトドメインのURLに変換してくれる例)
(Apex)
public PageReference nextPage() {
  return Page.VF_NextPage;
}

(Visualforce)
```<apex:commandbutton action="{! nextPage}" value="次ページ" />```


※ 下の場合は、Salesforceが裏側でサイトドメインのURLに変換してくれるので、サイトゲストユーザプロファイルでも閲覧できる。)






Parallels Desktopのアップデート時のエラーを回避する

# 概要

Parallels Desktopのアップデート時に

「お使いのシステム内の UID 0 に非ルートユーザアカウントがあるため、Parallels Desktopをインストールできません。問題ID: 15476」

というエラーでアップデートができなかったときの対処法



# 前提

macOS Sierra 10.12.5(16F73)
Parallels Desktop 12 for Mac バージョン 12.2.1 (41615)



# 原因の特定

```dscl . -list /Users UniqueID```

で出てきたUIDの一覧で、0に非ルートユーザの割当がないかを確認する。
http://kb.parallels.com/jp/122763



# 対処法

以下のコマンドでUIDを変更する
念のために重複しないように、かつ501以降の数字で指定した。

**uid 変更**
```sudo dscl . -create /users/(変更するユーザ) uid (変更先UID)```
**例**
```sudo dscl . -create /users/hoge uid 502```
http://blog.livedoor.jp/kosugip/archives/1715571.html






Storyboardを使わずにコードだけで画面を生成、遷移をする

■Storyboardを削除します

■Main Interfaceの変更

左側のプロジェクトディレクトリを選択すると、プロジェクトのプロパティが表示されます その中の General > Deployment Info > Main Interface の部分を空欄にしておきます

■ソースコード

下記のように編集します ```swift: AppDelegate.swift import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { window = UIWindow(frame: UIScreen.main.bounds) window?.rootViewController = MainTabBarViewController() window?.makeKeyAndVisible() return true } func applicationWillResignActive(_ application: UIApplication) { } func applicationDidEnterBackground(_ application: UIApplication) { } func applicationWillEnterForeground(_ application: UIApplication) { } func applicationDidBecomeActive(_ application: UIApplication) { } func applicationWillTerminate(_ application: UIApplication) { } } ``` ```Swift: Nav1ViewController.swift // 初期表示されるpushボタンがあるページ import UIKit import SnapKit final class Nav1ViewController: UIViewController { private lazy var container: UIView = { let container = UIView() container.backgroundColor = UIColor.gray let button = UIButton(type: .system) container.addSubview(button) button.setTitle("push", for: .normal) button.tintColor = UIColor.white button.backgroundColor = UIColor.blue button.addTarget(self, action: #selector(onTappedPush(_:)), for: .touchUpInside) button.snp.makeConstraints { make in make.width.equalTo(200) make.height.equalTo(40) make.center.equalTo(container) } return container }() override func viewDidLoad() { super.viewDidLoad() navigationItem.title = "Nav1" self.view.addSubview(container) container.snp.makeConstraints { make in make.edges.equalToSuperview() } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func onTappedPush(_ sender: UIButton) { print(sender) let vc = SecondViewController(titleName: "second") navigationController?.pushViewController(vc, animated: true) } } ``` ```Swift: SecondViewController.swift // ボタンの遷移先画面 import Foundation import UIKit final class SecondViewController: UIViewController { let titleName: String init(titleName: String) { self.titleName = titleName super.init(nibName: nil, bundle: nil) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } private lazy var container: UIView = { let container = UIView() container.backgroundColor = UIColor.yellow return container }() override func viewDidLoad() { super.viewDidLoad() navigationItem.title = titleName self.view.addSubview(container) container.snp.makeConstraints { make in make.edges.equalToSuperview() } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } ``` ```Swift: Nav2ViewController.swift // 2つ目のタブの画面 import Foundation import UIKit final class Nav2ViewController: UIViewController { private lazy var tableView: UITableView = { let tableView = UITableView() tableView.delegate = self tableView.dataSource = self return tableView }() override func viewDidLoad() { super.viewDidLoad() navigationItem.title = "Nav2" view = tableView } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } extension Nav2ViewController: UITableViewDelegate { } extension Nav2ViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { return UITableViewCell() } public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 10 } } ``` ```Swift: MainTabBarViewController.swift // AppDelegate.swift で起動時に開くように指定されている下部のタブ部分 import Foundation import UIKit final class MainTabBarViewController: UITabBarController { override func viewDidLoad() { super.viewDidLoad() let vc = Nav1ViewController() // コントローラのインスタンス vc.tabBarItem = UITabBarItem(tabBarSystemItem: .bookmarks, tag: 1) // bookmarksという名前でタブとして組み込む let nv = UINavigationController(rootViewController: vc) let vc2 = Nav2ViewController() vc2.tabBarItem = UITabBarItem(tabBarSystemItem: .downloads, tag: 2) let nv2 = UINavigationController(rootViewController: vc2) setViewControllers([nv, nv2], animated: false) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } ```

※ SnapKit

このコードではSnapKitを使っているので、 SnapKitの導入が必要になります この記事を参考にしてください http://shige-mon.blogspot.jp/2017/09/cocoapodssnapkit.html

参考

http://qiita.com/star__hoshi/items/b38cf99457e781ed7625

cocoaPodsを使って、SnapKitをプロジェクトに導入する

import SnapKit
と書いて

No such module 'SnapKit'
と怒られてしまった人のためのメモです


2017年9月26日時点で成功した方法を記述しています。



■cocoapods とは

ライブラリを管理するためのライブラリです。


cocoapods 導入した時に生成される Podfile の中身を
編集して、 pod install のコマンドを打つだけで
設定したライブラリを自動的に導入してくれます。


2017年10月時点では、iOSアプリ開発では
一般的に使われているツールのようです。



■cocoapodsのインストール

以下を実行して、Rubyを最新にします
$ sudo gem update --system
RubyGems system software updated


以下を実行して、インストールをします
$ sudo gem install -n /usr/local/bin cocoapods


$ pod setup
CocoaPods 1.4.0.beta.1 is available.
To update use: `sudo gem install cocoapods --pre`
[!] This is a test version we'd love you to try.
For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.4.0.beta.1
Setup completed



■Podfileの作成

プロジェクトフォルダに移動し、以下を実行します $pod init この操作で Podfile は自動的に生成されます

■Podfileを編集

アプリ名/Podfileを以下のように編集します ``` # Uncomment the next line to define a global platform for your project # platform :ios, '9.0'
target 'Omikuji' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
  # ここにimportで使うライブラリを記述します
  pod 'SnapKit', '>=3.2.0'

  # Pods for Omikuji

  target 'OmikujiTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'OmikujiUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end
```


※ このファイルを編集する際は(このファイルに限りませんが)、
mac OS標準のテキストエディットを使わないようにしてください。

スマート引用符の自動置換により、無効な文字が混入される可能性が高くなります。
混入された場合は、大体以下のようなエラーメッセージが出ます
[!] Smart quotes were detected and ignored in your Podfile. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes in your editor of choice.

※ cocoapodのバージョン管理
ライブラリのバージョンの指定方法は、以下を参考にしてみてください
https://hacknote.jp/archives/15217/

SnapKitの最新バージョン
https://github.com/SnapKit/SnapKit/releases



■ライブラリのインストール

以下をプロジェクトフォルダ内で実行します $ pod install Analyzing dependencies Downloading dependencies Installing SnapKit (3.2.0) Generating Pods project Integrating client project
[!] Please close any current Xcode sessions and use `Omikuji.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

[!] Automatically assigning platform ios with version 10.3 on target Omikuji because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.


※ エラーパターン

下記が出た場合は、記述内容に誤りがある可能性があるので、もう一度内容を確認してみてください。
改行コードも問題になる場合があるそうなので、改行を削除して新たに入力し直して実行もしてみてください
[!] Invalid `Podfile` file: syntax error, unexpected tCONSTANT, expecting end-of-input.


下記が出た場合はメソッド名のミスですので Pod → pod と修正するといいです
[!] Invalid `Podfile` file: undefined method `Pod' for #.

# from /Users/Shared/sko-fsf/X-Project/TransView/Podfile:8
# -------------------------------------------
#
> Pod 'SnapKit','>=3.2.0'
#
# -------------------------------------------




■xcworkspaceを開く

一度Xcodeを閉じて、プロジェクトフォルダ内に作成された 『アプリ名.xcworkspace』でプロジェクトを開きます ターミナルでは、プロジェクトフォルダまで移動し、以下を実行することで開けます $ open /Applications/Xcode.app/ アプリ名.xcworkspace pod installを実行すると 『アプリ名.xcworkspace』ができるので 今までアプリを開発する際は 『アプリ名.xcodeproj』 を開いていましたが、 『アプリ名.xcworkspace』 を開くようにします

■ビルド

プロジェクトを開いたら、cmd + B でビルドを実行しましょう import SnapKit 部分のエラーが消えることが確認できます

参考

cocoapodsのインストール方法
https://qiita.com/satoken0417/items/479bcdf91cff2634ffb1

cocoapodsの削除方法
https://qiita.com/ka0ru19/items/fe2611de71bb363c9537

全体の流れ
http://programming-beginner-memo.com/?p=101

podfile内のライブラリの追加の仕方
http://programming-beginner-memo.com/?p=606

ビルドを忘れずに
https://qiita.com/fksk/items/9e5fdc201af4f03f2dec

cocoaPodsを使って、SnapKitをプロジェクトに導入する
http://shigemon.jp/%E6%9C%AA%E5%88%86%E9%A1%9E/cocoapods-snapkit/





2017-09-26

Xcodeの使い方あれこれ

簡単なんだけど、初見では検索しないと解決できなかった基本操作を記録します。


■ファイル名の変更

右側のサイドバーを表示させるとファイルに関するプロパティを表示できる

■シミュレーターが途中でストップ

ソースコード上で Thread 1: breakpoint 1.1 と表示されているのは、自身で設定した(してしまった)ブレイクポイントで 処理が一時停止している状態です cmd + ctrl + y で引き続き処理を続行できます ソースコード下部に表示される適当な再生ボタンを押してみてください

■シミュレーターが途中でストップ2

ソースコード上で Thread 1:signal SIGABRT が出てシミュレーターの起動が止まった場合は コードとUI部品がうまくつながっていない可能性があります また、プロジェクトのプロパティの General > Deployment Info > Main Interface の設定が正しくない可能性があります

■シミュレータの操作アキーボードを閉じる

ソフトウェアキーボードを閉じる シミュレーターを操作しているときに、キーボードをしまうには Esc キーでできます ホームボタンを押す操作 shift + cmd + H 参考 https://qiita.com/evistream/items/b83f75d6934efa9ee115

2017-09-25

【Django入門】Mac環境にDjangoを導入する2(アプリケーション作成)




◆前回


前記事では、仮想環境を構築し、Djangoをインストール、
プロジェクトの作成とDB設定まで行いました。
【Django入門】Mac環境にDjangoを導入する1(環境構築とプロジェクト作成)


Djangoでは、プロジェクトーアプリケーション という構造をしています。
本記事では、作成したプロジェクトにアプリケーションを作成する作業を行います。




◆アプリケーションのインストール


■アプリケーションインストール


作成した仮想環境のディレクトリまで移動し、以下を実行します
myvenv user$ python3 manage.py startapp blog
$ tree -L 1 .
.
├── bin
├── blog
├── db.sqlite3
├── include
├── lib
├── manage.py
├── myapp
├── pip-selfcheck.json
└── pyvenv.cfg




■myapp/settings.pyファイルの編集


使用するアプリケーションをDjango上で定義します

```
# Application definition
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',
)
```




■モデルの作成


blog/models.pyのファイルを以下のように編集します

```
from django.db import models
from django.utils import timezone

class Post(models.Model):
    author = models.ForeignKey('auth.User')
    title  = models.CharField(max_length=200)
    text   = models.TextField()
    created_date = models.DateTimeField(default=timezone.now)
    published_date = models.DateTimeField(blank=True, null=True)

    def publish(self):
        self.published_date = timezone.now()
        self.save()

    def __str__(self):
        return self.title
```




■マイグレーションファイルの作成


$ python3 manage.py makemigrations blog
Migrations for 'blog':
  blog/migrations/0001_initial.py
    - Create model Post




■マイグレーションの実行


$ python3 manage.py migrate blog
Operations to perform:
  Apply all migrations: blog
Running migrations:
  Applying blog.0001_initial... OK




■Django adminの設定


blog/admin.pyファイルを下記に変更します

```
from django.contrib import admin
from .models import Post

# Register your models here.
admin.site.register(Post)
```




■superuser (サイトの管理者) の作成


$ source ./bin/activate
$ python manage.py createsuperuser
Username (leave blank to use 'sko'): admin
Email address: # メールアドレスを設定
Password: # パスワードを入力
Password (again): # パスワードをもう一度入力
Superuser created successfully.




■動作確認


以下にアクセスし、設定したユーザ名とパスワードを入力して
ログインできることを確認します。
http://127.0.0.1:8000/admin/blog/

※もちろんサーバを起動しておくことを忘れないでください





◆ルーティングの設定


■myapp/urls.pyの設定


以下のように設定します

```
from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'', include('blog.urls')),
]
```




■blog/urls.pyの作成


blog/urls.pyという空ファイルを作成し、以下のように編集します

```
from django.conf.urls import url
from . import views

urlpatterns = [
    # 'http://127.0.0.1:8000/'へのアクセスは views.post_list を返す
    url(r'^$', views.post_list),
]
```




■Viewの作成


blog/views.pyを下記の内容で作成します

```
from django.shortcuts import render

# Create your views here.
def post_list(request):
    return render(request, 'blog/post_list.html', {})
```




■Templateの作成


Template用のディレクトリを作成します

$ mkdir blog/templates
$ mkdir blog/templates/blog


ここへpost_list.html を作成します

```
<html>
    <p>Hi there!</p>
    <p>It works!</p>
</html>
```




■動作確認


下記にアクセスします。
http://127.0.0.1:8000/


すると、下記の html ファイルを表示します
/Django_app/myvenv/blog/templates/blog/post_list.html




参考
https://qiita.com/yoshizaki_kkgk/items/c9a5299b77b99ff07e4a






Mac上のMAMPでローカルにバーチャルホストを設定する方法




■前提



MAMPをインストールしておきます
インストールしたら、設定は変えずにその状態で
サーバが正しく起動できることを確認しておいてください。




■手順



ルートディレクトリの用意
httpd.confファイルの編集
httpd-vhosts.confファイルの編集




■ルートティレクトリの用意



\Applications\MAMP\htdocs\
のディレクトリに「test01」フォルダを作成します。

作成したフォルダ内に適当な文言を記述したindex.htmlを入れてください。




■httpd.confファイルを編集



ファイルの場所は下記です
\Applications\MAMP\conf\apache\httpd.conf

「# Virtual hosts」で検索すると、以下の部分が該当すると思いますので、
コメントアウト(#のこと)を削除して、設定ファイルを有効化します

```
# Virtual hosts
# Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
```

```
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
```




■httpd-vhosts.confファイルを編集



ファイルの場所は下記です
\Applications\MAMP\conf\apache\extra\httpd-vhosts.conf

このファイルの最後に下記を追記します

```
Listen 8001
<VirtualHost *:8001>
DocumentRoot "/Applications/MAMP/htdocs/test01"
</virtualhost>

Listen 8002
<VirtualHost *:8002>
DocumentRoot "/Applications/MAMP/htdocs/test02"
</VirtualHost>
```




■補足説明



以上の設定は、

http://localhost:8001/
を開いたときは、

"/Applications/MAMP/htdocs/test01"
のファイルを参照してください。
というような設定になります。

この設定単位を複数用意することで、
複数のローカルホストを使い分けることができます。




■動作確認



MAMPのサーバを再起動します。
下記にアクセスします。
http://localhost:8001/




■デバッグ



下記でログを参照できるので、うまく動かない時は
ログの error をヒントにしてみてください

$ tail /Applications/MAMP/logs/apache_error.log




参考
Mac上のMAMPでローカルにバーチャルホストを設定する方法
http://shigemon.jp/archives/356
http://kunkun.pya.jp/basic_design/notebook/local-mamp/






2017-09-22

【Django入門】Mac環境にDjangoを導入する1(環境構築とプロジェクト作成)

◆対象

Pythonをやりたい! とりあえずメジャーなフレームワークで構築してみよう Djangoで構築 という方の手順を記録してみました。

■Pythonの動作確認

$ python3 --version Python 3.5.2 動作が確認取れない場合はPythonをインストールする

◆仮想環境構築

以下で仮想環境を構築する
仮想環境には virtualenv、venv がありますが、
virtualenv がデファクトスタンダードらしいです。


venvは、virtualenvみたいな機能を標準でもサポートしようぜ!
ということでPython3.3から追加された標準モジュールのようです。


下記では、venv で作成しています。



■ディレクトリの作成

まず、仮想環境を作成したいディレクトリまで移動します $ mkdir sample_app $ cd sample_app

■仮想環境を作成する

$ python3 -m venv myvenv

■ディレクトリが作成されたことを確認

$ ls myvenv

■treeにより作成されたディレクトリ内容を確認してみる

treeをインストールしていない場合はインストールする $ brew install tree treeによるディレクトリ内容を確認 $ tree -L 1 myvenv myvenv ├── bin ├── include ├── lib └── pyvenv.cfg

■Djangoインストール

myvenv user$ pip3 install Django==1.11.5

◆プロジェクト作成

■現在位置の確認

$ pwd /Users/#{myname}/Desktop/sample_app/myapp $ tree -L 1 . . ├── bin ├── include ├── lib └── pyvenv.cfg

■プロジェクトを作成する

$ django-admin startproject myapp . $ ls bin lib myapp include manage.py pyvenv.cfg $ tree -L 1 . . ├── bin ├── include ├── lib ├── manage.py ├── myapp └── pyvenv.cfg

■設定ファイル内のタイムゾーンを変更する

Vimを使って編集してみました $ cd myapp $ vim settings.py 以下の内容に変更します ``` # LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'ja' # TIME_ZONE = 'UTC' TIME_ZONE = 'Asia/Tokyo' USE_I18N = True USE_L10N = True # USE_TZ = True USE_TZ = False ```

■データベースの設定

SQLiteを使用する場合は myapp/settings.py の中に以下が記載されています。 MySQL、PostgreSQLを使う場合は応じて変更が必要 ``` DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), } } ```

■DBのマイグレーション

SQLite3動作確認(macには予めインストールされている) $ sqlite3 -version マイグレーションの実行 $ ls bin lib myapp include manage.py pyvenv.cfg $ source ./bin/activate $ python manage.py migrate $ python3 manage.py migrate Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying sessions.0001_initial... OK

◆動作確認

■サーバ起動

$ python manage.py runserver $ python3 manage.py runserver Performing system checks... System check identified no issues (0 silenced). You have 13 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them. September 22, 2017 - 15:22:03 Django version 1.11.5, using settings 'myapp.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.

■動作確認

下記にアクセスします。 http://127.0.0.1:8000/ 参考 https://qiita.com/yoshizaki_kkgk/items/f3c79e38b802c7fc8863 https://qiita.com/maskedw/items/aaa2fd7abfd493cf2820 https://teratail.com/questions/64846 https://teratail.com/questions/82246

■次回記事

【Django入門】Mac環境にDjangoを導入する2(アプリケーション作成) http://shige-mon.blogspot.jp/2017/09/djangomacdjango.html

2017-09-21

XAMPPでPythonを動かす




■XAMPPの設定手順



「xampp」→「apache」→「conf」フォルダの「httpd.conf」ファイルに以下を追記

#
# For Python
#
AddHandler cgi-script .py
ScriptInterpreterSource Registry-Strict



■ソースファイルを配置する


以下の内容を「test.py」というファイル名で「xampp」→「htdocs」内に保存

#!C:\Python35\python.exe
# -*- coding: utf-8 -*-
print(“Content-Type: text/html\n”)
print(“Hello World”)
print(“<p>このようにして記述します</p>”)



補足: 1行目の「C:\Python35\python.exe」は、python.exeの場所と一致するように記述する
 私の場合は 「C:\Program Files (x86)\Python36-32\python.exe」 だった


「C:\Documents and Settings\[userName]\AppData\Local\Programs\Python\Python36-32\python.exe」 の場合もある



■XAMPPを起動


(ApacheとMySQLをStartボタンで起動)


ブラウザで以下に接続
http://localhost/test.py



参考
https://algorithm.joho.info/programming/sql-db/xampp-python-install/





2017-09-20

Joomla! を XAMPP 環境にインストールする

■前提

XAMPP あるいは MAMP で予めローカルサーバ環境を構築しておきます 以下の記事等を参考にしてください (Windows向け) XAMPPの初期設定 http://shige-mon.blogspot.jp/2017/09/xampp.html (mac OS向け) Mac上のMAMPでローカルにバーチャルホストを設定する方法 http://shige-mon.blogspot.jp/2017/09/macmamp.html

■Joomla!のダウンロード

下記にアクセスし、「本家コアパッケージ+日本語パック(サンプルデータ含む)」からダウンロードします http://joomla.jp/ 「htdocs」フォルダにインストールするフォルダを新規作成し、 そのフォルダの直下に、解凍したファイルの「administrator」の階層のファイル群を移動させる "http://localhost/作成したフォルダ名" へアクセスします

■サイトの設定

以下を設定します サイト名、管理ユーザのメールアドレス、ユーザ名、パスワード

■データベースの設定

以下を設定します データベース名 ホスト名 ローカルサーバに接続するユーザ名、パスワード データベース名 テーブルに付けるプレフィックス jml01_ としました 参考 http://www.joomlaway.net/tutorial/15x/39-15x-install/1251-joomla-install-for-xampp-lite.html

XAMPP の初期設定

Windows環境にインストールした際の手順を示します。


■インストール

XAMPPをインストールする

■サーバの起動

ApacheとMySQLのスタート

■動作確認

http://localhost/ にアクセス 表示されるのを確認

■Apacheの設定

Apacheの設定に以下を追記 <directory htdocs="" xampp=""> AuthUserFile C:\xampp\apache\conf\.htpasswd # AuthGroupFile C:\xampp\apache\conf\groups AuthName "Basic Auth" AuthType Basic Require valid-user </directory>

■ベーシック認証の設定

shellからrootユーザを作成する以下のコマンドを入力 (インストールしたXAMPPフォルダで実行する) c:\xampp\apache\bin\htpasswd -c C:\xampp\apache\conf\.htpasswd root

■MySQLのパスワードを設定

cd c:\xampp\mysql\bin mysqladmin -u root password

■phpMyAdminのパスワードをデフォルト入力

C:\xampp\phpMyAdmin\config.inc.php 内の値をtestPassWordに変更 $cfg['Servers'][$i]['password'] = 'testPassWord';

■「http://localhost/phpmyadmin/」へアクセスして確認

■PHP設定ファイルを編集

C:\xampp\php\php.ini の957行目あたり、date.timezoneのコメントアウト削除しAsia/Tokyoとして再起動。 ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = Asia/Tokyo

■必要に応じてキャッシュの設定をする

参考 http://oxynotes.com/?p=10673#2 Dropboxを使った共有ローカル環境 http://kumakumahate.hatenablog.com/entry/xampp_dropbox

2017-09-08

【VisualForce】VFを使ってExcelファイルを出力する方法

以下のように設定する


<apex:page controller="コントローラクラス" 
  cache="true" 
  contentType="text/xml;charset=UTF-8#test.xml" 
  readOnly="true">


Excelでテスト用のファイルを作り、保存をするときにxml形式で保存する
保存したファイルのソースコードを確認し、apex:page タグの間に挿入する


このVFページを呼び出す


あとは、Apexなどを使い


    <apex:repeat value="{!csvRows}" var="row">
        <apex:outputText value="{!row.columns}" />
    </apex:repeat>


などでxmlを出力させてあげれば、
動的にExcelファイル(正確にはxml?)を生成することができる





【Salesforce】項目変更履歴から商談の変更をApexで検出する話

変更履歴に関するHistoryオブジェクトたち
・OpportunityHistory
項目内の値の変更を記録しているオブジェクト
カスタムオブジェクトでいう Foo__history にあたるもの


・OpportunityFieldHistory
フェーズの変更を記録しているオブジェクト


参考資料
https://developer.salesforce.com/docs/atlas.ja-jp.object_reference.meta/object_reference/sforce_api_objects_opportunityhistory.htm?search_text=Opportunity https://developer.salesforce.com/docs/atlas.ja-jp.object_reference.meta/object_reference/sforce_api_objects_opportunityfieldhistory.htm?search_text=%E5%B1%A5%E6%AD%B4



設定
デフォルトでは、項目履歴の設定はオフになっているので、
オブジェクトの設定からオンにしてあげる


考えられる制限
・項目変更履歴を設定できる項目数は20か40そこららしい
・項目変更履歴を保持している期間、数の制限がある可能性







2017-09-01

位置情報取得で必要なAPI Keyを取得する

google geocode apikeyの取得方法です。
・Google Mapsを利用するときは、APIキーは必須です!(2016.06.27時点)


Googleアカウントをログイン状態にしておきます


以下の[キーの取得]を押し、キーを発行するプロジェクトを選択するか、
「create project」からプロジェクトを新規作成します
https://developers.google.com/maps/documentation/geocoding/get-api-key?hl=ja


You're all set! が出てきたら、「DONE」は押さずに
To improve your app's security, restrict this key's usage in the API Console.
の API Console リンクを押します


保存を押します


APIとサービスページのダッシュボードに移動し、「Google Maps Geocoding API」が
有効になっていることを確認します。



参考
https://nendeb.com/276
https://www.deep-deep.jp/blog_engineer/archives/4186





【Salesforce】メールサービスについて

制限

・処理可能メール数はユーザライセンス数×1000(最大100万通)
・メールが (本文テキスト、本文 HTML および添付ファイルを合わせて) 約 10 MB を
超える場合、メールメッセージは拒否される


参考
https://help.salesforce.com/articleView?id=code_email_services_editing.htm&type=0
https://help.salesforce.com/articleView?id=code_inbound_email.htm&type=0