Skip to content

Instantly share code, notes, and snippets.

View tasugim's full-sized avatar

Takashi Sugimoto tasugim

View GitHub Profile
@tasugim
tasugim / rename_octopress_posts_to_hugo_posts.rb
Created February 11, 2019 08:55
Octopressの記事ファイルをHugoに移行するためにリネームする。
require 'fileutils'
pattern = /\d{4}-\d{2}-\d{2}-(.*)\.markdown/
Dir.glob('./*.markdown').each do |file|
old_name = File.basename(file)
next unless (md = old_name.match(pattern))
new_name = "#{md[1]}.md"
FileUtils.mv(old_name, new_name)
@tasugim
tasugim / edit-octopress-frontmatter-for-hugo.py
Created February 12, 2019 06:52
Octopressの記事のFrontmatterをHugoで使用するために編集する。
import os
import glob
import frontmatter
def create_url(fname):
return 'blog/' + fname.replace('-', '/', 3).replace('.markdown', '')
target_file = "*.markdown"
@tasugim
tasugim / sd201903_1_4_list1.py
Last active March 1, 2019 13:05
『Software Design 2019 年 3 月号』の第1特集「IT エンジニアのための機械学習と微分積分入門」、第4章「微分でつなぐ、機械学習とニューラルネットワーク」のサンプルコードを写経したスクリプトです。
import torch
from torch import nn, optim
from torch.utils.data import TensorDataset, DataLoader
from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_absolute_error
# データ読み込み、訓練データ/テストデータの分割
housing = fetch_california_housing()
@tasugim
tasugim / update-frontmatter-categories.py
Created July 7, 2019 04:55
Frontmatterのカテゴリーをフラットな文字列から配列に置き換える。
import os
import glob
import frontmatter
target_file = "*.markdown"
new_dir = "new/"
os.makedirs(new_dir, exist_ok=True)
for fname in glob.glob(target_file):
{
"Resources" : {
"HelloBucket" : {
"Type" : "AWS::S3::Bucket",
"Properties" : {
"AccessControl" : "PublicRead",
"WebsiteConfiguration" : {
"IndexDocument" : "index.html",
"ErrorDocument" : "error.html"
}
Resources:
HelloBucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: PublicRead
WebsiteConfiguration:
IndexDocument: index.html
ErrorDocument: error.html
{
"Parameters": {
"KeyName": {
"Description": "The EC2 Key Pair to allow SSH",
"Type": "AWS::EC2::KeyPair::KeyName"
}
},
"Resources": {
"Ec2Instance": {
"Type": "AWS::EC2::Instance",
Parameters:
KeyName:
Description: The EC2 Pair to allow SSH access
Type: 'AWS::EC2::KeyPair::KeyName'
Resources:
Ec2Instance:
Type: 'AWS::EC2::Instance'
Properties:
SecurityGroups:
- !Ref InstanceSecurityGroup
{
"Resources": {
"myBucket": {
"Type": "AWS::S3::Bucket"
},
"myDistribution": {
"Type": "AWS::CloudFront::Distribution",
"Properties": {
"origins": [
{
Resources:
myBucket:
Type: 'AWS::S3::Bucket'
myDistribution:
Type: 'AWS::CloudFront::Distribution'
Properties:
Origins:
- DomainName: !GetAtt
- myBucket
- DomainName