VBAで配列のサイズを指定しないと、エラーとなる
Dim isholiday() As Boolean
isholiday(0) = checkHoliday(sWeek)
真ん中に、下記記述を入れるとOK
ReDim isholiday(endDate - startDate)
最初から以下のように指定してもNGだった
Dim isholiday(endDate - startDate) As Boolean
2017年12月25日月曜日
2017年12月12日火曜日
C# Array
int[] a1 = new int[10]; //10 elements
int[,] a2 = new int[10, 5]; //二次、50 (10 × 5) elements
int[,,] a3 = new int[10, 5, 2]; //三次、100 (10 × 5 × 2) elements
// An array with elements of an array type is sometimes called a jagged array because the lengths of the element arrays do not all have to be the same.
// creates an array with three elements, each of type int[] and each with an initial value of null
int[][] a = new int[3][];
a[0] = new int[10];
a[1] = new int[5];
a[2] = new int[20];
// allocates and initializes an int[] with three elements. the length of the array is inferred from the number of expressions between { and }
int[] a = new int[] {1, 2, 3};
// Local variable and field declarations can be shortened further such that the array type does not have to be restated
int[] a = {1, 2, 3};
int[,] a2 = new int[10, 5]; //二次、50 (10 × 5) elements
int[,,] a3 = new int[10, 5, 2]; //三次、100 (10 × 5 × 2) elements
// An array with elements of an array type is sometimes called a jagged array because the lengths of the element arrays do not all have to be the same.
// creates an array with three elements, each of type int[] and each with an initial value of null
int[][] a = new int[3][];
a[0] = new int[10];
a[1] = new int[5];
a[2] = new int[20];
// allocates and initializes an int[] with three elements. the length of the array is inferred from the number of expressions between { and }
int[] a = new int[] {1, 2, 3};
// Local variable and field declarations can be shortened further such that the array type does not have to be restated
int[] a = {1, 2, 3};
2017年11月30日木曜日
DjangoのModel使用
1)Modelを定義
appフォルダーにmodels.pyにTableとColumnを定義
from django.db import models
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
2)appをProjectに結び付く
settings.pyのINSTALLED_APPSにappを追加
INSTALLED_APPS = [
'polls.apps.PollsConfig',
.....
3)migrations作成
python manage.py makemigrations polls
4)migrate実施
python manage.py sqlmigrate polls 0001 #どんなSQL実行されるか確認
python manage.py migrate
appフォルダーにmodels.pyにTableとColumnを定義
from django.db import models
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
2)appをProjectに結び付く
settings.pyのINSTALLED_APPSにappを追加
INSTALLED_APPS = [
'polls.apps.PollsConfig',
.....
3)migrations作成
python manage.py makemigrations polls
4)migrate実施
python manage.py sqlmigrate polls 0001 #どんなSQL実行されるか確認
python manage.py migrate
Django appを作成
1)Projectを作成、cloud9環境ではすでに作成されたので、不要
django-admin startproject mysite
2)appを作成
python manage.py startapp polls
Projects vs. apps
What’s the difference between a project and an app? An app is a Web application that does something – e.g., a Weblog system, a database of public records or a simple poll app. A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects.
3)Viewを作成
polls/views.py を編集
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
4)To call the view, we need to map it to a URL
polls/urls.py を作成
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
5)To point the root URLconf at the polls.urls module
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
6)DBの設定
MySQLのアクセスモジュールを追加
sudo pip3 install PyMySQL
Projectフォルダーにsettings.pyのDATABASESを変更
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'c9', #dbname
'USER': 'XXXXc9', #username
'PASSWORD': 'password',
'HOST': '',
'PORT': '',
}
}
manage.pyに以下を追加
import pymysql
pymysql.install_as_MySQLdb()
7)migrate実施
python manage.py migrate
settings.pyのINSTALLED_APPSに必要なTableが作成されれば、DB設定OK
django-admin startproject mysite
2)appを作成
python manage.py startapp polls
Projects vs. apps
What’s the difference between a project and an app? An app is a Web application that does something – e.g., a Weblog system, a database of public records or a simple poll app. A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects.
3)Viewを作成
polls/views.py を編集
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
4)To call the view, we need to map it to a URL
polls/urls.py を作成
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
5)To point the root URLconf at the polls.urls module
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
6)DBの設定
MySQLのアクセスモジュールを追加
sudo pip3 install PyMySQL
Projectフォルダーにsettings.pyのDATABASESを変更
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'c9', #dbname
'USER': 'XXXXc9', #username
'PASSWORD': 'password',
'HOST': '',
'PORT': '',
}
}
manage.pyに以下を追加
import pymysql
pymysql.install_as_MySQLdb()
7)migrate実施
python manage.py migrate
settings.pyのINSTALLED_APPSに必要なTableが作成されれば、DB設定OK
2017年10月26日木曜日
cloud9でpython3/djangoを設定
django projectの設定(歯車)から、python2->3にしてから以下を実施
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.4 /usr/bin/python ->ここ3.5を設定したら、djangoが認識してくれなかったとりあえず3.4にした
sudo pip3 install django
以下のコマンドでバージョン確認
python -V
python -m django --version
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.4 /usr/bin/python ->ここ3.5を設定したら、djangoが認識してくれなかったとりあえず3.4にした
sudo pip3 install django
以下のコマンドでバージョン確認
python -V
python -m django --version
2017年10月6日金曜日
macにphpmyadminをインストール
brew install phpmyadmin
sudo vi /etc/apache2/httpd.conf で以下の設定を最後に追加
Alias /phpmyadmin /usr/local/share/phpmyadmin
<Directory /usr/local/share/phpmyadmin/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
<IfModule mod_authz_core.c>
Require all granted
</IfModule>
<IfModule !mod_authz_core.c>
Order allow,deny
Allow from all
</IfModule>
</Directory>
sudo apachectl restart
参考:https://soarcode.jp/posts/55
2017年9月26日火曜日
cloud9で.netを使用
cloud9にBlankのworkspaceを作成してから、shellで以下のコマンドを実行。
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-get update
sudo apt-get install dotnet-sdk-2.0.0
確認するには、dotnetの情報を表示。
dotnet --info
Web APPを作成
dotnet new razor -o app
或いは、
mkdir app
cd app
dotnet new mvc
cloud9にアクセスできるように、Program.csを変更
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://0.0.0.0:8080") //この行を追加
.Build();
変更後のBuild
cd app
dotnet build
dotnet run
そして、通常のcloud9 app URLにアクセスすればOK
参考:https://www.youtube.com/watch?v=ioSeIpphmAA
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-trusty-prod trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
sudo apt-get update
sudo apt-get install dotnet-sdk-2.0.0
確認するには、dotnetの情報を表示。
dotnet --info
Web APPを作成
dotnet new razor -o app
或いは、
mkdir app
cd app
dotnet new mvc
cloud9にアクセスできるように、Program.csを変更
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls("http://0.0.0.0:8080") //この行を追加
.Build();
変更後のBuild
cd app
dotnet build
dotnet run
そして、通常のcloud9 app URLにアクセスすればOK
参考:https://www.youtube.com/watch?v=ioSeIpphmAA
2017年8月16日水曜日
Laravelにおけるviewに変数を渡す方法
viewのwelcomeに変数$nameを渡すには、以下の方法がある
1)
Route::get('/', function () {
return view('welcome', ['name' => 'World',
]);
});
2)
Route::get('/', function () {
return view('welcome')->with('name', 'World');
});
3)
Route::get('/', function () {
$name = 'World';
$age = 42;
return view('welcome', ['name' => $name,
'age' => $age,
]);
//same with, return view('welcome', compact('name', 'age'));
});
Route::get('/', function () {
$tasks = [
'qwe',
'asd',
'zxc'
];
return view('welcome', compact('tasks'));
});
1)
Route::get('/', function () {
return view('welcome', ['name' => 'World',
]);
});
2)
Route::get('/', function () {
return view('welcome')->with('name', 'World');
});
3)
Route::get('/', function () {
$name = 'World';
$age = 42;
return view('welcome', ['name' => $name,
'age' => $age,
]);
//same with, return view('welcome', compact('name', 'age'));
});
Route::get('/', function () {
$tasks = [
'qwe',
'asd',
'zxc'
];
return view('welcome', compact('tasks'));
});
valetの使い方
Valet is a Laravel development environment for Mac minimalists. No Vagrant, no /etc/hosts file.
Laravel Valet configures your Mac to always run Nginx in the background when your machine starts.
Then, using DnsMasq, Valet proxies all requests on the *.dev domain to point to sites installed on your local machine.
Laravel Valet configures your Mac to always run Nginx in the background when your machine starts.
Then, using DnsMasq, Valet proxies all requests on the *.dev domain to point to sites installed on your local machine.
インストールには
composer global require laravel/valet
valet install
valetが正しくインストールされているかどうかを確認するには、任意の.dev domianをpingしてみる
ping foo.dev
valetがサイトを探す時のpathを指定
mkdir lara
cd lara
valet park
larval new blog
blog.dev にアクセスすると、laravelの画面が出る
httpsを有効にする
valet secure blog
httpsを有効から無効にする
valet unsecure blog
valetが正しくインストールされているかどうかを確認するには、任意の.dev domianをpingしてみる
ping foo.dev
valetがサイトを探す時のpathを指定
mkdir lara
cd lara
valet park
larval new blog
blog.dev にアクセスすると、laravelの画面が出る
httpsを有効にする
valet secure blog
httpsを有効から無効にする
valet unsecure blog
2017年6月8日木曜日
remote desktop login in できない件
ADのユーザー設定に「test1」に「Remote Desktop Users」グループを追加したが、domain controllersにremote loginしようとしても入れない。
domain controllersの「Local Security Policy」→「Local Policies」→「User Rights Assignment」→「Allow log on through Remote Desktop Services」を確認したところ、domain controllersにremote loginの場合、デフォルトAdministratorsメンバーのみできる
domain controllersの「Local Security Policy」→「Local Policies」→「User Rights Assignment」→「Allow log on through Remote Desktop Services」を確認したところ、domain controllersにremote loginの場合、デフォルトAdministratorsメンバーのみできる
2017年5月26日金曜日
laravel foreign key migration error
下記foreign keyを指定しようと、エラーとなった。
$table->foreign('dept_id')->references('id')->on('depts');
[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`c9`.`#sql-acb_114`, CONSTRAINT `employees_dept_id_foreign` FOREIGN KEY (`dept_id`) REFERENCES `depts` (
`id`)) (SQL: alter table `employees` add constraint `employees_dept_id_foreign` foreign key (`dept_id`) references `depts` (`id`))
原因は、外部Keyを追加したいtableはすでに値が入っている場合、nullableと指定しないといけない
$table-> unsignedInteger ('dept_id')->after('gender')->nullable();
参考:https://laracasts.com/discuss/channels/laravel/foreign-key-error-on-migration
$table->foreign('dept_id')->references('id')->on('depts');
[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`c9`.`#sql-acb_114`, CONSTRAINT `employees_dept_id_foreign` FOREIGN KEY (`dept_id`) REFERENCES `depts` (
`id`)) (SQL: alter table `employees` add constraint `employees_dept_id_foreign` foreign key (`dept_id`) references `depts` (`id`))
原因は、外部Keyを追加したいtableはすでに値が入っている場合、nullableと指定しないといけない
$table-> unsignedInteger ('dept_id')->after('gender')->nullable();
参考:https://laracasts.com/discuss/channels/laravel/foreign-key-error-on-migration
2017年5月25日木曜日
openAM IdP設定
1)SPのMetadataをDL
http://sp.xxxxx.jp/Shibboleth.sso/Metadata にアクセス、ファイルをDL
entityIDをSP側のApplicationDefaultsのentityIDと同じものに変更。複数ポートあるSPなら、それぞれのポートを指定し、ファイルをDL
2)MetadataをopenAMにセット
openAMの管理者画面から、Create SAMLv2 Providers->Register Remote Service Provider
「ファイル」を選択Metadataをアップロード
トラストサークルがない場合、新規作成。ある場合、既存のものに追加できる
「設定」ボタンを押すと、Remote Service Providerが追加される
3)属性マップの設定
FEDERATION(連携)画面の「エンティティープロバイダ」のIdP(http://openam.nijigo.local:8080/openam)をクリック、表明処理->属性マッパー
SPのattribute-map.xmlに定義しているnameと合うように設定、例えば
urn:oid:0.9.2342.19200300.100.1.1=uid
この設定によって、IdP側はuidの値(test1)をSP側にSAMLで渡す
<saml:Attribute Name="urn:oid:0.9.2342.19200300.100.1.1">
<saml:AttributeValue
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xs:string"
>test1</saml:AttributeValue>
http://sp.xxxxx.jp/Shibboleth.sso/Metadata にアクセス、ファイルをDL
entityIDをSP側のApplicationDefaultsのentityIDと同じものに変更。複数ポートあるSPなら、それぞれのポートを指定し、ファイルをDL
2)MetadataをopenAMにセット
openAMの管理者画面から、Create SAMLv2 Providers->Register Remote Service Provider
「ファイル」を選択Metadataをアップロード
トラストサークルがない場合、新規作成。ある場合、既存のものに追加できる
「設定」ボタンを押すと、Remote Service Providerが追加される
3)属性マップの設定
FEDERATION(連携)画面の「エンティティープロバイダ」のIdP(http://openam.nijigo.local:8080/openam)をクリック、表明処理->属性マッパー
SPのattribute-map.xmlに定義しているnameと合うように設定、例えば
urn:oid:0.9.2342.19200300.100.1.1=uid
この設定によって、IdP側はuidの値(test1)をSP側にSAMLで渡す
<saml:Attribute Name="urn:oid:0.9.2342.19200300.100.1.1">
<saml:AttributeValue
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xs:string"
>test1</saml:AttributeValue>
Shibboleth SPの設定
今回、SSO実現するためのSP側の設定となる。主に3つのXMLが中心的な役割を果たす。デフォルトの場所は、C:\opt\shibboleth-sp\etc\shibboleth にある
1)shibboleth2.xml、一番重要な設定ファイル。
①InProcess/ISAPI/Site
IISのSitesのIDとBindingポート番号と同じように設定する。また、nameはサイトのURLとなる。
<Site id="1" name="sp.xxxxx.jp"/>
<Site id="2" name="sp.xxxxx.jp" scheme="http" port="1116"/>
<Site id="3" name="sp.xxxxx.jp" port="1117"/>
②RequestMapper/RequestMap/Host
nameは上記Siteのname:portとなる。アクセス認証必要な部分は、Pathで設定。今回の場合sp.xxxxx.jp/ssoにアクセスする場合、認証が必要。複数ポートがある場合、デフォルト以外のapplicationIdを指定する必要がある。
<Host name="sp.xxxxx.jp">
<Path name="sso" authType="shibboleth" requireSession="true"/>
</Host>
<Host name="sp.xxxxx.jp:1116" applicationId="1116AAA">
<Path name="sso" authType="shibboleth" requireSession="true"/>
</Host>
<Host name="sp.xxxxx.jp:1117" applicationId="1117BBB">
<Path name="sso" authType="shibboleth" requireSession="true"/>
</Host>
SSO entityIDはIdP側のentityIDで、3)のmetadataにあるものと一致させる
http://openam.xxxxx.local:8080/openam
discovery serviceを使っていないため、discoveryProtocolとdiscoveryURL項目を削除
下記3)のmetadataを指定
<MetadataProvider type="XML" file="idp-metadata.xml"/>
複数ポートの場合、先定義したapplicationIdを使用する
<ApplicationOverride id="1116AAA" entityID="http://sp.xxxxx.jp:1116/shibboleth"/>
<ApplicationOverride id="1117BBB" entityID="http://sp.xxxxx.jp:1117/shibboleth"/>
2)attribute-map.xml
IdP側が送られたユーザー情報のattributeをどのようにマッピングするかの定義。デフォルトLDAP-based attributesがコメントしているため、コメントアウトする。このファイルが更新された場合、Shibboleth Daemonを再起動。
<Attribute name="urn:oid:0.9.2342.19200300.100.1.1" id="uid"/>
上記記述の意味は、IdPからPOSTされたSAMLの情報に、Name="urn:oid:0.9.2342.19200300.100.1.1"の値「test1」を$_SERVER["HTTP_UID"]に保存される(PHPの場合)
<saml:Attribute Name="urn:oid:0.9.2342.19200300.100.1.1">
<saml:AttributeValue
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xs:string"
>test1</saml:AttributeValue>
SAMLファイルにあるNameはIdP側で設定する必要がある。別途IdPの設定を参照
3)以下のIdPサーバーにアクセスし、Matadataを入手、C:\opt\shibboleth-sp\etc\shibbolethにidp-metadata.xmlとして保存。このファイルには、IdPのアクセスポイント、証明書などが定義されている。
http://openam.xxxxx.local:8080/openam/saml2/jsp/exportmetadata.jsp?entityid=
参考:http://blogs.forgerock.org/petermajor/2010/09/how-to-access-federation-metadata-from-browser/
1)shibboleth2.xml、一番重要な設定ファイル。
①InProcess/ISAPI/Site
IISのSitesのIDとBindingポート番号と同じように設定する。また、nameはサイトのURLとなる。
<Site id="1" name="sp.xxxxx.jp"/>
<Site id="2" name="sp.xxxxx.jp" scheme="http" port="1116"/>
<Site id="3" name="sp.xxxxx.jp" port="1117"/>
②RequestMapper/RequestMap/Host
nameは上記Siteのname:portとなる。アクセス認証必要な部分は、Pathで設定。今回の場合sp.xxxxx.jp/ssoにアクセスする場合、認証が必要。複数ポートがある場合、デフォルト以外のapplicationIdを指定する必要がある。
<Host name="sp.xxxxx.jp">
<Path name="sso" authType="shibboleth" requireSession="true"/>
</Host>
<Host name="sp.xxxxx.jp:1116" applicationId="1116AAA">
<Path name="sso" authType="shibboleth" requireSession="true"/>
</Host>
<Host name="sp.xxxxx.jp:1117" applicationId="1117BBB">
<Path name="sso" authType="shibboleth" requireSession="true"/>
</Host>
③ApplicationDefaults
entityIDは任意の値でも良いが、一般的に以下のような形
http://sp.xxxxx.jp/shibboleth
http://sp.xxxxx.jp/shibboleth
SSO entityIDはIdP側のentityIDで、3)のmetadataにあるものと一致させる
http://openam.xxxxx.local:8080/openam
discovery serviceを使っていないため、discoveryProtocolとdiscoveryURL項目を削除
下記3)のmetadataを指定
<MetadataProvider type="XML" file="idp-metadata.xml"/>
複数ポートの場合、先定義したapplicationIdを使用する
<ApplicationOverride id="1116AAA" entityID="http://sp.xxxxx.jp:1116/shibboleth"/>
<ApplicationOverride id="1117BBB" entityID="http://sp.xxxxx.jp:1117/shibboleth"/>
2)attribute-map.xml
IdP側が送られたユーザー情報のattributeをどのようにマッピングするかの定義。デフォルトLDAP-based attributesがコメントしているため、コメントアウトする。このファイルが更新された場合、Shibboleth Daemonを再起動。
<Attribute name="urn:oid:0.9.2342.19200300.100.1.1" id="uid"/>
上記記述の意味は、IdPからPOSTされたSAMLの情報に、Name="urn:oid:0.9.2342.19200300.100.1.1"の値「test1」を$_SERVER["HTTP_UID"]に保存される(PHPの場合)
<saml:Attribute Name="urn:oid:0.9.2342.19200300.100.1.1">
<saml:AttributeValue
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="xs:string"
>test1</saml:AttributeValue>
SAMLファイルにあるNameはIdP側で設定する必要がある。別途IdPの設定を参照
3)以下のIdPサーバーにアクセスし、Matadataを入手、C:\opt\shibboleth-sp\etc\shibbolethにidp-metadata.xmlとして保存。このファイルには、IdPのアクセスポイント、証明書などが定義されている。
http://openam.xxxxx.local:8080/openam/saml2/jsp/exportmetadata.jsp?entityid=
参考:http://blogs.forgerock.org/petermajor/2010/09/how-to-access-federation-metadata-from-browser/
laravel5.4 DB migration
1)table作成
php artisan make:migration create_posts_table
php artisan make:migration create_categories_table
php artisan make:migration create_comments_table
database/migrationsに新たに3つファイルが作成された、それぞれ以下のように編集
2017_05_23_143039_create_posts_table
2017_05_23_143100_create_categories_table
下記エラーになる場合、対応が必要。(mysql5.7.7以降のバージョンなら対応不要)
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
app/Providers/AppServiceProvider.php に以下のように追加
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
参考:https://manablog.org/laravel_bulletin_board/
https://laravel-news.com/laravel-5-4-key-too-long-error
php artisan make:migration create_posts_table
php artisan make:migration create_categories_table
php artisan make:migration create_comments_table
database/migrationsに新たに3つファイルが作成された、それぞれ以下のように編集
2017_05_23_143039_create_posts_table
public function up()
{
Schema::create('posts', function($table){
$table->increments('id');
$table->string('title');
$table->string('cat_id'); // ポストテーブルとカテゴリーテーブルの紐付けに利用します
$table->text('content');
$table->unsignedInteger('comment_count'); // 投稿に何件のコメントがついたのかをカウントします
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('posts');
}
2017_05_23_143100_create_categories_table
public function up()
{
Schema::create('categories', function($table){
$table->increments('id');
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('categories');
}
2017_05_23_143113_create_comments_tablepublic function up()
{
Schema::create('comments', function($table){
$table->increments('id');
$table->unsignedInteger('post_id'); // ポストテーブルとコメントテーブルの紐付けに利用します
$table->string('commenter');
$table->text('comment');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('comments');
}
php artisan migrate でtableが作成される下記エラーになる場合、対応が必要。(mysql5.7.7以降のバージョンなら対応不要)
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes
app/Providers/AppServiceProvider.php に以下のように追加
use Illuminate\Support\Facades\Schema;
public function boot()
{
Schema::defaultStringLength(191);
}
参考:https://manablog.org/laravel_bulletin_board/
https://laravel-news.com/laravel-5-4-key-too-long-error
IISとShibbolethのインストール
SSO実現するには、IdP側はopenAMを使用、SP側はShibbolethを使用。Shibbolethのインストール手順は以下の通り。
1)IISをインストール
2)IISインストールオプションに必要な項目を追加
3)ShibbolethのSPモジュールをインストール
https://shibboleth.net/downloads/service-provider/latest/にて使用するOSのパッケージをDLし、インストーラの指示通り実行。(再起動が必要)
4)IISの設定確認
①ISAPI Filters
②Handler Mappings
③ISAPI and CGI Restrictions
5)Shibboleth Daemon起動しているかどうかを確認
6)Shibbolethの状態を確認
http://localhost/Shibboleth.sso/Status にアクセスして、画面の最後のところに下記になっているなら、OK
<Status>
<OK/>
</Status>
1)IISをインストール
2)IISインストールオプションに必要な項目を追加
3)ShibbolethのSPモジュールをインストール
https://shibboleth.net/downloads/service-provider/latest/にて使用するOSのパッケージをDLし、インストーラの指示通り実行。(再起動が必要)
4)IISの設定確認
①ISAPI Filters
②Handler Mappings
③ISAPI and CGI Restrictions
5)Shibboleth Daemon起動しているかどうかを確認
6)Shibbolethの状態を確認
http://localhost/Shibboleth.sso/Status にアクセスして、画面の最後のところに下記になっているなら、OK
<Status>
<OK/>
</Status>
ラベル:
IIS,
shibboleth,
SSO
2017年5月23日火曜日
laravel5.4 say hello
laravelがインストール完了したあと、
1)コントローラーを作成
php artisan make:controller Hello
app/Http/Controllers/Hello.phpが作成され
2)routes/web.phpに下記を追加し、public/helloにアクセスしてみると「Hello World!」が表示される
Route::get('/hello',function(){
return 'Hello World!';
});
3)routes/web.phpを変更してみる
Route::get('hello', 'Hello@index');
4)app/Http/Controllers/Hello.phpに下記を追加、再度public/helloにアクセスしてみる
public function index()
{
return 'hello world from controller : )';
}
5)Viewを追加してみる
resources/views/hello.blade.phpを作成、以下を追加
6)routes/web.phpに下記を追加
Route::get('/hello/{name}', 'Hello@show');
7)app/Http/Controllers/Hello.phpにshowファンクションを追加
public function show($name)
{
return view('hello',array('name' => $name));
}
8)public/hello/{name}にアクセスしてみる
参考:https://tutorials.kode-blog.com/laravel-hello-world
1)コントローラーを作成
php artisan make:controller Hello
app/Http/Controllers/Hello.phpが作成され
2)routes/web.phpに下記を追加し、public/helloにアクセスしてみると「Hello World!」が表示される
Route::get('/hello',function(){
return 'Hello World!';
});
3)routes/web.phpを変更してみる
Route::get('hello', 'Hello@index');
4)app/Http/Controllers/Hello.phpに下記を追加、再度public/helloにアクセスしてみる
public function index()
{
return 'hello world from controller : )';
}
5)Viewを追加してみる
resources/views/hello.blade.phpを作成、以下を追加
<!DOCTYPE html>
<html>
<head>
<title>Laravel</title>
<link href="//fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
<style>
html, body {
height: 100%;
}
body {
margin: 0;
padding: 0;
width: 100%;
display: table;
font-weight: 100;
font-family: 'Lato';
}
.container {
text-align: center;
display: table-cell;
vertical-align: middle;
}
.content {
text-align: center;
display: inline-block;
}
.title {
font-size: 96px;
}
</style>
</head>
<body>
<div class="container">
<div class="content">
<div class="title">Hello {{$name}}, welcome to Laraland! : )</div>
</div>
</div>
</body>
</html>
6)routes/web.phpに下記を追加
Route::get('/hello/{name}', 'Hello@show');
7)app/Http/Controllers/Hello.phpにshowファンクションを追加
public function show($name)
{
return view('hello',array('name' => $name));
}
8)public/hello/{name}にアクセスしてみる
参考:https://tutorials.kode-blog.com/laravel-hello-world
cloud9にLaravel5をインストール
1)cloud9でPHP/Apache projectを作成
2)bashでcomposerの準備
sudo composer self-update
sudo composer global require "laravel/installer"
export PATH=~/.composer/vendor/bin:$PATH
3)PHP7にupdate
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install libapache2-mod-php7.0
sudo a2dismod php5
sudo a2enmod php7.0
sudo apt-get install php7.0-dom php7.0-mbstring php7.0-zip php7.0-mysql
4)laravelアプリを作成
laravel new {app-name}
https://lalatest-xxxxxc9.c9users.io/{app-name}/public/
5){app-name}/config/app.phpの設定
'timezone' => 'Asia/tokyo',
'locale' => 'ja',
6){app-name}/config/database.phpの設定
'mysql' => [
....
'database' => 'c9',
'username' => 'xxxxxc9',
'password' => '',
....
7)デバッグ機能を有効化(オプション)
{app-name}/config/app.phpに
'debug' => true,
参考:http://qiita.com/mike_fx/items/c3da0fcd3050d7ea2f26
2)bashでcomposerの準備
sudo composer self-update
sudo composer global require "laravel/installer"
export PATH=~/.composer/vendor/bin:$PATH
3)PHP7にupdate
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install libapache2-mod-php7.0
sudo a2dismod php5
sudo a2enmod php7.0
sudo apt-get install php7.0-dom php7.0-mbstring php7.0-zip php7.0-mysql
4)laravelアプリを作成
laravel new {app-name}
https://lalatest-xxxxxc9.c9users.io/{app-name}/public/
5){app-name}/config/app.phpの設定
'timezone' => 'Asia/tokyo',
'locale' => 'ja',
6){app-name}/config/database.phpの設定
'mysql' => [
....
'database' => 'c9',
'username' => 'xxxxxc9',
'password' => '',
....
7)デバッグ機能を有効化(オプション)
{app-name}/config/app.phpに
'debug' => true,
参考:http://qiita.com/mike_fx/items/c3da0fcd3050d7ea2f26
2017年5月16日火曜日
AWS windows server 2012R2にopenamをインストール
1)AWSにwindows server 2012R2のインスタンスを追加
基本的に、GUIの指示に沿って、特に問題ない。セキュリティグループの設定もこの時点でしなかった
2)インスタンスに接続(リモートデスクトップ)
インスタンス一覧の「接続」ボタンを押せば、指示通りで問題ない
3)JDKインストール
今回は8にした。JAVA_HOME環境変数を設定
4)tomcatインストール
こちらは7のzipファイルをDLし(8だとopenamが動かない)、c:\tomcatに展開
CATALINA_HOME環境変数を「c:\tomcat」に設定
C:\tomcat\binにsetenv.batを作成
set CATALINA_OPTS=-Xmx2048m -XX:MaxPermSize=512m
5)openamをインストール
forgerockのHPでOpenAM Enterprise 13.0.0のwarファイルをDL
名前をopenam.warに変更しC:\tomcat\webappsにコピー
C:\tomcat\bin\startup.bat で起動
6)http://localhost:8080/openam/にアクセスすると、設定画面が出てくる
7)C:\Windows\System32\drivers\etc\hostsファイルに下記追加
awsのprivate IP openam.xxx.xxx
8)http://www.openam.jp/wp-content/uploads/techtips_vol1.pdf の手順で新しい設定を行う。ここで注意することは、Server URLには「.」2つ以上にする必要ある。あと、windowsサーバーの場合、firewallをoffにしてください。
参考:http://yomon.hatenablog.com/entry/2015/09/13/235857
https://t246osslab.wordpress.com/2014/10/08/openam%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E6%99%82%E3%81%AE%E6%B3%A8%E6%84%8F%E7%82%B9%E3%81%A8%E3%83%88%E3%83%A9%E3%83%96%E3%83%AB%E3%82%B7%E3%83%A5%E3%83%BC%E3%83%86%E3%82%A3/
基本的に、GUIの指示に沿って、特に問題ない。セキュリティグループの設定もこの時点でしなかった
2)インスタンスに接続(リモートデスクトップ)
インスタンス一覧の「接続」ボタンを押せば、指示通りで問題ない
3)JDKインストール
今回は8にした。JAVA_HOME環境変数を設定
4)tomcatインストール
こちらは7のzipファイルをDLし(8だとopenamが動かない)、c:\tomcatに展開
CATALINA_HOME環境変数を「c:\tomcat」に設定
C:\tomcat\binにsetenv.batを作成
set CATALINA_OPTS=-Xmx2048m -XX:MaxPermSize=512m
5)openamをインストール
forgerockのHPでOpenAM Enterprise 13.0.0のwarファイルをDL
名前をopenam.warに変更しC:\tomcat\webappsにコピー
C:\tomcat\bin\startup.bat で起動
6)http://localhost:8080/openam/にアクセスすると、設定画面が出てくる
7)C:\Windows\System32\drivers\etc\hostsファイルに下記追加
awsのprivate IP openam.xxx.xxx
8)http://www.openam.jp/wp-content/uploads/techtips_vol1.pdf の手順で新しい設定を行う。ここで注意することは、Server URLには「.」2つ以上にする必要ある。あと、windowsサーバーの場合、firewallをoffにしてください。
参考:http://yomon.hatenablog.com/entry/2015/09/13/235857
https://t246osslab.wordpress.com/2014/10/08/openam%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E6%99%82%E3%81%AE%E6%B3%A8%E6%84%8F%E7%82%B9%E3%81%A8%E3%83%88%E3%83%A9%E3%83%96%E3%83%AB%E3%82%B7%E3%83%A5%E3%83%BC%E3%83%86%E3%82%A3/
2017年4月18日火曜日
getElementsByClassNameに対するaddEventListener
下記コードがエラーになった。
document.getElementsByClassName( "jpg" ).addEventListener( "click", function(e) {...});
調べたら、forでloopの中で一つ一つaddEventListenerが必要となる
var jpgBtn = document.getElementsByClassName( "jpg" );
for (i = 0; i < jpgBtn.length; i++) {
jpgBtn[i].addEventListener( "click", function(e) {
console.log(this);
console.log(e);
});
}
document.getElementsByClassName( "jpg" ).addEventListener( "click", function(e) {...});
調べたら、forでloopの中で一つ一つaddEventListenerが必要となる
var jpgBtn = document.getElementsByClassName( "jpg" );
for (i = 0; i < jpgBtn.length; i++) {
jpgBtn[i].addEventListener( "click", function(e) {
console.log(this);
console.log(e);
});
}
2017年4月14日金曜日
SVGのimage要素での外部画像ファイル参照する場合欠落現象
Fabricjsを使って、いくつかの画像と文字を編集し、以下のように全体をsvgのdata uriとして保存し、imgタグに入れた場合、SVGファイルに「xlink:href」で外部画像を参照する部分が欠落してしまった。
var result = fabCanvas.toSVG();
var dataUri = 'data:image/svg+xml,' + encodeURIComponent(result);
$("#result").html("<img src='" + dataUri + "'/>");
そのため、参照ファイルもdata uriに変換することで対応した。
function drawFrame() {
fabric.Image.fromURL('../img/frame.png', function(oImg) {
var dataUri = oImg.toDataURL();
fabCanvas.setBackgroundImage(dataUri,function(oImg) {
......
});
});
fabric.Image.fromURL('../img/frame_resize_mask.png', function(oImg) {
var dataUri = oImg.toDataURL();
fabCanvas.setOverlayImage(dataUri);
});
}
参考:http://fingaholic.github.io/posts/2012-09-10-svg.html
var result = fabCanvas.toSVG();
var dataUri = 'data:image/svg+xml,' + encodeURIComponent(result);
$("#result").html("<img src='" + dataUri + "'/>");
そのため、参照ファイルもdata uriに変換することで対応した。
function drawFrame() {
fabric.Image.fromURL('../img/frame.png', function(oImg) {
var dataUri = oImg.toDataURL();
fabCanvas.setBackgroundImage(dataUri,function(oImg) {
......
});
});
fabric.Image.fromURL('../img/frame_resize_mask.png', function(oImg) {
var dataUri = oImg.toDataURL();
fabCanvas.setOverlayImage(dataUri);
});
}
参考:http://fingaholic.github.io/posts/2012-09-10-svg.html
2017年4月6日木曜日
jQuery TOOLS使用時ajax POSTうまく機能しない
overlayなど簡単に実現できるjQuery TOOLSライブラリを入れる場合、jqueryそのものが勝手に入れてくれる。なぜか、以前うまく機能していたコードがエラーになって、データをサーバーに転送されなくなった
$.ajax({
method: "POST",
url: '/Projects/ajaxCall',
data: { "base64image" : base64image, "projectName" : projectName },
success: function (msg) {
alert("デザインが保存されました。");
console.log("OK");
},
error: function (response, desc, exception) {
console.log("NG");
}
});
そして、ajaxで"POST"を指定することではなく、直接にpost methodを使うことで解決した。原因はわからないが、jQuery TOOLSライブラリのせいだと思う
$.post(
'/Projects/ajaxCall',
{
"base64image" : base64image,
"projectName" : projectName
},
function(data){
alert("デザインが保存されました。");
console.log("OK");
});
$.ajax({
method: "POST",
url: '/Projects/ajaxCall',
data: { "base64image" : base64image, "projectName" : projectName },
success: function (msg) {
alert("デザインが保存されました。");
console.log("OK");
},
error: function (response, desc, exception) {
console.log("NG");
}
});
そして、ajaxで"POST"を指定することではなく、直接にpost methodを使うことで解決した。原因はわからないが、jQuery TOOLSライブラリのせいだと思う
$.post(
'/Projects/ajaxCall',
{
"base64image" : base64image,
"projectName" : projectName
},
function(data){
alert("デザインが保存されました。");
console.log("OK");
});
2017年4月4日火曜日
Speaking JavaScript -- Statements Expressions Functions
ネットで公開している本(http://speakingjs.com/)を見つかった。ものすごく良いみたい、ここで重要なところをメモする
In other languages, you learn language features. In JavaScript, you often learn patterns instead.
In other languages, you learn language features. In JavaScript, you often learn patterns instead.
Statements Versus Expressions
Statements “do things.” A program is a sequence of statements.
文,是"做事"
Expressions produce values. They are function arguments, the right side of an assignment, etc.
式,"产生值",在赋值的右边
Finally, wherever JavaScript expects a statement, you can also use an expression; for example:在需要文之处,总可以使用"式;"
文,是"做事"
Expressions produce values. They are function arguments, the right side of an assignment, etc.
式,"产生值",在赋值的右边
Finally, wherever JavaScript expects a statement, you can also use an expression; for example:在需要文之处,总可以使用"式;"
The whole line is a statement (a so-called expression statement), but the function callfoo
(
7
,
1
);
foo(7, 1)
is an expression.整个line是文,但foo(7, 1)是式
Using ambiguous expressions as statements
Two kinds of expressions look like statements—they are ambiguous with regard to their syntactic category:
- Object literals (expressions) look like blocks (statements):
{
foo
:
bar
(
3
,
5
)
}
The preceding construct is either an object literal (details: Object Literals) or a block followed by the labelfoo:
, followed by the function callbar(3, 5)
. - Named function expressions look like function declarations (statements):
function
foo
()
{
}
The preceding construct is either a named function expression or a function declaration. The former produces a function, the latter creates a variable and assigns a function to it (details on both kinds of function definition: Defining Functions).
In order to prevent ambiguity during parsing, JavaScript does not let you use object literals and function expressions as statements. That is, expression statements must not start with:
- A curly brace
- The keyword
function
If an expression starts with either of those tokens, it can only appear in an expression context. You can comply with that requirement by, for example, putting parentheses around the expression. Next, we’ll look at two examples where that is necessary.
Evaluating an object literal via eval()
eval
parses its argument in statement context. You have to put parentheses around an object literal if you want eval
to return an object:> eval('{ foo: 123 }') 123 > eval('({ foo: 123 })') { foo: 123 }
Immediately invoking a function expression
The following code is an immediately invoked function expression (IIFE), a function whose body is executed right away (you’ll learn what IIFEs are used for in Introducing a New Scope via an IIFE):
> (function () { return 'abc' }()) 'abc'
If you omit the parentheses, you get a syntax error, because JavaScript sees a function declaration, which can’t be anonymous:
> function () { return 'abc' }() SyntaxError: function statement requires a name
If you add a name, you also get a syntax error, because function declarations can’t be immediately invoked:
> function foo() { return 'abc' }() SyntaxError: Unexpected token )
Whatever follows a function declaration must be a legal statement and
()
isn’t.Functions
One way of defining a function is via a function declaration:定义函数一种方法是函数宣言
function
add
(
param1
,
param2
)
{
return
param1
+
param2
;
}
The preceding code defines a function,
add
, that has two parameters, param1
and param2
, and returns the sum of both parameters. This is how you call that function:> add(6, 1) 7 > add('a', 'b') 'ab'
Another way of defining
add()
is by assigning a function expression to a variable add
:另一种是函数式var
add
=
function
(
param1
,
param2
)
{
return
param1
+
param2
;
};
A function expression produces a value and can thus be used to directly pass functions as arguments to other functions:函数式产生值,可以直接传递给另一个函数作为参数
someOtherFunction
(
function
(
p1
,
p2
)
{
...
});
Variables Are Function-Scoped
The scope of a variable is always the complete function (as opposed to the current block). For example:变量的范围总是整个函数
function
foo
()
{
var
x
=
-
512
;
if
(
x
<
0
)
{
// (1)
var
tmp
=
-
x
;
...
}
console
.
log
(
tmp
);
// 512
}
We can see that the variable
tmp
is not restricted to the block starting in line (1); it exists until the end of the function.Closures
Each function stays connected to the variables of the functions that surround it, even after it leaves the scope in which it was created. For example:每个函数与包围其函数的变量有关联,即使离开了创建该函数的范围(环境)
function
createIncrementor
(
start
)
{
return
function
()
{
// (1)
start
++
;
return
start
;
}
}
The function starting in line (1) leaves the context in which it was created, but stays connected to a live version of
start
:> var inc = createIncrementor(5); //inc成为一个函数,不需要参数。start为5 > inc() 6 > inc() 7 > inc() //start为5一直被inc所记忆 8
A closure is a function plus the connection to the variables of its surrounding scopes. Thus, what
createIncrementor()
returns is a closure.The IIFE Pattern: Introducing a New Scope
Sometimes you want to introduce a new variable scope—for example, to prevent a variable from becoming global. In JavaScript, you can’t use a block to do so; you must use a function. But there is a pattern for using a function in a block-like manner. It is called IIFE (immediately invoked function expression, pronounced “iffy”):在JS中不能通过block去限制变量范围,但可以使用即时调用函数来模仿block-like
(
function
()
{
// open IIFE
var
tmp
=
...;
// not a global variable
}());
// close IIFE
Be sure to type the preceding example exactly as shown (apart from the comments). An IIFE is a function expression that is called immediately after you define it. Inside the function, a new scope exists, preventing
tmp
from becoming global.IIFE use case: inadvertent sharing via closures
Closures keep their connections to outer variables, which is sometimes not what you want: result[1]是函数function () { return i },这时i已经变成了5,这个i类似全局变量
var
result
=
[];
for
(
var
i
=
0
;
i
<
5
;
i
++
)
{
result
.
push
(
function
()
{
return
i
});
// (1)
}
console
.
log
(
result
[
1
]());
// 5 (not 1)
console
.
log
(
result
[
3
]());
// 5 (not 3)
The value returned in line (1) is always the current value of
i
, not the value it had when the function was created. After the loop is finished, i
has the value 5, which is why all functions in the array return that value. If you want the function in line (1) to receive a snapshot of the current value of i
, you can use an IIFE: 通过即时调用函数,i2只在(1)范围内有效,被里面的函数关联上,保存在Closure中for
(
var
i
=
0
;
i
<
5
;
i
++
)
{
(
function
()
{ // (1)
var
i2
=
i
;
// copy current i
result
.
push
(
function
()
{
return
i2
});
}());
}
登録:
投稿 (Atom)