Skip to content

Instantly share code, notes, and snippets.

View takunagai's full-sized avatar

nagataku takunagai

View GitHub Profile
@takunagai
takunagai / utils.ts
Created November 19, 2023 22:41
[Returns a random integer]ランダムな整数を返す #utility
/**
* ランダムな整数を返す
* @param min 最小値
* @param max 最大値
* @returns min 以上 max 以下のランダムな整数
*/
export function getRandomInt(min: number, max: number): number {
return Math.floor(Math.random() * (max - min + 1)) + min
}
@takunagai
takunagai / index.js
Last active October 31, 2023 11:41
[Copy selected text to clipboard] 選択したテキストをクリップボードにコピー #JavaScript
async function copyUrlToClipboard(text) {
try {
await navigator.clipboard.writeText(text);
console.info('Successfully copied URL');
} catch (err) {
console.log(err)
return { error: err }
}
return { success: true }
@takunagai
takunagai / functions.php
Last active September 5, 2023 19:44
[WordPress: Data Serialization and Database I/O] WordPress データのシリアル化とデータベースへの入出力 #WordPress
<?php
/**
* WordPress データのシリアル化とデータベースへの入出力
* @ref: https://wporz.com/wordpress-serialize/
*/
/**
* 複数のデータを配列にセットしシリアル化、wp_options テーブルに保存
*/
$update[] = $data1;
@takunagai
takunagai / index.html
Created July 11, 2023 10:11
[pollyfil: Bootstrap v5 for IE11] #Bootstrap #old
<{* IE11 対応 for Bootstrap 5 (polyfill.io を使用)
* Fix preventDefault for IE
* @ref { @link https://polyfill.io/v3/ }
* リクエストの User-Agent ヘッダーを読み、要求元のブラウザに適した polyfills を返す
* このため、モダンブラウザでアクセスしてもコードは表示されない
* https://polyfill.io/v3/polyfill.min.js?features=es5 でもいける? *}>
<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js"></script>
<script>
(function() {
const workingDefaultPrevented = (function() {
@takunagai
takunagai / CardShineEffect.jsx
Created July 2, 2023 23:32
[Creating a shine effect on a card with Tailwind CSS] Card に輝きの効果をつける #react #tailwind #css
/*
Creating a shine effect on a card with Tailwind CSS
https://www.julienthibeaut.xyz/blog/create-shine-effect-on-card-with-tailwind-css?utm_campaign=tailwind-weekly-121&utm_source=Tailwind+Weekly
*/
export const CardShineEffect = () => {
return (
<div className="bg-[linear-gradient(45deg,transparent_25%,rgba(68,68,68,.2)_50%,transparent_75%,transparent_100%)] bg-zinc-950 relative max-w-md overflow-hidden rounded-xl border border-slate-900 bg-[length:250%_250%,100%_100%] bg-[position:-100%_0,0_0] bg-no-repeat px-8 py-16 shadow-2xl transition-[background-position_0s_ease] hover:bg-[position:200%_0,0_0] hover:duration-[1500ms]">
<span className="mb-4 inline-flex items-center justify-center rounded-md bg-blue-600 p-2 shadow-lg">
<svg
className="h-6 w-6 text-white"
@takunagai
takunagai / functions.php
Created May 1, 2023 07:42
[Short Code Output] #WordPress
<?php
/*-------------------------------------------
* Businesscalendar Plugin のウィジェットを
* ショートコードで使えるように
* 表示させたい箇所に `[widget_shortcode]`
* http://www.is-p.cc/wordpress/plug-in/business-calendar/700
* ----------------------------------------- */
add_shortcode( 'businesscalendar_shortcode', 'add_businesscalendar_shortcode' );
function add_businesscalendar_shortcode() {
ob_start();
@takunagai
takunagai / sample.sql
Created February 25, 2023 00:03
[WordPress Sample SQL Queries] #WordPress #sql
# WordPress 記事タイトル/アイキャッチ画像のID を表示
select
a.id 'ID',
a.post_title 'タイトル',
c.guid 'アイキャッチ URL'
from
(select * from wpgh_posts
where post_type in ('post','page','lesson')
and post_status='publish') a
left outer join wpgh_postmeta b
@takunagai
takunagai / functions.php
Last active November 11, 2022 09:03
[mega menu support for menu-4 & menu-5] #WordPress
<?php
/**
* Support menu-4, menu-5 on MegaMenu.
* Default: Only Support primary, secondary, menu-3 menus
*/
add_filter( 'astra_nav_mega_menu_support', 'custom_megamenu_support', 10, 1 );
function custom_megamenu_support( $nav_menus ) {
$nav_menus[] = 'menu_3';
$nav_menus[] = 'menu_4';
return $nav_menus;
@takunagai
takunagai / functions.php
Created October 5, 2022 03:07
[Spectra - Disable the Block display conditions for Page post type] 指定投稿タイプなら Block Conditon を無効に #WordPress #spectra
<?php
/**
* Spectra - Disable the Block display conditions for Page post type.
* @ref https://wpspectra.com/docs/display-conditions-blocks/
*/
add_filter( 'enable_block_condition', function( $default = true) {
if (isset($_REQUEST['post_type']) && 'page' === $_REQUEST['post_type']) {
return false;
} elseif (isset($_GET['post']) && 'page' === get_post_type($_GET['post'])) {
return false;
@takunagai
takunagai / functions.php
Last active December 12, 2022 07:29
[WIdget - Dashboard - Support Widget (Fetch from RSS)] #WordPress
<?php
/**
* サポートウィジェット
* サポート用外部サイトのRSSを取得し表示
*/
function astra_child_custom_dashboard_support() {
?>
<p>
<a href="#">» Webページで見る</a>
<a href="https://sitename.com/form-support" target="_blank">» お問合せ</a>