This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::io::prelude::*; | |
use std::net::TcpListener; | |
// サーバアドレスを指定 | |
const SERVER_ADDRESS: &str = "127.0.0.1:8888"; | |
fn main() { | |
// HTTPサーバを起動 | |
println!("[HTTPサーバを起動] http://{}", SERVER_ADDRESS); | |
let listener = TcpListener::bind(SERVER_ADDRESS).unwrap(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// k近傍法(k-nn)によるアヤメの分類プログラム | |
use rand::seq::SliceRandom; | |
// データとラベルを持つ構造体を定義 --- (*1) | |
#[derive(Debug, Clone)] | |
struct KnnItem { | |
data: Vec<f64>, | |
label: String, | |
} | |
// k近傍法でデータを予測する --- (*2) | |
fn knn_predict(items: &[KnnItem], test: &[f64], k: usize) -> String { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sepal_length | sepal_width | petal_length | petal_width | class | |
---|---|---|---|---|---|
5.1 | 3.5 | 1.4 | 0.2 | Iris-setosa | |
4.9 | 3.0 | 1.4 | 0.2 | Iris-setosa | |
4.7 | 3.2 | 1.3 | 0.2 | Iris-setosa | |
4.6 | 3.1 | 1.5 | 0.2 | Iris-setosa | |
5.0 | 3.6 | 1.4 | 0.2 | Iris-setosa | |
5.4 | 3.9 | 1.7 | 0.4 | Iris-setosa | |
4.6 | 3.4 | 1.4 | 0.3 | Iris-setosa | |
5.0 | 3.4 | 1.5 | 0.2 | Iris-setosa | |
4.4 | 2.9 | 1.4 | 0.2 | Iris-setosa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ライブラリを読み込む --- (*1) | |
const express = require('express'); | |
const OpenAI = require('openai') | |
const path = require('path') | |
// APIキーを設定する(以下は書き換えが必要です★★★) --- (*2) | |
const API_KEY = 'xxx' | |
// const API_KEY = process.env['OPENAI_API_KEY'] | |
// APIキーを設定したオブジェクトを生成 | |
const openai = new OpenAI({ apiKey: API_KEY }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
from pygame.locals import * | |
import sys, random | |
# 変数の初期化 | |
maze_w = 31 # 迷路の列数 | |
maze_h = 23 # 迷路の行数 | |
maze = [] # 迷路データ | |
tile_w = 16 | |
px = 1 # プレイヤーの座標 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CRC-32のためのキャッシュテーブルを作成する関数 --- (*1) | |
fn crc32_table() -> [u32; 256] { | |
// テーブルを0で初期化 | |
let mut table: [u32; 256] = [0; 256]; | |
let crc32poly:u32 = 0xEDB88320; | |
// 0-255の各値について繰り返し計算を行う --- (*2) | |
for i in 0..256 { | |
let mut crc:u32 = i as u32; // 値を初期化 | |
// 8回(8ビット分)繰り返す --- (*4) | |
for _ in 0..8 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// CRC-32を計算する関数 | |
fn crc32(bin_data: &[u8]) -> u32 { | |
let crc32poly:u32 = 0xEDB88320; | |
// CRC-32の初期値 --- (*1) | |
let mut crc:u32 = 0xFFFFFFFF; | |
// バイト列の各バイトについて繰り返し計算を行う --- (*2) | |
for byte in bin_data { | |
// XORを行う --- (*3) | |
crc ^= *byte as u32; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import datetime | |
from googleapiclient.discovery import build | |
from google.auth import load_credentials_from_file | |
# クレデンシャルファイルのパスを指定 --- (*1) | |
CREDENTIALS_PATH = 'credentials.json' | |
# カレンダーIDを指定 --- (*2) | |
CALENDAR_ID = '28e4bb3f327eb238d29a282e9935fc957c40bb3e63ae831b9ecc935bee67efed@group.calendar.google.com' | |
# スコープの指定 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import smtplib | |
from email.mime.text import MIMEText | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.application import MIMEApplication | |
from email import encoders | |
from googleapiclient.discovery import build | |
from google.auth import load_credentials_from_file | |
# クレデンシャルファイルのパスを指定 --- (*1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# メインウィンドウの初期化 --- (*1) | |
wm title . "FizzBuzz" | |
wm geometry . 600x400 | |
# fizzbuzz関数を定義 --- (*2) | |
proc fizzbuzz { n } { | |
# 変数$nがFizzかBuzzかを判定 --- (*2) | |
set is_fizz [expr {($n % 3) == 0}] | |
set is_buzz [expr {($n % 5) == 0}] | |
# 判定結果に応じて結果を返す --- (*3) |
NewerOlder