Skip to content

Instantly share code, notes, and snippets.

@ginlime
ginlime / cdate_compare_plugins.js
Last active May 24, 2023 01:37
日時操作 JavaScript ライブラリ「cdate」に比較系のメソッドを追加するプラグイン
// comare で target を入れてないのは簡易にやりたいだけなので、改変はご自由に
const cdateP = cdate().plugin(P => class extends P {
compare(target) {
const base = new Date(this.t);
const subject = new Date(target);
if(!base.getHours() && !base.getMinutes() && !base.getSeconds() && !base.getMilliseconds()){
// 日付での比較と判断
subject.setHours(0);
subject.setMinutes(0);
subject.setSeconds(0);
@ginlime
ginlime / validityHasBadInput.js
Created June 10, 2020 09:19
IE の ValidityState に badInput がないので、とりあえず識別する
// IE でも使う想定だから ES じゃないのは勘弁な!
// ValidityState に badInput があるか判定
// hasOwnProperty 適用できないんスよ……
var validityStateCheck = (function(){
var validityStateHasBadInput = false,
isValidityStateChecked = false;
return {
hasBadInput: function(validity){
if(isValidityStateChecked){
@ginlime
ginlime / qrcode
Created October 28, 2019 22:22
表示中のサイトで QR コードを表示するブックマークレット
javascript:(()=%3E%7Bconst%20w=window,d=document;new%20Promise(resolve=%3E%7Blet%20i=setInterval(()=%3E%7Bif(w%5B'jQuery'%5D!=undefined)%7BclearInterval(i);console.log('jQuery%20ready!');resolve();%7D%7D,100);if(w%5B'jQuery'%5D===undefined)%7Bs=d.createElement('script');s.src='//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js';d.body.appendChild(s);%7D%7D).then(()=%3E%7Breturn%20Promise.all(%5Bnew%20Promise(resolve=%3E%7Blet%20i=setInterval(()=%3E%7Bif(w%5B'jQuery'%5D.fn.modal!=undefined)%7BclearInterval(i);console.log('modal%20ready!');resolve();%7D%7D,100);if(w%5B'jQuery'%5D.fn.modal===undefined)%7Blet%20l=d.createElement('link'),s=d.createElement('script');l.rel='stylesheet';l.href='//cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.2/jquery.modal.css';s.src='//cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.2/jquery.modal.min.js';d.body.appendChild(l);d.body.appendChild(s);%7D%7D),new%20Promise(resolve=%3E%7Blet%20i=setInterval(()=%3E%7Bif(w%5B'jQuery'%5D.fn.qrcode!=undefined)%7BclearInterval(i);cons
@ginlime
ginlime / vbac.wsf
Last active April 2, 2018 06:23
vbac.wsf で出力されるコードが Shift_JIS で エディタによっては面倒なので、nkf で UTF-8 に変換するようにしてみた(要 nkf)
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<package>
<comment>
The vbac is not VBA compiler.
Instead, this unsophisticated script frees VBA code from binary files.
This script is distributed as part of the Ariawase library.
The Project Page: https://github.com/vbaidiot/Ariawase
Modified by: twitter:@ginlime
@ginlime
ginlime / shorten.php
Created March 15, 2018 06:34
YOURLS の API を JavaScript から使う時に、API の ID/PW を隠すために噛ませる PHP
<?php
/*
パラメータ(両方とも必須にしている):
shorturl:短縮したい URL
title:yourls の画面に表示するタイトル
*/
$host = $_SERVER['HTTP_REFERER'];
$str = parse_url($host);
@ginlime
ginlime / kansuji2arabic.js
Last active January 17, 2018 09:11
JavaScript で漢数字からアラビア数字に変換
// https://qiita.com/dosec/items/c6aef40fae6977fd89ab
// から移植+α
// とりあえず
// (文字列).kansuji2arabic(split3)
// で動作
(function(){
// 改良版 typeOf(のさらに改良)
// http://qiita.com/Hiraku/items/87e5d1cdaaa475c80cc2
var typeOf = function(x) {
@ginlime
ginlime / spritesmith_template_scss.txt
Created December 21, 2017 07:36
SCSS template for spritesmith with Retina/responsive support / spritesmith 用 Retina/レスポンシブ対応 SCSS テンプレート
{{#block "sprites"}}
{{#each sprites}}
${{strings.name_name}}: '{{name}}';
${{strings.name_x}}: {{px.x}};
${{strings.name_y}}: {{px.y}};
${{strings.name_offset_x}}: {{px.offset_x}};
${{strings.name_offset_y}}: {{px.offset_y}};
${{strings.name_width}}: {{px.width}};
${{strings.name_height}}: {{px.height}};
${{strings.name_total_width}}: {{px.total_width}};
@ginlime
ginlime / spritesmith_template_less.txt
Created December 21, 2017 07:35
LESS template for spritesmith with Retina/responsive support / spritesmith 用 Retina/レスポンシブ対応 LESS テンプレート
{{#block "sprites"}}
{{#each sprites}}
@{{strings.name_name}}: '{{name}}';
@{{strings.name_x}}: {{px.x}};
@{{strings.name_y}}: {{px.y}};
@{{strings.name_offset_x}}: {{px.offset_x}};
@{{strings.name_offset_y}}: {{px.offset_y}};
@{{strings.name_width}}: {{px.width}};
@{{strings.name_height}}: {{px.height}};
@{{strings.name_total_width}}: {{px.total_width}};
@ginlime
ginlime / JSONPlus による JSON の自己参照.md
Last active February 16, 2017 07:59
JSON の自己参照は楽だ。

JSONPlus による JSON の自己参照

JSONPlus

普通に自己参照を使えばいいんだけど、多用すると「@self」まみれでプロパティ参照が長くなって可読性がちょっと落ちるんじゃないかなーということで、JSONPlus の resolve を使う方法。

前提

  • Gulp でとりあえず動作させる
  • JSONPlus を使うので JSON5 としてコメント書いてる

gulpfile.js

var hoge = '';
$(selector).on(event,function(){
$.ajax({
async:false,
success:function(){
hoge='1';
}
});
if(hoge=='1'){
fuga();