Skip to content

Instantly share code, notes, and snippets.

@ayapi
ayapi / retrySeries.js
Last active September 26, 2022 18:21
node-retryとcaolan/asyncを組み合ゎせて、複数のタスクを持っジョブで、途中のタスクでエラーになったらジョブの最初のタスクからゃり直し、みたぃな
var async = require('async');
var retry = require('retry');
var tasks = {
get: function(done){
console.log('get');
setTimeout(done, 1000);
},
send: function(done){
console.log('send');
@ayapi
ayapi / refresh-viewport-height-demo.html
Last active July 19, 2022 10:34
minimum example xterm.js refresh-viewport-height
<!doctype html>
<html>
<head>
<title>xterm.js demo</title>
<link rel="stylesheet" href="../src/xterm.css" />
<script src="../src/xterm.js" ></script>
<script src="../addons/fit/fit.js" ></script>
<style>
#term-box {
overflow: hidden;
@ayapi
ayapi / retry.js
Created February 27, 2014 18:23
tim-kos/node-retryでリトライ処理をかく練習 ネットワークが不安定な時とかを配慮できる
var _ = require('lodash');
var retry = require('retry');
// 試行のサンプルメソッド
var test = function(callback){
_.delay(function(){
var arg;
//20%の確率で成功、みたぃな
var num = _.random(0, 4);
@ayapi
ayapi / index.md
Created April 27, 2022 10:14
WSLのArchがMicrosoft.NETCore.Appのバージョンエラーで起動できなくなったら
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '5.0.0' (x64) was not found.
  - The following frameworks were found:
    6.0.2 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

て言ゎれたら

@ayapi
ayapi / gulpfile.js
Created May 23, 2014 02:47
gulp-stylus + autoprefixer-stylus
var gulp = require('gulp');
var stylus = require('gulp-stylus');
var autoprefixer = require('autoprefixer-stylus');
gulp.task('stylus', function () {
return gulp.src('./styl/style.styl')
.pipe(stylus({
use: [autoprefixer('iOS >= 7', 'last 1 Chrome version')]
}))
.pipe(gulp.dest('./css'))
@ayapi
ayapi / comment.md
Created October 20, 2017 03:41
Promise説明

この関数が呼び出されると、処理が完了するたびにPromiseオブジェクトが返されます。

Promiseオブジェクトが返るのゎ処理が完了してからでゎなくて、すぐに返ります

体感できるょーにするために、execMkdirの非同期処理を仮のものに書き換ぇて、 処理めっちゃ遅ぃゃっをシミュレートしてみます

// promiseTest.js
@ayapi
ayapi / completion.js
Created October 17, 2016 10:43
completion (doesnt work yet)
"use strict";
const chevrotain = require('chevrotain');
const Lexer = chevrotain.Lexer;
const Parser = chevrotain.Parser;
const extendToken = chevrotain.extendToken;
const KEYWORD = extendToken('KEYWORD', Lexer.NA);
const PRIVATE = extendToken('PRIVATE', /Private/i, KEYWORD);
const PUBLIC = extendToken('PUBLIC', /Public/i, KEYWORD);
@ayapi
ayapi / emittingBunyanLogEvent.js
Last active January 4, 2016 05:18
node-bunyanでログファイルがかきこまれたらイベントを発火するょーにしてみた logが増ぇた時にView(node-webkitのDOMとか)を更新したぃとかでっかぇる系
var util = require('util');
var _ = require('lodash');
var bunyan = require('bunyan');
function MyRingBuffer(options){
bunyan.RingBuffer.call(this, arguments)
}
util.inherits(MyRingBuffer, bunyan.RingBuffer);
MyRingBuffer.prototype.write = function(record){
@ayapi
ayapi / requestTimeoutDeferred.js
Last active January 4, 2016 02:39
タイムアウト処理をdeferredでゃる練習 コンソールで「node requestTimeoutDeferred 0」って打ったら、 loadイベントがタイムアウトょり早く発火した時の動き コンソールで「node requestTimeoutDeferred 1」って打ったら、 loadイベントが発火するょり前にタイムアウトの時間がきちゃった時の動き
var deferred = require('deferred');
var Backbone = require('backbone');
var _ = require('lodash');
var timer = [
{load: 1000, timeout: 2000},
{load: 3000, timeout: 2000}
];
var Sample = Backbone.Model.extend({
@ayapi
ayapi / opencv-node_invertColorTest.js
Last active January 1, 2016 14:59
opencv-nodeをっかって画像を階調反転して表示する
var cv = require('opencv-node');
var path = require('path');
var fullpath = path.resolve('./lena.png');
console.log('Opening ', fullpath);
var src = cv.imread(fullpath, -1);
if(src.empty) return console.log('Error opening file');