Skip to content

Instantly share code, notes, and snippets.

View ogaty's full-sized avatar

Yuji Ogata ogaty

View GitHub Profile
@ogaty
ogaty / Postman-pre-request-script-csrf-token-laravel-sanctum.js
Created May 31, 2024 02:16 — forked from janzikmund/Postman-pre-request-script-csrf-token-laravel-sanctum.js
Postman Pre-Request script to append CSRF token in header for POST requests in Laravel Sanctum authenticated SPA. Requires active environment with {{url}} variable defined for main app domain.
/**
* Postman Pre-Request script to append CSRF token in header for POST requests in Laravel
* Sanctum authenticated SPA. Requires active environment with {{url}} variable defined
* for main app domain.
*
* Postman Interceptor allows appending cookies from browser, but Laravel CSRF middleware
* only validates CSRF in headers or in _token form field, not in cookies. Axios automatically
* appends the CSRF from cookie to headers, but Postman cannot access intercepted cookies
* and use them, so we have to do one pre-request to get the CSRF token, store it
* in environment so it can be reused, and then append it to headers.
<?php
$args = array(
// ↓ 特定の「著者」に関連付けられた投稿を表示する場合
'author' => '1,2,3', // 著者IDを指定
'author_name' => 'solecolor', // user_nicknameを指定(名前ではありません)
'author__in' => array( 2 , 6 ), // 著者IDを配列で指定(著者IDを含む記事を絞り込む)
'author__not_in' => array( 2 , 6 ), // 著者IDを配列で指定(著者IDを含まない記事を絞り込む)
// ↓ 特定の「カテゴリー」に関連付けられた投稿を表示する場合
'cat' => 5, // カテゴリーIDを指定
@ogaty
ogaty / show-all-256-colors.py
Created August 6, 2018 10:37 — forked from mgedmin/show-all-256-colors.py
Script to show all 256 colors supported by xterms
#!/usr/bin/python
"""Print a swatch using all 256 colors of 256-color-capable terminals."""
__author__ = "Marius Gedminas <marius@gedmin.as>"
__url__ = "https://gist.github.com/mgedmin/2762225"
__version__ = '2.0'
def hrun(start, width, padding=0):