s3からphpでファイルをローカルにダウンロード

引き続き、aws sdkを読み込みます。

require_once('vendor/autoload.php');

$s3client = new Aws\S3\S3Client([
	'credentials' => [
		'key' => '',
		'secret' => ''
	],
	'region' => 'ap-northeast-1',
	'version' => 'latest',
]);

$result = $s3client->getObject([
	'Bucket' => 'hoge',
	'Key' => 'article.csv',
	'SaveAs' => 'article.csv',
]);

なに、こんなに簡単なのか。。。。。。
続いて、csvからmysql! gogogo!

letの変数は重複させない

@IBAction func getGoo(_ sender: Any) {
        let results1 = ["Image1","Image2","Image3"]
        let random1 = arc4random_uniform(UInt32(results1.count))

        let image1 = UIImage(named: results1[Int(random1)])
        imageView.image = image1
    }
    

    @IBAction func getChoki(_ sender: Any) {
        let results2 = ["Image1","Image2","Image3"]
        let random2 = arc4random_uniform(UInt32(results2.count))
        
        let image2 = UIImage(named: results2[Int(random2)])
        imageView.image = image2
    }
    
    @IBAction func getPa(_ sender: Any) {
        let results3 = ["Image1","Image2","Image3"]
        let random3 = arc4random_uniform(UInt32(results3.count))
        let image3 = UIImage(named: results3[Int(random3)])
        imageView.image = image3
    }

let result, let randomを3回書くと、うまく表示されません。varだったら行けるのかもしれませんが。

最新の日銀金融政策を中国語で自動表示する

最新バージョンだけなら、難なくいけますね。


$text = $titles[0]."<br><br>";

foreach(glob("file/".$y."/{*.txt}",GLOB_BRACE) as $file){
    if(is_file($file)){
        $files[] = htmlspecialchars($file);
    }
}
// var_dump($files);

	$file = fopen($files[0], "r");
	if($file){
		while ($line = fgets($file)){
			$text .= $line;
		}
	}
	fclose($file);

	

	$key = '';

	$host = "https://api.cognitive.microsofttranslator.com";
	$path = "/translate?api-version=3.0";
	$params = "&to=zh";

	if(!function_exists('com_create_guid')){
		function com_create_guid(){
			return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
			mt_rand(0, 0xffff), mt_rand(0, 0xffff),
			mt_rand(0, 0xffff),
			mt_rand(0, 0x0fff) | 0x4000,
			mt_rand(0, 0x3fff) | 0x8000,
			mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
		}
	}

	function Translate ($host, $path, $key, $params, $content) {
	    $headers = "Content-type: application/json\r\n" .
	        "Content-length: " . strlen($content) . "\r\n" .
	        "Ocp-Apim-Subscription-Key: $key\r\n" .
	        "X-ClientTraceId: " . com_create_guid() . "\r\n";
	    $options = array (
	        'http' => array (
	            'header' => $headers,
	            'method' => 'POST',
	            'content' => $content
	        )
	    );
	    $context  = stream_context_create($options);
	    $result = file_get_contents ($host . $path . $params, false, $context);
	    return $result;
	}

	$requestBody = array (
	    array (
	        'Text' => $text,
	    ),
	);
	$content = json_encode($requestBody);
	$result = Translate($host, $path, $key, $params, $content);

	$json = json_decode($result);
	$newtext =  $json[0]->translations[0]->text;

	echo $newtext; 

ガンガンいきたいところだが、アプリ(android・iOS)のタスクがかなり重いので、translatorはひとまずこれをazureに載せるところまでとしたい。

weather mapのデータをDBに格納する

テーブル名はcakeを使うので、複数形にします。

create table weather.marunouchis(
	id int unsigned auto_increment primary key,
	forecast varchar(255),
	main varchar(255),
	description varchar(255),
	temp float,
	humidity int,
	cloud int,
	speed float,
	created datetime default null
);

PDO::PARAM_INTは、floatやdoubleはないとのこと。指定しないとstrになる。

$now = date("Y-m-d H:i:s");
$i = 0;
foreach($main as $value){
    $stmt->bindParam(':forecast', $time[$i], PDO::PARAM_STR);
    $stmt->bindParam(':main', $value, PDO::PARAM_STR);
    $stmt->bindParam(':description', $description[$i], PDO::PARAM_STR);
    $stmt->bindParam(':temp', $temp[$i], PDO::PARAM_STR);
    $stmt->bindParam(':humidity', $humidity[$i], PDO::PARAM_INT);
    $stmt->bindParam(':cloud', $cloud[$i], PDO::PARAM_INT);
    $stmt->bindParam(':speed', $speed[$i], PDO::PARAM_INT);
    $stmt->bindParam(':created', $now, PDO::PARAM_STR);
    $stmt->execute();
    $i++;
}

入っていますね。

PDOでデータをupdate

まずは”?”を使って更新します。

<?php

$dsn = "mysql:dbname=stock;host=localhost";
$user = "root";
$password = "";
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND=>"SET CHARACTER SET 'utf8'");
try {
	$dbh = new PDO($dsn, $user, $password, $options);
} catch (PDOException $e){
	print('connection failed:'.$e->getMessage());
}

$sql = "select stoph SET 'price' = ? WHERE id = ?";
$stmt = $dbh->prepare($sql);

$stmt->execute(array(430, 2929));
?>

Technical Documentation

OSS, JOB
documentation for you, coworkers, or your users!

README
app, bin, config, db, lib, log, public, test, vendor/assets, gitignore, README, Gemfile, Gemfile.lock

What happens if I don’t choose a license?
It’s super important to choose License.

Choose an open source license
which of the following best describes your situation?
https://choosealicense.com/

-add to README
known bugs
frequently asked questions
table of contents

Readable READMEs with Markdown
-> easily readable

Markdown is a light markup language often used for READMEs. It is fairly straightforward, and much of the syntax is intuitive.

#Here is your task
‘code’
**Here**
_there_

Markdown files should be saved with a .md extension.

<h1>My Fabulous Recipe</h1>
<p>This recipe for <strong>cereal and milk</strong> has been passed down my family for months.</p>
<h2>Ingredients</h2>
<ul>
	<li>Cereal (you can find cool cereals <a href="www.example.com/coolcereals">here</a>)</li>
	<li>Milk</li>
</ul>

<h2>Directions</h2>
<p>If I were writing these out as <em>code</em>, it might look something like this:</p>

<pre><code>if bowl is empty:
	add cereal
	if bowl only has cereal in it:
	add milk
</code></pre>
</body>

Role-Based Access Control(RBAC)

User -> Role -> Rights
– In enterprise setting, access may be based on job function or role of a user
payroll manager, project member etc.
access rights are associated with role
User authenticate themselves to the system
User then can activate one or more role for themselves

RBAC Benefits
Policy need not be updated when certain person with a role leaves the organization
New employee should be able to activate the desired role
Revisiting least privilege
user in one role has access to a subset of the files
switch roles to gain access to other resources

Estimators

Maximum likelihood estimator
laplacian estimator

100101 P(head)=0.5
11011 P(head)=0.4

DATA x1 x2 .. xn
1/n ΣiXi between 0-1

MLE