Skip to content

Instantly share code, notes, and snippets.

View kyontan's full-sized avatar
♨️

kyontan kyontan

♨️
View GitHub Profile
@kyontan
kyontan / test.rb
Created May 30, 2016 07:32
群のなんか
def apply(x, k)
ret = []
x.each.with_index{|a, i| ret[i] = k[a-1] }
ret
end
def dim(x)
t, i = x, 1
loop do
t = apply(t,x)
@kyontan
kyontan / app.rb
Last active December 11, 2016 06:17
謎分類器
#!/usr/bin/env ruby
helpers do
def img(path, l = nil, width=100, height=100)
html = "<img src=\"/#{path}\" width=#{width} height=#{height}>"
html = "<a href=\"#{l}\">#{html}</a>" if l
html
end
@kyontan
kyontan / rc.rb
Last active February 11, 2017 18:35
rc (rest client)
#!/usr/bin/env ruby
# rest_tester
# Created by 2017, kyontan <[email protected]>
# Licenced by CC0 (https://creativecommons.org/publicdomain/zero/1.0/deed.ja) except for module TTy
require "optparse"
require "shellwords"
require "json"
@kyontan
kyontan / KnobConForGame.ino
Created March 24, 2017 10:44
KnobCon firmware for adventure game
#ifndef USBCON
#define USBCON
#endif
#include <Joystick.h>
#include <Keyboard.h>
#define PIN_LED 17
#define PIN_A 3
#define PIN_B 7
@kyontan
kyontan / mastodon_remote_follow.rb
Last active April 16, 2017 13:24
マストドンで延々とリモートフォローをしつづけるやつです。
#!/usr/bin/env ruby
# how to use:
# 1. domains ファイルをこのスクリプトを同じディレクトリに配置し、リモートフォローしたいインスタンスのドメインを記載してください
# (place `domains` file located same directory as the script file, and write the domain name of instance which you want to remote follow.)
# 2. run this script
# 3. 発見されたアカウントがあなたのインスタンスに登録されます, ただ、リモートアカウントとして登録されるだけで、実際にフォローなどは行われません
# (new accounts might have registered to your insntance, but not yet `followed` by your account (only registered to instance as a remote account))
# 4. なんらかのお好きな方法でフォローしてください
# (please follow them by your account yourself, your ways)
@kyontan
kyontan / n-queen.cl
Created June 5, 2017 13:13
n-queen problem in Common LISP
(defun can-place (x y queens)
(cond
((member t (mapcar #'(lambda (xy) (or (= x (car xy)) (= y (cadr xy)))) queens)) nil)
((member t (mapcar #'(lambda (xy) (= 1 (abs (/ (- x (car xy)) (- y (cadr xy)))))) queens)) nil)
(t)))
; try putting a queen to (x y);
; if possible, put it and try putting recursively
; otherwise, trying putting a queen in order: (1 1) ~ (max max)
@kyontan
kyontan / h2o.conf
Created July 19, 2017 19:11
HTTP2 Server Push link header generator (Using h2o & mruby, for ictsc-score-server)
hosts:
"example.com":
listen:
port: 443
ssl:
key-file: /etc/h2o/key.pem
certificate-file: /etc/h2o/cert.pem
http2-casper: ON
reproxy: ON
paths:
@kyontan
kyontan / rest_client.rb
Created July 28, 2017 12:39
Simple rest client
require 'uri'
require 'json'
require 'net/http'
module RestClient
class << self
def get(path)
execute :get, path
end
@kyontan
kyontan / tm.rb
Created November 6, 2017 18:57
Turing Machine Simulator
#!/usr/bin/env ruby
class TM
BLANK = :blank
MOVE_LEFT = :left
MOVE_RIGHT = :right
HALT = :halt
attr_reader :pos, :state
@kyontan
kyontan / yield_self.js
Created March 6, 2018 07:54
yield_self in JavaScript (ECMAScript)
Object.defineProperty(Array.prototype, 'yield_self', {
enumerable: false,
value: function(f) { return f(this); }
});
// > array
// [ 1, 2, 3 ]
// > array.yield_self(x => x.concat(x))
// [ 1, 2, 3, 1, 2, 3 ]