Skip to content

Instantly share code, notes, and snippets.

View skoji's full-sized avatar
:octocat:
Working from home

Satoshi KOJIMA skoji

:octocat:
Working from home
View GitHub Profile
@skoji
skoji / ydml.rnc
Created November 10, 2010 08:51
well-formed YDML definition in Relax NG Compact Syntax
start = element ydml { Block* }
Block = Paragraph* & Center* & Left* & Right* & Quote* & Hasen*
Paragraph = Inline +
Inline = Large|Small|Bold|Image|Ruby|text
Center = element center { Inline+ }
Left = element left { Inline+ }
Right = element right { Inline+ }
Quote = element quote { Inline+ }
Hasen = element hasen { empty }
@skoji
skoji / densho_conv.rb
Created June 9, 2011 03:36
text to HTML convert utility. read from stdin. must define some singleton methods in the initialization block.
require 'uri'
class DenshoConv
attr_accessor :file_prefix, :file_suffix, :title, :stylesheets, :count, :toc, :count_format, :replace_url, :outer_div_class
def init_default_filters
before_filter do
|text|
if @replace_url
URI.extract(text, ['http', 'https']).each { |url|
@skoji
skoji / manifest.json
Created September 13, 2011 03:25
GDD2010JP DevQuiz WebGame
{
"name": "ChromeExtensionSolver",
"version": "1.0",
"description": "Open the first card and show background color of the card.",
"content_scripts": [
{
"matches": [
"http://gdd-2011-quiz-japan.appspot.com/webgame/problem*"
],
"js": [
@skoji
skoji / solve.rb
Created September 13, 2011 03:27
GDD2011JP DevQuiz 一人ゲーム solver
gets.to_i.times do
gets
nums = gets.split(' ').map(&:to_i)
queue = [[nums, 0]]
while !queue.empty?
node, ct = queue.shift
if (node.all? { |x| x % 5 == 0})
puts ct + 1
break
end
@skoji
skoji / gopng.go
Created September 13, 2011 03:38
GDD2011JP DevQuiz Go!
package main
import (
"fmt"
"io"
"strings"
"image/png"
)
func CountColor(pngdata io.Reader) int {
@skoji
skoji / gist:1539290
Created December 30, 2011 10:55
why this code won't run on ruby 1.8.7? (it runs on 1.9.3)
require 'pp'
class Bar
attr_accessor :foo_bars
def initialize(&block)
@foo_bars = []
yield self
end
def foo_bar(&block)
@skoji
skoji / builder_sample.rb
Created February 21, 2012 21:15
GEPUB::Builder API example
# -*- coding: utf-8 -*-
# GEPUB::Builder example.
require 'ruby gem'
require 'gepub'
builder = GEPUB::Builder.new {
# In the root block, you can define metadata.
# You can define title, creator(s), contributor(s), publisher(s), date, unique_identifier, identifier, language.
# Title can be specified with title, subtitle, collection, short_title, expanded_title, edition.
# You can also define description, format, relation, right, source, subject, type.
@skoji
skoji / Usage
Last active December 31, 2015 12:09
遅すぎですが。 ちょっと変更しました。EPUB前提なら、XMLで読んだようがいろいろとよいのでNokogiri::HTMLではなくNokogiri::XMLにしてみました
$ gem install nokogiri
$ ruby zen-to-han.rb < source.html > destination.html
@skoji
skoji / nora_custom_sample_1.rb
Last active August 29, 2015 13:57
NoraMark (http://github.com/skoji/noramark) customization sample
text =<<EOF
speak(Alice): Alice is speaking.
speak(Bob): and this is Bob.
EOF
document = NoraMark::Document.parse(text)
document.add_transformer(generator: :html) do
modify "speak" do
@node.name = 'p'
@node.prepend_child inline('span', @node.parameters[0], classes: ['speaker'])
# Markdown-ish heading with explicit setion boundary
---
lang: ja
title: test title
stylesheets: css/normalize.css, css/main.css
---
=: this is the first heading