[MovableType]数値切り上げ

<mt:Var name="target" regex_replace="/^\-?\d+\.(\d*)$/","$1" setvar="_one_tenth">
<mt:Var name="target" regex_replace="/^(\d+)\.\d+$/","$1" setvar="_result">
<mt:If name="_one_tenth" ne="$target">
    <mt:If name="_one_tenth" gt="0">
        <mt:SetVar name="_result" op="+" value="1">
    </mt:If>
</mt:If>

[JavaScript]getRGBAByHex

getRGBAByHex(hex,alpha){
    if (hex.slice(0,1) == "#")hex = hex.slice(1) ;
    if (hex.length == 3)hex = hex.slice(0,1) + hex.slice(0,1) + hex.slice(1,2) + hex.slice(1,2) + hex.slice(2,3) + hex.slice(2,3);
    let rgb = [hex.slice(0,2),hex.slice(2,4),hex.slice(4,6)].map(function(str){
        return parseInt(str,16);
    });
    return `rgba(${rgb[0]},${rgb[1]},${rgb[2]},${alpha})`;
}

[JavaScript]canvas.clip

animate() {
    requestAnimationFrame(()=>{
        this.animate();
    });
    const ctx;
    ctx = canvas.getContext('2d');
    ctx.globalCompositeOperation = "source-over";
    ctx.globalAlpha = 1.0;
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.save();
    ctx.beginPath();
    ctx.rect(0,0,canvas.width,100);
    ctx.clip();
    //ここに描画処理
    ctx.restore();
}

[React]koa-router備忘録

const Router = require('koa-router');
const router = new Router();
router.get('/', async (ctx, next) => {
    if(エラー条件){
        ctx.status = 400;//500
        return;
    }
    await ctx.render('index', {});
});

[JavaScript]スクロール無効化

window.addEventListener('touchmove', (e)=>{this.cancelScroll(e);}, { passive: false });
window.addEventListener('mousewheel', (e)=>{this.cancelScroll(e);}, { passive: false });

cancelScroll(e) {
    e.preventDefault();
}

[React]State

import { useState } from "react"
export const App = () => {
    const [num, setNum] = useState(0);
    const onClickButton = () => {
        setNum(num + 1);
    };
    return (
        <>
        <button onClick={onClickButton}>Button</button>
        <p>{num}</p>
        </>
    );
};

[Laravel Sail]migrate

モデル作成

sail artisan make:model Post -m

 
マイグレーションファイルのupを下記へ

public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
       $table->id();
       $table->string('title');
       $table->text('body');
       $table->timestamps();
});
}

 

マイグレーション

sail artisan migrate

 

カラム追加のマイグレーションファイル作成

sail artisan make:migration add_test_column --table=users

 

中身

public function up(): void
{
    Schema::table('users', function (Blueprint $table) {
        $table->string('test')->after('email');
    });
}
public function down(): void
{
    Schema::table('users', function (Blueprint $table) {
        $table->dropColumn('test');
    });
}

 

カラム削除のマイグレーションファイル作成

sail artisan make:migration delete_test_column --table=users

 

中身

public function up(): void
{
    Schema::table('users', function (Blueprint $table) {
        $table->dropColumn('test');
    });
}
public function down(): void
{
    Schema::table('users', function (Blueprint $table) {
        $table->string('test')->after('email');
    });
}

 

ロールバック

sail artisan migrate:rollback

[EloquentORM]備忘録#1

PostController

$posts = Post::with('user')->where('user_id',auth()->id())->orderBy('created_at','desc')->get();

 
Models/Userに下記追記

public function posts(){
    return $this->hasMany(Post::class);
}

 
Models/Postに下記追記

public function user(){
    return $this->belongsTo(User::class);
}

[Git][SourceTree]fatal: unsafe repository

「fatal: unsafe repository」が出たら

エラー文にあるように下記を実行することで解消する。

git config --global --add safe.directory '%(prefix)///wsl.localhost/Ubuntu/home/jack/test-project'

  
確認

git config --list

  
削除

git config --global --unset-all safe.directory

[PHP]idiorm #7 raw_execute + AES_ENCRYPT

define('DB_ENCRYPT_KEY','aabbccddeeff');
require_once __DIR__ . '/idiorm.php';
ORM::configure('mysql:host=localhost;dbname=xxxx');
ORM::configure('username', 'yyy');
ORM::configure('password', 'zzz');
ORM::configure('driver_options', [
    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8',
]);

$query = "INSERT INTO {$table_name}(`e_id`,`description`) VALUES(:e_id,AES_ENCRYPT(:description,'xxyyzz'))";
result = ORM::for_table('users')->raw_execute($query,['e_id'=>1,'description'=>'あいうえお']);

$query = "UPDATE {$table_name} SET `description`=AES_ENCRYPT(:description,'xxyyzz') WHERE `e_id` = :e_id";
result = ORM::for_table('users')->raw_execute($query,['e_id'=>1,'description'=>'あいうえお']);