Skip to content

Instantly share code, notes, and snippets.

View tats-u's full-sized avatar

Tatsunori Uchino tats-u

View GitHub Profile
@tats-u
tats-u / kiyoshi.cpp
Last active March 13, 2016 15:13
キヨシズンドコ節 in C++ (Zlib license/Copyright © 2016 Tats.U.)
#include <iostream>
#include <random>
#include <array>
#include <string>
using namespace std;
enum {
ZUN,
DOKO,
};
int main() {
@tats-u
tats-u / kiyoshi.py
Created March 13, 2016 15:15
キヨシズンドコ節 in Python3 (Zlib license/Copyright © 2016 Tats.U.)
from random import *
seed()
count = 0
tbl = ("ズン", "ドコ")
while count < 5:
rnd = randrange(2)
if count < 4:
if rnd == 0:
count += 1
else:
@tats-u
tats-u / enable_luajitlatex.sh
Last active April 11, 2016 14:22
A Bash script to nable LuaJITLaTeX in Linux
#!/bin/bash
# Linux: 原則rootで実行してください
# Windows: Git Bashなどで実行してください
sed -i -e '/luajitlatex/s/^ *#! *//' `kpsewhich fmtutil.cnf` || exit $?
fmtutil-sys --byfmt luajitlatex || exit $?
case `uname | tr [:upper:] [:lower:]` in
*msys*)
break;;
*cygwin*)
@tats-u
tats-u / fizzbuzz.sh
Created February 17, 2018 07:26
Fizz Buzz (sh & Bash completion)
#!/usr/bin/env bash
# Bash
for i in {1..100}; do # Don't have to use `seq`
# There are ((...))) and [[...]]] (didn't use this time) in Bash
if ((i % 15 == 0)); then
echo Fizz Buzz
elif ((i % 3 == 0)); then
echo Fizz
elif ((i % 5 == 0)); then
@tats-u
tats-u / gets_line.c
Created March 26, 2018 12:09
長さ無制限のgets
#include <stdio.h>
#include <stdlib.h>
//1行の入力を受け付ける関数。
//字数無制限。
//-1→失敗 0→正常 1→入力なし
//利用方法: gets_line(&pt) (pt: char* (=NULL))
//使用したポインタは必ず開放してください
#define GETS_LINE_INITIAL_LEN 64
@tats-u
tats-u / enable-wsl.ps1
Last active March 14, 2019 16:17
WSL有効化PowerShellスクリプト(管理者権限で実行してください)
$wsl_state = (Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux).State
if ($wsl_state) {
Write-Output "WSL has already been enabled."
exit(0)
}
if ($wsl_state -eq $null) {
Write-Output "WSL cannot be enabled because it doesn't exist on your PC. Update it to the latest Windows 10."
exit(1)
}
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
@tats-u
tats-u / make_hyper_default.sh
Last active November 26, 2018 05:52
Set Hyper as the default terminal
# Copyright 2018 Tatsunori Uchino
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE O
@tats-u
tats-u / nvim_aliases.ps1
Last active March 14, 2019 16:02
Run NeoVim by vim or vi in Windows PowerShell (Run `scoop install neovim` before)
if ((Get-Command nvim -ErrorAction Ignore)) {
if (-not (Get-Command vim -ErrorAction Ignore)) {
Set-Alias vim nvim
}
if (-not (Get-Command vi -ErrorAction Ignore)) {
Set-Alias vi vim
}
if (-not (Get-Command gvim -ErrorAction Ignore)) {
Set-Alias gvim nvim-qt
}
@tats-u
tats-u / bash_like_prompt.ps1
Last active March 14, 2019 16:19
Change the prompt of your PowerShell to one like Bash
function prompt() {
$return_code = $?
$domain_and_name = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$absolute = (Get-Location).Path
$esc = "$([char]27)"
$reset = $esc + "[0m"
$nas_prefix = 'Microsoft.PowerShell.Core\FileSystem::'
$is_root = (New-Object Security.Principal.WindowsPrincipal ([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
$prompt_sign = if ($is_root) { Write-Output '#' } else { Write-Output '$' }
return "${esc}[1;36mPS${reset}" `
@tats-u
tats-u / ubuntu_use_jp_mirror_repo.sh
Last active October 21, 2022 06:54
Ubuntuのリポジトリを日本ミラー(jp.archive.ubuntu.com)に変更するスクリプト
#!/bin/bash
# 利用法:
# curl -LsSf https://gist.github.com/tats-u/89a20f60c11ef86b32deeaf4a6e3cc91/raw/ubuntu_use_jp_mirror_repo.sh | sudo bash
#
# 主にWSL・Docker上のUbuntuが利用対象です
# (ベアメタルや各種VMにインストールしたUbuntuはすでにリポジトリが日本ミラーになっているため)
sed -i '/^deb/s@://archive\.ubuntu\.com@://jp.archive.ubuntu.com@' /etc/apt/sources.list