Skip to content

Instantly share code, notes, and snippets.

View DriftwoodJP's full-sized avatar

DriftwoodJP DriftwoodJP

View GitHub Profile
@DriftwoodJP
DriftwoodJP / adding-markers-to-google-map-using-local-json-file_index.html
Last active November 20, 2020 17:14
Adding markers to a Google Map using a local JSON file.
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<style>
</style>
</head>
<body>
@DriftwoodJP
DriftwoodJP / content-archive.php
Last active May 28, 2019 08:25
How to link the WordPress title & thumbnail to an external URL.
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail();
else :
print_post_no_image_thumbnail();
endif;
?>
@DriftwoodJP
DriftwoodJP / setup_wp.sh
Last active August 1, 2018 09:32
To set options in WordPress
#!/bin/bash
wp option update siteurl 'https://stg.example.com/wordpress'
wp option update home 'https://stg.example.com/wordpress'
wp option update blogname 'foo'
wp option update blogdescription ''
wp option update timezone_string 'Asia/Tokyo'
wp option update date_format 'Y/m/d'
wp option update time_format 'H:i'
wp option update permalink_structure '/blog/%year%/%monthnum%/%day%_%post_id%.html'
@DriftwoodJP
DriftwoodJP / init_wp.sh
Created July 30, 2018 09:00
To delete all terms, posts & comments in WordPress
#!/bin/bash
# Delete all categories.
wp term list category --field=term_id | xargs wp term delete category
# Delete all post tags.
wp term list post_tag --field=term_id | xargs wp term delete post_tag
# Delete all posts.
wp post delete --force $(wp post list --format=ids)
@DriftwoodJP
DriftwoodJP / install_wp-cli.sh
Last active August 1, 2018 06:11
To install the WP-CLI & Composer
#!/bin/bash
cd $HOME
mkdir local/bin local/tmp
cd ~/local/tmp
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mv wp-cli.phar ~/local/bin/wp
@DriftwoodJP
DriftwoodJP / lesson7.rb
Created December 27, 2017 09:00
「アジャイル時代のオブジェクト脳のつくり方 Rubyで学ぶ究極の基礎講座」の7章のソースコード。
# rubocop:disable AsciiComments, EmptyLines, LineLength, Semicolon, VariableNumber, Lambda, Proc, RedundantBlockCall, ShadowingOuterLocalVariable, ShadowedArgument
#
# 「アジャイル時代のオブジェクト脳のつくり方 Rubyで学ぶ究極の基礎講座」の7章のソースコード。
#
#
@DriftwoodJP
DriftwoodJP / gist:9b6d868f70f24f514231969c6541ef13
Created December 4, 2017 07:49 — forked from torounit/gist:5106240
Wordpressで指定したカテゴリーの年別アーカイブを作成する | webOpixel http://www.webopixel.net/wordpress/236.html の改造版。プラグイン有効時にflush_rules()か、パーマリンク設定の更新が必要。
<?php
function extend_date_archives_add_rewrite_rules() {
add_rewrite_rule( 'category/([^/]+)/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$', 'index.php?category_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&day=$matches[4]&feed=$matches[4]', 'top' );
add_rewrite_rule( 'category/([^/]+)/date/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$', 'index.php?category_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]&day=$matches[4]', 'top' );
add_rewrite_rule( 'category/([^/]+)/date/([0-9]{4})/([0-9]{1,2})/?$', 'index.php?category_name=$matches[1]&year=$matches[2]&monthnum=$matches[3]', 'top' );
add_rewrite_rule( 'category/([^/]+)/date/([0-9]{4})/?$', 'index.php?category_name=$matches[1]&year=$matches[2]', 'top' );
}
add_action('wp_loaded', 'extend_date_archives_add_rewrite_rules');
@DriftwoodJP
DriftwoodJP / verify_mode.rb
Created July 19, 2017 02:18
Using Net::HTTP to the HTTPS url
require 'openssl'
require 'net/http'
https = Net::HTTP.new('www.google.co.jp', 443) # address, port
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
# https.verify_mode = OpenSSL::SSL::VERIFY_PEER
# https.ca_file = '/etc/ssl/cert.pem'
https.start do
response = https.get('/') # path
@DriftwoodJP
DriftwoodJP / class-scc-share-pocket-strategy.php
Created December 13, 2016 10:49
SNS Count Cache 0.10.0 Pocket 仕様変更対応版
<?php
/*
class-scc-share-pocket-strategy.php
Description: This class is abstract class of a data crawler
Author: Daisuke Maruyama
Author URI: http://marubon.info/
License: GPL2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
@DriftwoodJP
DriftwoodJP / webStorage.js
Created November 2, 2016 07:15
a Web Storage example.
'use strict';
const MyStorage = function(app) {
this.app = app;
this.storage = localStorage;
this.data = JSON.parse(this.storage[this.app] || '{}');
};
MyStorage.prototype = {
getItem: function(key) {