Skip to content

Instantly share code, notes, and snippets.

View horike37's full-sized avatar

Takahiro Horike horike37

  • Serverless Operations, Inc
  • Japan
View GitHub Profile
@horike37
horike37 / cognito.php
Last active October 3, 2015 13:54
Cognitoでfacebook認証して、STSで認可して、S3に画像をアップロードするPHPスクリプト
<?php
require_once("vendor/autoload.php");
use Aws\CognitoIdentity\CognitoIdentityClient;
use Aws\Sts\StsClient;
use Aws\S3\S3Client;
$facebook = new Facebook(array(
'appId' => '<facebookのappid>',
'secret' => '<facebookのsecret>',
));
@horike37
horike37 / duplicate-trustform-for-multisite.php
Last active April 12, 2016 07:03
親サイト(blog_idが1)に作ったTrust Formのフォームを新規サイト作成時にコピーして、自動で固定ページにフォームを設置するコード
<?php
add_action( 'wpmu_new_blog', function($blog_id) {
//マルチサイトの親のお問い合わせデータを取ってくる
switch_to_blog(1);
$trust_form = get_posts( array('post_type'=>'trust-form') );
if ( empty($trust_form) ) {
return;
}
@horike37
horike37 / startInstance.js
Created November 27, 2015 02:52
EC2インスタンスを起動させるためのLambdaファンクション
var AWS = require('aws-sdk');
function startInstance(instance_id, context) {
var ec2 = new AWS.EC2();
var params = {
InstanceIds: [
instance_id
]
};
@horike37
horike37 / getMetricStatics.js
Last active November 27, 2015 03:05
CloudWatchのメトリックを取得するLambdaファンクション
var AWS = require('aws-sdk');
function ISODateString(d){
function pad(n){return n<10 ? '0'+n : n}
return d.getUTCFullYear()+'-'
+ pad(d.getUTCMonth()+1)+'-'
+ pad(d.getUTCDate())+'T'
+ pad(d.getUTCHours())+':'
+ pad(d.getUTCMinutes())+':'
+ pad(d.getUTCSeconds())+'Z'
@horike37
horike37 / amimotoviewcontroller.m
Created November 27, 2015 03:07
startInstanceのLambdaを起動させるobjective-cのコード
- (IBAction)startInstance:(id)sender {
LAContext *myContext = [[LAContext alloc] init];
NSError *error = nil;
// 端末が指紋認証を使えるかどうか判定
if([myContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
NSString *myLocalizedReasonString = @"指紋認証せんかい!";
[self.activityIndicator startAnimating];
// 指紋認証画面を表示
[myContext evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics
@horike37
horike37 / query.php
Last active December 10, 2015 15:27
WordPress上の記事をElasticaをつかってElasticSearchにインポート
<?php
require_once 'vendor/autoload.php';
use Elastica\Client;
use Elastica\Query;
use Elastica\Query\QueryString;
add_action( 'pre_get_posts', function($query){
if ( $query->is_search() && $query->is_main_query() ) {
$client = new \Elastica\Client(array(
@horike37
horike37 / amimoto-single-instance.json
Last active January 6, 2016 22:30
VPCのネットワーク設定からシングルインスタンスのAMIMOTO立ち上げるCloudFormation テンプレート
{
"Parameters":{
"InstanceType": {
"Description": "EC2 instance type",
"Type": "String",
"Default": "t2.small",
"AllowedValues": [
"t2.small",
"t2.medium",
"t2.large",
@horike37
horike37 / test.js
Last active November 12, 2020 16:31
The sample code of unit test Lambda function in Serverless Framework projects .
const path = require('path'),
chai = require('chai'),
should = chai.should(),
Serverless = require('serverless')
describe('ServerlessProjectTest', function() {
beforeEach(function(done) {
this.timeout(0);
s = new Serverless();
service: horike-service
provider: aws
functions:
hello:
handler: handler.hello
events:
- http:
path: hello
method: GET
resources:
'use strict';
const AWS = require('aws-sdk');
const BbPromise = require('bluebird');
class AwsProvider {
request(service, method, params) {
const awsService = new AWS[service]();
const req = awsService[method](params);