自動化無しに生活無し

WEB開発関係を中心に備忘録をまとめています

  • FFmpegを使ってUbuntuサーバーにUSBで接続されたウェブカメラで映像を録画する

    Ubuntu 22.04 Server ハードはラズパイ3B+ インストール FFmpegとv4l2-utilsをインストール sudo apt install ffmpeg v4l-utils デバイスを特定する v4l2-ctl --list-devices こんなふうに表示される(一部省略) BUFFALO BSWHD06M USB Camera : (usb-3f980000.usb-1.4): /dev/video0 /dev/video1 /dev/media3 対応しているフォーマットと解像度を特定する ffmpeg -f v4l2 -list_formats all -i /dev/video0 こんなふうに表示される(一部省略) [video4linux2,v4l2 @ 0xaaaad7c25420] Raw : yuyv422 : YUYV 4:2:2 : 1280x720 800x600 640x480 640x360 352x288 320x240 176x144 160x120 [video4linux2,v4l2 @ 0xaaaad7c25420] Compressed: mjpeg : Motion-JPEG : 1280x960 1280x720 800x600 640x480 640x360 352x288 320x240 176x144 160x120 映像を録画する ffmpeg -f v4l2 -framerate 30 -video_size 352x288 -i /dev/video0 output.mkv 後はこの映像をscpなどでDLして ...
  • 【Ubuntu】netplanに無線LAN(wifi)で固定IPアドレスを割り当てる

    有線であれば以下のように書く。 network: ethernets: eth0: dhcp4: false addresses: - 192.168.11.246/24 routes: - to: default via: 192.168.11.1 nameservers: addresses: - 192.168.11.1 version: 2 無線LANの場合、ip addrで表示される無線LANのデバイス名を控えた上で下記のように記す network: wifis: wlan0: dhcp4: false addresses: - 192.168.11.246/24 routes: - to: default via: 192.168.11.1 nameservers: addresses: - 192.168.11.1 access-points: "SSIDname": password: "password" version: 2 ...
  • nanoエディタの操作方法

    急にnanoエディタが立ち上がり、ふだんvimを使っている身としては、調べながら終了させるのは手間になる。 Ctrl+Xで終了できる 保存するかどうか聞かれるので、nを押して保存せずに終了する。 保存する時は、yを押してEnterキーを推せば保存して終了できる。 nanoエディタはWindowsのメモ帳とほぼ同様に扱うことができ、管理者権限が必要なファイルの編集もできる。 vimが使いづらいなと思う場合にお ...
  • 【CSS3】チャットのウェブデザインを作る

    HTML <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Hello World test!!</title> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <link rel="stylesheet" href="style.css"> </head> <body> <main class="container"> <div class="mine_speech_bubble_area"> <div class="speech_bubble"></div> </div> <div class="others_speech_bubble_area"> <div class="speech_bubble"></div> </div> </main> </body> </html> Django用のHTML {% for topic in topics %} <div class="{% if topic.user.id == request.user.id %}mine{% else %}others{% endif %}_speech_bubble_area"> <div class="speech_bubble">{{ topic.comment|linebreaksbr }}</div> </div> {% endfor %} CSS .mine_speech_bubble_area{ text-align:right; } .others_speech_bubble_area{ text-align:left; } .mine_speech_bubble_area .speech_bubble { /* 自分が送った時は右下の角をつける */ background:lime; border-bottom-right-radius:0; } .others_speech_bubble_area .speech_bubble { /* 相手が送った時は左上の角をつける */ background:silver; border-top-left-radius:0; } .speech_bubble{ text-align:left; word-break:break-all; display:inline-block; max-width:80%; padding:0.5rem; margin:0.5rem 0; border-radius:1rem; } 動かすとこうなる。 ...
  • Ubuntuに環境変数をセットし、Pythonでosモジュールを使って読む方法【os.environ使用、crontabにも対応】

    例えば、gitで管理しているプロジェクトをgitでデプロイする時。 たとえローカルサーバーのDBのパスワードとは言え、ハードコードした状態でコミットするわけには行かない。(gitignoreに入れてしまうとパスワードが含まれない) そこで、環境変数をセットし、Python側でそれを読む。 環境変数をセットする。 #変数名=値 ZZZ=test #変数を環境変数としてセットする。 export ZZZ #↑2つは下記でも可 export ZZZ=test セットした環境変数 ...
  • PHPでmb_strlenもしくはstrlenがNotFoundのときの対策

    mb_strlen()もしくはstrlen()がNotFoundになるときは、下記コマンドを実行してphp-mbstringをインストールする #PHPのバージョンは合わせる sudo apt install php8.1-mbstring ちなみに、strlen()はバイト数、mb_strlen()は文字列の長さ(マルチバイト文字を1文字とみなす)を返す。 ...
  • 【VanillaJS】Djangoで素のJavaScriptのXMLHttpRequest(Ajax)を使ってリクエストを送信【jQuery不使用】

    POSTメソッドを送信する 前項で取得したCSRFトークンをリクエストヘッダにセットして送信する。 window.addEventListener("load" , () => { const submit = document.querySelector("#submit"); submit.addEventListener( "click", () => { send(); }); }); const send = () => { const form_elem = "#form_area"; const form = document.querySelector(form_elem); const data = new FormData( form ); const url = form.getAttribute("action"); const method = form.getAttribute("method"); // formタグ内のデータを確認。 for (let v of data ){ console.log(v); } const request = new XMLHttpRequest(); //送信先とメソッドの指定 request.open(method,url); // formタグ内にcsrf_tokenが含まれているため不要。 //console.log(csrftoken); //request.setRequestHeader("X-CSRFToken", csrftoken); //送信(内容) request.send(data); //成功時の処理 request.onreadystatechange = () => { if( request.readyState === 4 && request.status === ...
  • WindowsでPythonをインストールする

    Pythonのインストール Pythonのインストーラーを配布しているサイト( https://www.python.org/downloads/ )へ行く。 Download Python 3.10.6 の部分をクリックする。インストーラーがDLされる。 ( ※下記画像の赤枠部分。3.10.6は2022年9月現在のバージョンであり、今後バージョンが更新される。最新版のPythonインストーラーをDLする。 ) ダウンロードフォルダにて、先ほどDLしたインストーラーのファイルがあるので、ダブルクリックしてPytho ...
  • composerでLaravel9.xプロジェクトが作れない問題に対処する【php8.1】

    ある日、composerコマンドを実行してLaravelプロジェクトを作ろうにも、エラーが出て作れない。 composer create-project --prefer-dist laravel/laravel testlaraveler1 を実行すると下記が得られる。 Creating a "laravel/laravel" project at "./testlaraveler1" Info from https://repo.packagist.org: #StandWithUkraine Installing laravel/laravel (v9.3.5) - Downloading laravel/laravel (v9.3.5) - Installing laravel/laravel (v9.3.5): Extracting archive Created project in /home/akagi/Documents/programming/php/laravel_test03/testlaraveler1 > @php -r "file_exists('.env') || copy('.env.example', '.env');" Loading composer repositories with package information Updating dependencies Your requirements could not be resolved to an installable set of packages. Problem 1 - spatie/laravel-ignition[1.0.0, ..., 1.4.0] require ext-curl * -> it is missing from your system. Install or enable PHP's curl extension. - Root composer.json requires spatie/laravel-ignition ^1.0 -> satisfiable by spatie/laravel-ignition[1.0.0, ..., 1.4.0]. To enable extensions, verify that they are enabled in your .ini files: - /etc/php/8.1/cli/php.ini - /etc/php/8.1/cli/conf.d/10-opcache.ini - /etc/php/8.1/cli/conf.d/10-pdo.ini - /etc/php/8.1/cli/conf.d/15-xml.ini - /etc/php/8.1/cli/conf.d/20-calendar.ini - /etc/php/8.1/cli/conf.d/20-ctype.ini - /etc/php/8.1/cli/conf.d/20-dom.ini - /etc/php/8.1/cli/conf.d/20-exif.ini - /etc/php/8.1/cli/conf.d/20-ffi.ini - /etc/php/8.1/cli/conf.d/20-fileinfo.ini - /etc/php/8.1/cli/conf.d/20-ftp.ini - /etc/php/8.1/cli/conf.d/20-gettext.ini - /etc/php/8.1/cli/conf.d/20-iconv.ini - /etc/php/8.1/cli/conf.d/20-phar.ini - ...