Skip to content

Instantly share code, notes, and snippets.

nyaocat / run-in-nonet
Created May 8, 2021
View run-in-nonet
set -eu
readonly NSNAME="ns${RANDOM}"
sudo ip netns add "$NSNAME"
trap "sudo ip netns delete '$NSNAME'" 0
sudo ip netns exec "$NSNAME" sudo -u "$USER" "$@"
nyaocat / type-safe-builder.ts
Created Nov 30, 2020
View type-safe-builder.ts
type WidthDefined = {width: number};
type HeightDefined = {height:number};
type TitleDefined = {title:string};
type AllDefined = WidthDefined & HeightDefined & TitleDefined;
class WidgetBuilder<T>{
constructor(private params: T){}
width<D>(this:WidgetBuilder<D extends WidthDefined ? never : D>, width: number):WidgetBuilder<D & WidthDefined> {
return new WidgetBuilder(Object.assign(this.params, {width}));
nyaocat / w-make
Last active Sep 20, 2020
make を継続的に実行するコマンド
View w-make
# w-make コマンド
# このファイルを PATH の通った場所に実行属性付きで w-make として保存し、
# `make xxx` の代わりに `w-make xxx` を実行すると必要な依存ファイルの変更を監視して継続的に make をたたく
# 要: make, inotifywait, perl
while :
make "$@"
nyaocat /
Last active Sep 20, 2019
雑な mDNS サーバ実装
# License: NYSL
use warnings;
use strict;
use Sys::Hostname;
use IO::Socket::Multicast;
use Net::DNS;
use IO::Interface::Simple;
my $sock = IO::Socket::Multicast->new(LocalPort => 5353);
nyaocat / grepedit
Created Apr 5, 2019
grep した結果に対してのみ編集を行うコマンド(例: grepedit -E '^[1-9]' * )
View grepedit
set -eu
trap "rm '$BUF'" 0
grep -H -n "$@" > "$BUF"
"${EDITOR:-vi}" "$BUF"
nyaocat / npm
Created Mar 11, 2019
nodeをインストールしたくないので docker で代用する(下記ファイルを PATH の通る場所に node, npm, npx と名付けてそれぞれ保存すると使える)
View npm
set -eu
mkdir -p $HOME/.config $HOME/.npm
docker run \
-it --rm \
--tmpfs "/tmp" \
-v "$PWD:$PWD" \
-v "$HOME/.config:$HOME/.config" \
nyaocat /
Last active Mar 14, 2022
pysdl2 in wxpython
import sdl2
import sdl2.ext
import math
import wx
class SDL2Timer(wx.Timer):
def Yaruzo(self, a):
# window = sdl2.SDL_CreateWindow("Hi".encode("utf-8"),
nyaocat / xfce4-session.bat
Created Feb 15, 2018
View xfce4-session.bat
start "xserver" "C:\Program Files\VcXsrv\vcxsrv.exe" -fullscreen
wsl sh -c "env DISPLAY=:0 xfce4-session"
View docker-edit
# usage: docker-edit container filepath
# License: NYSL
set -eu
trap "rm $TMPFILE" 0
docker cp $1:$2 $TMPFILE
nyaocat / aaa.cpp
Last active Feb 15, 2018
type-safe event holder
View aaa.cpp
#include <iostream>
#include <string>
#include "signal.hpp"
struct event_A : public s::signal<int, int> {};
struct event_B : public s::signal<std::string, int, double> {};
int main() {
s::bind<event_A>([](int p1, int p2) {