Skip to content

Instantly share code, notes, and snippets.

@youchan
youchan / scraper.js
Created January 25, 2020 08:00
技術書典のサークルの頒布物のページから情報を抜きだす
const puppeteer = require('puppeteer');
const fs = require("fs");
const url = "https://techbookfest.org/event/tbf07/circle/xxxxxxxxxxxxxxx";
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
@youchan
youchan / generator.rb
Created August 31, 2019 05:54
マンガでわかるRubyのスクリプト
require "psych"
require "redcarpet"
require_relative "./renderer"
require_relative "./toc_renderer"
module Mwr
class Generator
def initialize(workdir)
@workdir = File.expand_path(workdir)
@youchan
youchan / tfidf.rb
Created April 19, 2019 11:39
code partyで書いたtf-idfのRuby実装
text = File.read "./utamap.test.txt"
vocabraries = []
word2id = {}
text.split("\n").each do |doc|
words = doc.split(" ")
words.each do |word|
unless word2id.has_key?(word)
vocabraries << word
require_relative "./renderer"
require "psych"
markdown = Redcarpet::Markdown.new(Renderer, autolink: true, tables: true)
files = Psych.load_file("articles/articles.yaml")
File.open("html/index.html", "w") do |html|
html.write <<~HTML
<html>
@youchan
youchan / game_of_life.rb
Last active April 20, 2020 00:21
One liner version n Conway's Game of Life
s=30;Array.new((s+2)*(s+2),0).tap{|g|[100,133,163,164,165].each{|i|g[i]=1};100.times{s.times{|y|puts s.times.map{|x|g[x+s+3+y*(s+2)]==1??*:?.}.join};(s*s).times.map{|i|i+=i/s*2;[0,1,2,3,5,6,7,8].map{|x|g[i+x%3+x/3*2+x/3*s]}.sum.then{|x|x==3?1:x==2?g[i+s+3]:0}}.tap{|n|(s*s).times{|i|g[i+s+3+i/s*2]=n[i]}};sleep(0.1);print"\e[#{s}A"}}
bin = "YARB\u0002\u0000\u0000\u0000\u0005\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000x86_64-darwin16\u0000"
putself = 16
putstring = 20
opt_send_without_block = 52
leave = 55
hello = 3
codes = [
@youchan
youchan / dataset.rb
Last active March 1, 2018 01:33
TF-IDF法を実装してみた
require "sparql/client"
class Dataset
include Enumerable
def initialize
@sparql = SPARQL::Client.new("http://ja.dbpedia.org/sparql")
end
def each
@youchan
youchan / decision_tree.rb
Last active February 9, 2018 16:32
Decision Tree in Ruby
require "datasets"
class Array
def avg(&block)
return 0.0 if self.length == 0
self.sum(&block) / self.length
end
end
class Node
class CkySolver
def initialize(&init_proc)
@init_proc = init_proc
end
def solve(n, &callback)
a = Array.new(n * n)
n.times {|i| a[i*n + i] = @init_proc.call(i) }
(n - 1).times do |d|
名前 カテゴリ 説明
nop nop nop
getlocal variable level, idx で指定されたローカル変数の値をスタックに置く。
setlocal variable level, idx で指定されたローカル変数の値を val にする。
getblockparam variable ブロックパラメータを取得する。
setblockparam variable ブロックパラメータを設定する。
getspecial variable 特殊なローカル変数($~, $_, ...)の値を得る。
setspecial variable 特別なローカル変数($~, $_, ...)の値を設定する。
getinstancevariable variable self のインスタンス変数 id の値を得る。