Skip to content

Instantly share code, notes, and snippets.

View iwamoto-takaaki's full-sized avatar

takaaki iwamoto-takaaki

  • Kumamoto, japan
View GitHub Profile
@iwamoto-takaaki
iwamoto-takaaki / replace.js
Last active May 14, 2020 13:09
memo: wordpress replace by regular
// wordpressの投稿の一括変換の依頼が来たので変換のスクリプトを書いた。
var fs = require('fs')
// 行をまたいで置換を行うために、対象があるかぎり再帰的に置換する関数
function rereg(str, reg, newStr) {
if(!reg.test(str)) return str;
return rereg(str.replace(reg, newStr), reg, newStr);
}
fs.readFile('input.txt', 'utf8', function (err,data) {
@iwamoto-takaaki
iwamoto-takaaki / file0.rb
Last active December 1, 2018 17:15
RubyのTimesをC#の拡張メソッドで実装してみた ref: https://qiita.com/takaaki-iwamoto/items/7f59f9768d1e757e74a7
3.times{|i|
p i
}
# out =>
# 0
# 1
# 2
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
function calcPayment(loan, termRate, numberOfTerms, loanType, count){
if (count < 1) return 0;
if (loanType == "payment_equal") {
return calcPaymentEqual(loan, termRate, numberOfTerms) * count;
}else{
return calcPrincipalEqual(loan, termRate, numberOfTerms)
+ calcPayment(loan * (numberOfTerms - 1) / numberOfTerms, termRate, numberOfTerms - 1, loanType, count - 1);
using System;
using System.Collections.Generic;
using System.Linq;
public static class Extension{
// var list = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
// 1.To(5).Select(i => list[i]).ToList().ForEach(c => Console.Write(c));
// out => bcdef
public static IEnumerable<int> To(this int from, int to){
return Enumerable.Range(from, to - from + 1);
public class Scanner{
private string line;
private string[] token;
private int cursole = 0;
public string ReadLine(){
line = Console.ReadLine();
token = line.Split(' ');
cursole = 0;
return line;
<!DOCTYPE>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>TextQuest</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript" >
// これ見てて作りたくなった。
// https://teratail.com/questions/13308
// fieldの定義はうまく言ったと思うが、コードは汚い
using System;
static class Heapsort{
struct Node{
public int[] List;
public int Root_i;
public int Bottom_i;
public int Root{
get{return this.List[this.Root_i];}
}
using System;
static class MargeSort{
static int[] Sort(this int[] list){
InnerMargesort(list,new int[list.Length], 0, list.Length - 1);
return list;
}
static void InnerMargesort(int[] list, int[] temp, int lh, int rh){
if (rh <= lh) return;
var mid = (lh + rh)/2;
using System;
static class selectSort{
static int[] Sort(this int[] list){
for(var i = 0; i < list.Length - 1; ++i){
int min = i + 1;
for(var j = i; j < list.Length; ++j)
if (list[j] < list[min]) min = j;
list.Swap(min, i);
}
using System;
static class ShellSort{
static int[] Sort(this int[] list){
list.InnerSort(list.Length / 2);
return list;
}
static void InnerSort(this int[] list, int gap){
if(gap < 1) return;