Skip to content

Instantly share code, notes, and snippets.

@dseg
dseg / nftables.conf
Created April 22, 2016 07:45
A basic nftables config. Only accept ssh, http and https.
#!/usr/bin/nft -f
# ipv4/ipv6 Simple & Safe Firewall
# you can find examples in /usr/share/nftables/
table inet filter {
chain input {
type filter hook input priority 0;
# allow established/related connections
ct state {established, related} accept
@dseg
dseg / sfen-parser.pegjs
Created March 8, 2016 14:33
sfen-parser.pegjs
/**
* Title: SFEN parser
* Date: 23-Jan-2014
* Author: Daichi Shinozaki <dsdseg@gmail.com>
* Demo URL: http://jsfiddle.net/dseg/QezQ7/15/
*
* Note:
* Tested with PEG.js 0.8.0
* http://pegjs.majda.cz/
*
@dseg
dseg / estimategas.sh
Created March 28, 2018 07:48
Estimate Gas (of Ethereum)
#!/bin/sh
# Requirements: geth
fee=$(geth attach ipc:/home/ubuntu/main_net/geth.ipc --exec 'web3.fromWei(web3.eth.gasPrice*web3.eth.estimateGas({from:"0xc1912fee45d61c87cc5ea59dae31190fffff232d"}))')
date
echo -n $fee | tr -d \"
echo \ ETH.
@dseg
dseg / ens3
Last active January 12, 2018 13:04
クラウド環境でArchLinuxを使う (Vultr編) ref: https://qiita.com/dseg/items/b4ad1c076dc585cb4432
Description='A basic static ethernet connection'
Interface=ens3
Connection=ethernet
IP=static
Address=('111.112.113.114/255.255.254.0')
Gateway='111.112.113.1'
DNS=('108.61.10.10')
## For IPv6 autoconfiguration
#IP6=stateless
@dseg
dseg / config
Last active November 29, 2017 10:43
秘密鍵、管理してますか? YubiKeyで鍵の一元管理とSSH接続、2段階認証の高速化を試す ref: https://qiita.com/dseg/items/77d77467970b1b510285
PKCS11Provider opensc-pkcs11.dll
use std::io::Write;
use std::net::{TcpListener, TcpStream};
use std::thread;
fn handle_client(mut stream: TcpStream) {
thread::spawn(move || {
stream.write(b"Hello World\r\n").unwrap();
});
}
@dseg
dseg / Satoshi to BTC
Created June 1, 2017 15:19
satoshi2btc.sh
# Usage: btc bitcoin_amount_in_satoshi
# $ btc 1550000000
# 15.50000 BTC
#
function btc {
if [[ -n $1 ]]; then
btc=$(bc -l <<< "$1 / 100000000.0")
printf '%.5f BTC\n' $btc
fi
}
@dseg
dseg / jst.sh
Created March 30, 2017 10:26
Output now in BusyBox (for example, Alpine Linux) as Japan Standard Time
TZ=JST-9 date -Iseconds|tr T ' '|tr - /|head -c 19
@dseg
dseg / makeQueryString.ts
Created February 23, 2017 08:59
Crafting a query string from an array using ES6's template literal feature
/**
* Template String Tag (For crafting query-string for HTTP/Get from a array)
*
* Usage: qsTag`${['a','b','c','d']}`(); // a=b&c=d
*/
export const qsTag = (strings, ...keys) => (...values) => {
let result = [];
const input = keys[0];
input.forEach((key: any, i: number, ary: any[]) => {
const postfix = (ary.length-1 === i ? '' : '&');
@dseg
dseg / select.tsx
Created January 27, 2017 06:32
A React Select Snippet
<select>
{
// options が undefined or nullなら、何も出力しない。配列なら選択肢に整形する。
options && Array.isArray(options) && options.map((item : any, idx : number) =>
<option
key={`inq_opt_${idx}`}
value={item.value}>{item.label}</option>)
}
</select>