Skip to content

Instantly share code, notes, and snippets.

@takakabe
takakabe / photo.sh
Created September 28, 2017 08:39
ShellScript
#!/bin/bash
raspistill -vf -hf -o /home/pi/raspberry_bot/scripts/wawawa.jpg
curl -F file=@/home/pi/raspberry_bot/scripts/wawawa.jpg -F channels=CHANNELID -F token=xoxb-000000000000-XXXXXXXXXXXXXXXXXXXXXXXX https://slack.com/api/files.upload
@takakabe
takakabe / script.coffee
Last active September 28, 2017 09:20
RaspberryPi
module.exports = (robot) ->
robot.respond /写真/, (msg) ->
@exec = require('child_process').exec
command = "raspistill -vf -hf -o /home/pi/raspberry_bot/scripts/wawawa.jpg;
curl -F file=@/home/pi/raspberry_bot/scripts/wawawa.jpg -F channels=C99999999 -F token=xoxb-9999999999999999-XXXXXXXXXXXXXXXXXXXXXXXX https://slack.com/api/files.upload"
#msg.send "Command: #{command}"
msg.send "しゃしんとってるよ。ちょっとまってね。"
@exec command, (error, stdout, stderr) ->
@msg.send error if error?
#msg.send stdout if stdout?
@takakabe
takakabe / ec2_create
Created October 3, 2017 10:40
CloudFormation
Resources:
Instance:
Type: "AWS::EC2::Instance"
Properties:
AvailabilityZone: "ap-northeast-1a"
ImageId: "ami-4af5022c"
InstanceType: "t2.micro"
KeyName: "キーペア名"
SecurityGroupIds:
- "sg-XXXXXXX"
Resources:
Instance:
Type: "AWS::EC2::Instance"
Properties:
AvailabilityZone: "ap-northeast-1a"
ImageId: "ami-4af5022c"
InstanceType: "t2.micro"
KeyName: "キーペア名"
PrivateIpAddress: "192.140.1.1"
SecurityGroupIds:
@takakabe
takakabe / ec2_public_dns.yaml
Created October 17, 2017 11:15
CloudFormation
Resources:
Instance:
Type: AWS::EC2::Instance
Properties:
AvailabilityZone: ap-northeast-1a
ImageId: ami-XXXXXXXX
InstanceType: t2.micro
KeyName: キーペア名
NetworkInterfaces:
- AssociatePublicIpAddress: "true"
@takakabe
takakabe / iam_create_user.yaml
Created October 28, 2017 15:22
CloudFormation
Resources:
User1:
Type: "AWS::IAM::User"
Properties:
Groups:
- AdministratorGroup
LoginProfile:
Password: wawawa
PasswordResetRequired: True
ManagedPolicyArns:
import json
import boto3
def lambda_handler(event, context):
ec2 = boto3.client("ec2")
response = ec2.describe_instances()
for i in response["Reservations"]:
print("ID: ",i["Instances"][0]["InstanceId"])
print("最終起動時刻: ",i["Instances"][0]["LaunchTime"])
@takakabe
takakabe / address.sh
Last active December 12, 2017 14:49
ShellScript
#!/bin/bash
# IPアドレスを2進数に変換する
# 実行例
# $ ./address.sh 172.24.140.1/26
# Netmask: 11111111 11111111 11111111 11000000
# Address: 10101100 00011000 10001100 00000000
address=${1}
@takakabe
takakabe / cli_knowledge.sh
Last active December 25, 2017 04:43
AWSCLI
#!/bin/bash
instanceid=`echo "${1}"`
output_type=`echo "${2}"`
if [ ${#} -ne 2 ]
then
echo "usage:${0} instanceid [json|table|text]"
exit 1
fi
from datetime import datetime
time_format = '%H%M'
a_time = '1730'
b_time = '1700'
time_diff = datetime.strptime(a_time,time_format) - datetime.strptime(b_time,time_format)
print(time_diff)