Skip to content

Instantly share code, notes, and snippets.

@yoh2
yoh2 / takahashi_num_1_18.c
Last active August 29, 2015 14:19
1〜18桁の高橋の数 (http://masami.d2.r-cms.jp/blog_detail/blog_id=3&id=6) を求める。力技の割には意外と速い。
// 1桁〜18桁までの高橋の数を求める。
// 高橋の数 : http://masami.d2.r-cms.jp/blog_detail/blog_id=3&id=6
#include <stdio.h>
#include <stdbool.h>
// 高橋の数を格納する型。
typedef long long num_t;
#define PRId_num_t "lld"
// 自然数から各桁を構成する数字を数える。
@yoh2
yoh2 / nyancat
Created October 6, 2015 17:01
xinetd config file for nyancat
service telnet
{
socket_type = stream
protocol = tcp
wait = no
user = games
server = /usr/games/bin/nyancat
server_args = -t
only_from = 0.0.0.0/0 ::/0
flags = IPv6
@yoh2
yoh2 / 40_custom
Created November 8, 2015 08:49
UEFIから起動するWindowを起動するためのGRUB2設定。root=(...)はEFI用パーティションを指定。
#!/bin/sh
exec tail -n +3 $0
# This file provides an easy way to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry "Windows" --class windows --class os {
set root=(hd0,2)
chainloader '/EFI/Microsoft/Boot/bootmgfw.efi'
}
@yoh2
yoh2 / make.conf-tower
Created May 12, 2013 11:25
make.conf晒してみる。これはデスクトップ用途のタワーPC
# These settings were set by the catalyst build script that automatically built this stage
# Please consult /etc/make.conf.example for a more detailed example
#CFLAGS="-O2 -mtune=i686 -pipe"
#CFLAGS="-O2 -march=opteron -mtune=opteron -pipe"
CFLAGS="-O3 -march=native -mtune=native -msse4a -mfma -mfma4 -mxop -pipe -ftree-vectorize -ftree-loop-optimize"
CHOST="x86_64-pc-linux-gnu"
CXXFLAGS="$CFLAGS"
FFLAGS="$CFLAGS"
MAKEOPTS="-j45"
#MAKEOPTS="-j33"
@yoh2
yoh2 / make.conf-note
Created May 12, 2013 11:31
make.conf晒し。これはノートPCの。
# These settings were set by the catalyst build script that automatically
# built this stage.
# Please consult /etc/make.conf.example for a more detailed example.
CFLAGS="-O2 -funroll-loops -ftree-vectorize -ftree-loop-optimize -march=native -mtune=native -msse4.2 -pipe"
#CFLAGS="-O2 -funroll-loops -pipe"
#CFLAGS="-O2 -funroll-loops -march=nocona -mtune=nocona -pipe"
CXXFLAGS="${CFLAGS}"
# WARNING: Changing your CHOST is not something that should be done lightly.
# Please consult http://www.gentoo.org/doc/en/change-chost.xml before changing.
CHOST="x86_64-pc-linux-gnu"
@yoh2
yoh2 / nyancat
Created June 21, 2013 19:11
VPSに設定しているtelnetポート設定
service telnet
{
socket_type = stream
protocol = tcp
wait = no
user = games
server = /usr/games/bin/nyancat
server_args = -t
only_from = 0.0.0.0/0 ::/0
flags = IPv6
@yoh2
yoh2 / swat
Created June 21, 2013 19:34
SWATを有効にするためのxinetd設定ファイル /etc/xinetd.d/swat の我が家での設定。 デフォルトだとonly_fromがlocalhostになっていることがあって、そのままでは他ホストからアクセスできないのできちんと設定するのがミソ。 面倒なら 0.0.0.0/0 で横着する手も。
# default: off
# description: SWAT is the Samba Web Admin Tool. Use swat \
# to configure your Samba server. To use SWAT, \
# connect to port 901 with your favorite web browser.
# $Header: /var/cvsroot/gentoo-x86/net-fs/samba/files/config/swat.xinetd,v 1.1 2007/09/07 21:07:40 dev-zero Exp $
service swat
{
port = 901
socket_type = stream
@yoh2
yoh2 / bf.pl
Created December 12, 2013 14:13
何となく書いてしまったBrainf*ck実装。
#!/usr/bin/perl -w
# usage: bf.pl [source (default: stdin)]
sub run_bf
{
my @prog = @_;
my $ip = 0;
my $dp = 0;
@yoh2
yoh2 / bf.hs
Created December 13, 2013 19:02
でもってHaskellでBF。先日のbf.plより速くなると思う……がその分やや長い。
import System.IO
import System.Environment
import Data.Word
import qualified Data.ByteString as B
-- Utilities
applyFst :: (a -> c) -> (a, b) -> (c, b)
applyFst f (x, y) = (f x, y)
@yoh2
yoh2 / file1.txt
Last active January 22, 2016 19:48
-pthread を忘れると std::thread で例外が発生する仕組み ref: http://qiita.com/yoh2/items/97821d3d1dbe3e024d4f
$ g++ -Wall -std=c++11 sample.cpp -o sample1 # ← sample1 は -pthread 付けない
$ g++ -Wall -std=c++11 -pthread sample.cpp -o sample2 # ← sample2 は -pthread 付ける
$ ./sample1
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
中止
$ ./sample2
Hello!