Skip to content

Instantly share code, notes, and snippets.

@kencoba
kencoba / ProofsOnBooks.v
Created March 19, 2024 08:46
Sample proofs from books.
(* 新妻弘,「演習 群・環・体 入門」,共立出版株式会社 より *)
Require Import ZArith.
Open Scope Z_scope.
Theorem thm_1_1 : forall a b c : Z , a + b = a + c -> b = c.
Proof.
intros a b c H.
apply Z.add_cancel_l with (p := a).
assumption.
Qed.
@kencoba
kencoba / CounterServlet.java
Created June 3, 2023 11:40
A sample servlet for understanding between a request and a sesson.
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@kencoba
kencoba / trans.rb
Created October 16, 2020 09:50
Transaction simulator with Ruby
class Request
end
class Read < Request
attr_reader :var
def initialize(var)
@var = var
end
@kencoba
kencoba / trans.py
Created October 16, 2020 09:50
Transaction simulator with Python.
class Request:
pass
class Read(Request):
def __init__(self, var):
self.var = var
class Write(Request):
@kencoba
kencoba / main.rs
Created September 29, 2020 01:36
A translation from Ruby to Rust in the book :pp.018-020[「もっとプログラマ脳を鍛える数学パズル」](https://www.shoeisha.co.jp/book/detail/9784798153612)
fn main() {
println!("{n}P{r} = {x}", n = 5, r = 2, x = permutation(5, 2));
println!("{n}C{r} = {x}", n = 5, r = 2, x = combination(5, 2));
}
pub fn permutation(n: i64, r: i64) -> i64 {
let mut result = 1;
for i in (n - r + 1)..=n {
result *= i;
}
@kencoba
kencoba / main.rs
Created September 29, 2020 01:34
A translation from Ruby to Rust in the book :pp.013-017[「もっとプログラマ脳を鍛える数学パズル」](https://www.shoeisha.co.jp/book/detail/9784798153612)
use std::collections::HashMap;
struct Checker {
memo: HashMap<(i64, i64), i64>,
max_seat_at_one_table: i64,
}
impl Checker {
pub fn check(&mut self, remain: i64, pre: i64) -> i64 {
match &self.memo.get(&(remain, pre)) {
@kencoba
kencoba / download_activity.rb
Created August 31, 2020 11:05
Download Moodle activity data.
#!/usr/bin/env ruby
# usage: ruby download_activity.rb https://www.example.com/ app user passWd\! 12 result.csv
# caution : if your password includes bash's special character ,put a '\' before that char (ex: '!' is '\!').
require "tempfile"
require "uri"
moodle_site = ARGV[0]
app_root = ARGV[1]
username = ARGV[2]
@kencoba
kencoba / svnadmin.rb
Created August 30, 2020 11:16
(Experimental) adding user to Subversion.
# usage:
# $ sudo ruby ./svnadmin.rb #{account} #{password}
account=ARGV[0]
password=ARGV[1]
# create user account.
system "sudo adduser --gecos ',,,' --disabled-login --quiet #{account}"
puts "result of adduser"
@kencoba
kencoba / Arithmetic.scala
Created August 17, 2020 10:03
Sample code of "Creating DSL With Antlr4 and Scala" for Scala2.13
import java.io.ByteArrayInputStream
import org.antlr.v4.runtime.{CharStream, CharStreams, CommonTokenStream}
/**
* See original Saumitra's blog.
* https://saumitra.me/blog/creating-dsl-with-antlr4-and-scala/
*
* This code is for Scala 2.13.
*/
@kencoba
kencoba / Vagrantfile
Created August 12, 2020 08:23
Vagrantfile for Haskell.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/bionic64"
config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
config.vm.network "private_network", ip: "192.168.33.10"