Skip to content

Instantly share code, notes, and snippets.

View ushitora-anqou's full-sized avatar
🤪
Lots of fun

Ryotaro Banno ushitora-anqou

🤪
Lots of fun
View GitHub Profile
@ushitora-anqou
ushitora-anqou / streamline.cpp
Last active July 13, 2019 14:36
Tiny readline [WIP] -- Strongly inspired by https://github.com/troglobit/editline
#include <termios.h>
#include <unistd.h>
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/stream.hpp>
#include <deque>
#include <sstream>
#define AQ1_RANGE(cont) std::begin(cont), std::end(cont)
#define AQ1_ASSERT(cond, msg) \
@ushitora-anqou
ushitora-anqou / ban.sh
Last active October 31, 2022 04:49
GCPのファイアウォールに中国とオーストラリアからの上り通信を弾く設定を追加するシェルスクリプト
#!/bin/bash
#
# Shell script to add GCP's firewall to deny all ingress from China and Australia.
# Author: Ushitora Anqou
# License: MIT
#
curl https://ipv4.fetus.jp/cn.txt | grep -vE '#|^$' > cn.txt
curl https://ipv4.fetus.jp/au.txt | grep -vE '#|^$' > au.txt
for i in $(seq 1 250 $(wc -l cn.txt | cut -d' ' -f1)); do sed -n "$i,$((249 + i))p" cn.txt > cn-$(echo $i | awk '{printf "%02d", ($1-1)/250}'); done
for i in $(seq 1 250 $(wc -l au.txt | cut -d' ' -f1)); do sed -n "$i,$((249 + i))p" au.txt > au-$(echo $i | awk '{printf "%02d", ($1-1)/250}'); done
@ushitora-anqou
ushitora-anqou / switch_windows.sh
Last active May 11, 2019 14:15
Switch to the left/right window by wmctrl
#!/bin/bash
# Usage: switch_windows.sh left|right
# Thanks to: http://hico-horiuchi.hateblo.jp/entry/20130502/1367508391
P#!/bin/bash
PATH=/usr/bin:$PATH
if [ "$1" = "left" ]; then
CMP_POS="<"
@ushitora-anqou
ushitora-anqou / gamma.rb
Created April 8, 2019 07:00
ガンマ分布に従う乱数生成Rubyスクリプト
# Box–Muller's method
# https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
def normal_rand(mu = 0, sigma = 1)
x = rand
y = rand
z = Math.sqrt(-2 * Math.log(x)) * Math.cos(2 * Math::PI * y)
z * sigma + mu
end
#include <iostream>
#include <optional>
int main()
{
std::string input;
while (std::getline(std::cin, input)) {
std::optional<int> begin, end;
for (int i = 0; i < input.size(); i++) {
char ch = input[i];

Keybase proof

I hereby claim:

  • I am ushitora-anqou on github.
  • I am anqou (https://keybase.io/anqou) on keybase.
  • I have a public key whose fingerprint is F462 D1EA 528C D32B 6D16 522D CFDB B7E0 6092 4E96

To claim this, I am signing this object:

#!/usr/bin/ruby
STDOUT.sync = true # disable buffering
$target_urls = [
"8.8.8.8",
"8.8.4.4",
"4.2.2.2",
"4.2.2.1",
"www.google.com",
@ushitora-anqou
ushitora-anqou / cover.tex
Last active November 30, 2018 06:10
kkje2b cover
\documentclass[%
paper=a4,article,fontsize=10pt,%
number_of_lines=40,gutter=1in,%
jlreq_notes%
]{jlreq}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
int printf(char *str, int a, int b);
int validate(int *map, int N, int p)
{
if (map[p]) return 0;
int row = p / N, col = p % N;
for (int i = 0; i < N; i++)
if (map[i * N + col]) return 0;
for (int i = 0; i < N; i++)
@ushitora-anqou
ushitora-anqou / mc.sh
Created July 28, 2018 06:15
Minecraft start script
#!/bin/sh
PATH="/usr/bin:/usr/local/bin:$PATH"
SESSION_NAME="minecraft"
MC_LIVE_PATH="/home/minecraft/instance/live"
MC_BACKUP_PATH="$MC_LIVE_PATH/../backup"
MC_EXECUTE_COMMAND="java -Xmx1024M -Xms1024M -jar server.jar nogui"
mc_already_started() {