Skip to content

Instantly share code, notes, and snippets.

View nariyu's full-sized avatar

Yusuke Narita nariyu

  • playwell inc.
  • Tokyo, JP
  • X @nariyu
View GitHub Profile
@nariyu
nariyu / index.js
Created November 2, 2021 14:01
ディレクトリアクセスに index.html を補完する Lambda@Edge 関数
'use strict';
exports.handler = (event, context, callback) => {
// リクエスト
const request = event.Records[0].cf.request;
// `/moja` から `/moja/` にリダイレクト
if (request.uri.match(/\/([^\.\/]+)$/)) {
const url = request.uri.replace(/(\/[^\.\/]+\/?)$/, '$1/').replace(/\/\/+/g, '/');
@nariyu
nariyu / dateutil.ts
Last active July 9, 2020 07:44
日時のフォーマット
/**
* 日時を成形した文字列で取得する
* @param {Date} dateTime 日付(オプション)
* @param {String} formatStr フォーマット(オプション)
* @return {String} フォーマット後の文字列
*/
export const formatDate = (
dateTime?: Date | number,
formatStr?: string | null,
): string => {
@nariyu
nariyu / slide.js
Last active August 26, 2017 17:12
google画像検索の結果画面で実行するとスライドショーになるbookmarklet
b=document.body;a=b.querySelectorAll('a.rg_l');a=Array.prototype.slice.apply(a);c=document.createElement('div');s=c.style;s.position='fixed';s.zIndex=1000;s.top=s.left=0;s.width=s.height='100%';s.background='rgba(0,0,0,.8)';s.opacity=0;s.transition='opacity 1s linear 0s';b.appendChild(c);setTimeout(function(){s.opacity=1},10);l=[];a.forEach(function(i){m=i.href.match(/imgurl=(https?.+?\.(jpe?g|png|gif))/i);if(!m)return;l.push(decodeURIComponent(m[1]))});n=function(u,i,s){u=l.shift();i=new Image;s=i.style;i.onload=function(){s.width='auto';s.height='70%';s.opacity='1';l.push(u);setTimeout(function(){s.opacity='0';setTimeout(function(){c.removeChild(i)},500)},2800,i);setTimeout(n,3000)};i.onerror=function(){c.removeChild(i);n()};i.src=u;s.position='absolute';s.top=s.left='50%';s.boxShadow='0 0 30px #000';s.opacity='0';s.transform='translate(-50%,-50%)';s.transition='opacity 0.5s linear 0s';c.appendChild(i)};setTimeout(n,1000)
@nariyu
nariyu / port.go
Created July 16, 2015 09:14
空いてるポートを探すやーつ
package xxx
import (
"fmt"
"net"
)
// 使える TCP ポートを探すんだ
func searchUsablePort(startPort, endPort int) int {
@nariyu
nariyu / EventEmitter.js
Last active August 29, 2015 14:21
EventEmitter (ES6)
'use strict';
// イベントリスナーの入れ物
let listenerMap = new Map;
/**
EventEmitter クラス
*/
@nariyu
nariyu / share.html
Last active August 29, 2015 14:10
今のところ使えるシェアボタンの作り方(2014年12月8日現在)
<!-- デザインを自分で作る場合。CSSで好きにデザインしたらいい。 -->
<!-- ただし tw/fb のシェア画面が PC でも全画面で開く。ダサい。 -->
<ul>
<li class="twitter"><a href="http://twitter.com/share?text=SAMPLE_TEXT&amp;lang=ja&amp;url=http%3A%2F%2Fexample.com%2F" target="_blank">Tweet</a></li>
<li class="facebook"><a href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fexample.com%2F" target="_blank">Facebook</a></li>
<li class="line"><a href="http://line.naver.jp/R/msg/text/?SAMPLE_TEXT%20http://example.com/">LINEで送る</a></li>
</ul>
<!-- 標準のデザインを使う場合。カウント表示はなしだよ。 -->
@nariyu
nariyu / flexformatter
Created September 12, 2011 13:51
Flex Formatter Definitions
#FlexFormatter settings
#Thu Oct 13 10:41:32 JST 2011
ActionScript.metatagsOnSameLineAsTargetFunction=Bindable
Actionscript.advancedSpacesInsideParensInParameterLists=0
MXML.keepRelativeIndentInMultilineComments=true
MXML.attrsPerLine=1
MXML.blankLinesBeforeTags=0
ASRearr_GroupGettersAndSettersWithStaticProperties=false
Actionscript.keepBlankLines=true
MXML.tagsDoNotFormatInside=.*\:Model,.*\:XML,