Skip to content

Instantly share code, notes, and snippets.

host:example.com url:/api/users status:200 time:2018-01-01T00:00:00+09:00
host:example.com url:/api/users status:200 time:2018-01-01T00:00:01+09:00
@yuba
yuba / file0.txt
Last active April 20, 2018 14:33
ディレクトリ内のすべてのファイルをループする ref: https://qiita.com/yuba/items/489fadb350246b5c94e7
while read -d $'\0' file; do
"${file}" に対して処理
done < <(find ディレクトリ -mindepth 1 -maxdepth 1 -print0)
@yuba
yuba / file0.sql
Created December 6, 2017 22:24
カラムにnullが含まれるなら結果がnullになるmax() ref: https://qiita.com/yuba/items/a402cc00f7e1ce900e4b
max(end_date) keep (dense_rank last order by end_date nulls last)
@yuba
yuba / file0.txt
Created June 21, 2017 10:54
本当に比較して一致したのか不安な人向けdiff ref: http://qiita.com/yuba/items/668131a54c91788d207a
#!/usr/bin/env bash
diff\
<(tee <$1 >(echo 左側:`wc -l`行>&2)) \
<(tee <$2 >(echo 右側:`wc -l`行>&2)) &&\
echo 一致しました>&2
@yuba
yuba / file0.txt
Last active June 15, 2017 02:42
クラスメソッド参照、インスタンスメソッド参照の取得と差し込み ref: http://qiita.com/yuba/items/6a167756fda660f8e759
class C:
def __init__(self, n):
self.n = n
def m(self, x, y):
print('self.n:%s, x:%s, y:%s' % (self.n, x, y))
i = C(1)
C.m # クラスメソッド参照
i.m # インスタンスメソッド参照
@yuba
yuba / iterate_by_slice.py
Last active April 26, 2017 11:57
sliceオブジェクトをインデックス番号のリストに変換する ref: http://qiita.com/yuba/items/245975ffc2f0322f8680
def iterate_by_slice(s: slice, length: int):
i, stop, step = s.indices(length)
if step > 0 :
while i < stop:
yield i
i += step
else:
while i > stop:
yield i
i += step
@yuba
yuba / file0.txt
Last active December 1, 2017 14:13
地球を真球と仮定して2地点間の距離を算出する ref: https://qiita.com/yuba/items/4372944ce0f6a0bf6cb5
distance_km = 6371 * acos(
cos(latA/180*pi) * cos((lonB - lonA)/180*pi) * cos(latB/180*pi) +
sin(latA/180*pi) * sin(latB/180*pi)
);
@yuba
yuba / Polynomial.java
Created July 4, 2016 12:26
n次多項式を表現し、二分法で根を求めることができるクラス。 new Polynomial(-3, -2, 1 , -4, 0, 2).solve() などとやるとdouble配列で根が返ってくる。2次式でも1次式でさえ公式使わず二分法。
import java.util.HashSet;
import java.util.Set;
/**
* xの多項式を表します
*/
public class Polynomial
{
/**
* @param a 定数, 1次係数, 2次係数, 3次係数, ... と係数を指定します
@yuba
yuba / file0.java
Last active May 26, 2016 04:02
任意のjarファイルから条件に合ったクラスをロードする ref: http://qiita.com/yuba/items/f9f02d4e81c5020c268a
/**
* 指定したjarファイルから指定interfaceの実装クラス(引数なしコンストラクタを持つもの)をすべてロードして返します。
* @param jarPath jarファイル
* @param i 実装しているべきinterfaceまたは親クラス
* @param <Interface> 実装しているべきinterfaceまたは親クラス
* @return jarファイル内に含まれる、条件に合うクラスすべてを含むリスト
* @throws IOException jarファイルの読み込みができませんでした。
*/
public static <Interface> List<Class<Interface>> loadClassesInJar(String jarPath, Class<Interface> i) throws IOException
{
@yuba
yuba / file0.txt
Created April 20, 2016 09:02
配列にfirst, lastメソッドを生やす ref: http://qiita.com/yuba/items/9b38fa15bc6b62e1ec71
/** Extends array object */
interface Array<T> {
/** Returns the first element that satisfies the predicate */
first(predicate:(element:T) => boolean, defaultVaule: T): T;
/** Returns the last element that satisfies the predicate */
last(predicate:(element:T) => boolean, defaultVaule: T): T;
}
Array.prototype.first = function (predicate: (element) => boolean, defaultVaule) {
for (var i: number = 0; i < this.length; i++) {