Skip to content

Instantly share code, notes, and snippets.

@naosim
naosim / DocumentTopPosition.js
Created March 31, 2018 02:18
エレメントの位置を取得する
class DocumentTopPosition {
constructor(doc, win) {
this.document = doc || document;
this.window = win || window;
}
/**
* @returns {number} top position
*/
get(element) {
@naosim
naosim / DisplayOutMonitor.js
Created March 31, 2018 08:35
Elementが画面外に出たことを検知する
class DisplayOutMonitor {
constructor(option) {
option = option || {}
this.document = option.document || document
this.interval = option.interval || 100
}
/**
* @param {string}
* @param {(isOut:boolean)=>void}
@naosim
naosim / .htaccess
Created March 31, 2018 20:49
PHP用htaccess設定
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app/silexsample/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /app/silexsample/index.php [L]
</IfModule>
@naosim
naosim / lock.php
Last active April 30, 2018 22:16
phpでlockする
<?php
function lock($lockFileName, $fuc) {
if(!file_exists($lockFileName)) {
file_put_contents($lockFileName, '');
}
$lock_fp = fopen($lockFileName ,"w");
flock($lock_fp, LOCK_EX);
try {
return $fuc();
@naosim
naosim / vo_string.js
Created May 13, 2018 07:47
バリューオブジェクト生成 (String)
const template = `
package __PACKAGE__;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
@AllArgsConstructor
@EqualsAndHashCode
public class __CLASS__ {
private final String value;
@naosim
naosim / table2md.html
Created June 5, 2018 21:30
htmlのテーブルからmarkdownを作る
<!DOCTYPE html>
<div id="div20180606">
<table border="1">
<tr><th>名前</th><th>備考</th>
<tr><td>ほげ</td><td>改行<br>テスト</td></tr>
<tr><td>ふー</td><td>改行<br>テスト</td></tr>
</table>
</div>
<script>
@naosim
naosim / table.js
Created June 12, 2018 21:59
markdownからcreatetableを作るメモ
// node . inputfile outRootDir
if(process.argv.length == 2) {
const msg = 'USAGE\nnode . inputMarkdownFile outRootDir'
console.log(msg)
throw msg
}
const inputMarkdownFile = process.argv[2]
const outRootDir = process.argv[3]
@naosim
naosim / lastupdate.js
Created December 18, 2018 02:02
ディレクトリ配下で最後に更新したファイルを取得する
// 最後に更新されたファイルを取得する
// 利用例
// ls -l | node lastupdate.js
// => 2018-12-18 10:50 ./worklog/index.js
//
// サブディレクトリも対象にするならこう
// find . -type f | xargs ls -l | node worklog index.js
//
// 事前準備
// npmで'textpipe'を入れておくこと
@naosim
naosim / sheet.js
Last active July 12, 2019 22:23
GASでスプレッドシートを操作する
/**
* レコードの全取得
*/
function findAll(name /* シート名 */) {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(name);
var table = sheet.getDataRange().getValues()
return JSON.parse(JSON.stringify(table));
}
/**
@naosim
naosim / loadLibForOneMethod.js
Last active May 11, 2021 19:58
【GAS】githubやgist上のライブラリを読み込むスニペット
/**
* 外部ファイルからjsを読み込む
* githubやgists上にあるコードを使いたい時用
*/
function loadLibForOneMethod(mainMethodName, url) {
// リトライありのfetch
function retryFetch(url) {
var lastError = null;
for(var i = 0; i < 3; i++) {
try {