Skip to content

Instantly share code, notes, and snippets.

deguchi

Block or report user

Report or block deguchi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View puppeteer smartphone screenshot
const devices = require('puppeteer/DeviceDescriptors');
let fetch = require('node-fetch');
let FormData = require('form-data');
let fs = require('fs');
let opener = require('opener');
it('スマートフォン版のスクリーンショットを撮影', async function () {
this.timeout(20000);
await page.emulate(devices['iPhone 6']);
await page.screenshot({
View closest
function closest(node, selector) {
// IEや一部ブラウザでは.closet()が実装されていないので自前も用意
return (node.closest || function (_selector) {
do {
// nodeとselectorがマッチしたら返す
if ((node.matches || node.msMatchesSelector).call(node, _selector)) {
return node;
}
// マッチしなかったら親要素を代入
View buildQueryString
const buildQueryString = (params) => {
let parts = [];
let add = (key, value) => {
parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
}
for (let key in params) {
let param = params[key];
if (Array.isArray(param)) {
param.map((value) => {
add(key, value);
@deguchi
deguchi / index.html
Last active Nov 22, 2017
QuaggaJS LiveStream(getUserMedia) demo
View index.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=640, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>サービス名</title>
<style>
html, body {
padding: 0;
View getQueryString
function getQueryString() {
var params = {}
location.search.substr(1).split('&').map(function(param) {
var pairs = param.split('=');
params[pairs[0]] = decodeURIComponent(pairs[1]);
});
return params;
}
View wp api custom endpoint
// Register a REST route
add_action( 'rest_api_init', function () {
//Path to meta query route
register_rest_route( 'boardgame/v2', '/fedrated_query/', array(
'methods' => 'GET',
'callback' => 'custom_meta_query'
) );
});
// Do the actual query and return the data
View wordpress functions.php
function my_acf_load_field( $field ) {
if ( ! empty ( $_GET[$field['name']] )) {
$field['default_value'] = $_GET[$field['name']];
}
return $field;
}
add_filter('acf/load_field', 'my_acf_load_field');
remove_filter( 'the_content', 'wpautop' );
View wordpress functions.php
// this will effect all relationship fields
// if you only want to effect specific fields
// see https://www.advancedcustomfields.com/resources/acf-fields-relationship-query/
add_filter('acf/fields/relationship/query', 'relationship_only_own_posts', 10, 3);
function relationship_only_own_posts($args, $field, $post_id) {
// ACFのcourseの値で、表示する前提条件を絞る
$args['meta_key'] = 'course';
$post = get_fields($post_id);
$post_course = $post["course"];
View wordpress functions.php
function my_acf_load_field( $field ) {
if ( ! empty ( $_GET[$field['name']] )) {
$field['default_value'] = $_GET[$field['name']];
}
return $field;
}
add_filter('acf/load_field', 'my_acf_load_field');
remove_filter( 'the_content', 'wpautop' );
View index.py
# -*- coding: utf-8 -*-
import re
import json
import requests
url = 'https://store.nintendo.co.jp/customize.html'
content = requests.get(url).text
if re.search(r'\bSOLD\s+OUT\b', content):
print('Nintendo Switch SOLD OUT.')
You can’t perform that action at this time.