Skip to content

Instantly share code, notes, and snippets.

View kachick's full-sized avatar
😋
😪

Kenichi Kamiya kachick

😋
😪
View GitHub Profile
/* 強調タグを追加 */
function emphasizeWord(word) {
return '<strong>' + word + '</strong>';
}
/* 長い順に並べるための比較関数 */
function compareLengthDecrease(a, b) {
a = a.length;
b = b.length;
return a > b ? -1 : a < b ? 1 : 0;
ALLOW_TAGS = %w/font span p b br/
def validate_xml_fragment
str = self
tags = str.scan(/\G(?:(<[^<>]+>)|[^<>&]+|[^&<>]*(?:&#?\w+;[^&<>]*)+)/)
return ERB::Util.html_escape(str) unless $'.empty?
stack = []
tags.each do |tag|
case tag.first
when /<(\w+)(?: +\w+=(?:"[^"]*"|'[^']*'|\w+))* *(\/)?>/
return ERB::Util.html_escape(str) unless ALLOW_TAGS.include?($1)
@cpetschnig
cpetschnig / validate_ipv6.rb
Created February 4, 2010 09:19
Regular Expression Validation for IPv6 Addresses in Ruby
# Regular Expression Validation for IPv6 addresses in Ruby
#
# Inspired by (if not to say copied from): http://forums.dartware.com/viewtopic.php?t=452
# Thanks, Dartware!
IPV6_REGEX = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f
@nurse
nurse / merger.rb
Created June 5, 2010 04:22
Merger for Ruby
#! /bin/ruby
# http://coderepos.org/share/browser/docs/shyouhei/ruby%20development/merger.rb
require 'date'
require 'tempfile'
$repos = 'svn+ssh://svn@ci.ruby-lang.org/ruby/'
ENV['LC_ALL'] = 'C'
def help
@nurse
nurse / gist:555963
Last active January 24, 2017 05:45
JIS8 charset for emacs

IRC 等で用いられるいわゆる半角カナを含む ISO-2022-JP variant の emacs 用設定

文字セット

reg#  character set       ESC sequence  designated to
------------------------------------------------------
  6   US-ASCII            ESC ( B       G0
 13   JIS X 0201-Katakana ESC ( I       G0
 14   JIS X 0201-Roman    ESC ( J       G0

42 JIS X 0208-1978 ESC $ @ G0

@tricknotes
tricknotes / excel.js
Created January 24, 2011 19:43
Excelファイルの読み書き用ユーティリティ
/*
* Windows上でExcelを操作するためのシンプルなモジュールです。
* ファイルのオープン・クローズを隠蔽しています。
*/
var excel = (function() {
var exports = {};
// Excel操作
@nurse
nurse / abnf2onig.rb
Created March 30, 2011 05:56
ABNF to Oniguruma Regexp Converter
#!/usr/local/bin/ruby
# If you want an ABNF to Regexp, see below.
# http://www.a-k-r.org/abnf/
# https://github.com/martinthomson/abnf2regex
require 'strscan'
RULENAME_ = /[A-Za-z][A-Za-z0-9\-]*/
C_WSPP_ = /[ \t]+(?:(?:;.*)?\n[ \t]+)*|(?:(?:;.*)?\n[ \t]+)+/
C_WSPS_ = /[ \t]*(?:(?:;.*)?\n[ \t]+)*/
C_NL_ = /(?:;.*)?\n/
@hryk
hryk / glitch.rb
Created May 10, 2011 11:13
glitch your display.
#!/usr/bin/env macruby
#
# MacRubyで画面グリッチをフルスクリーン表示する
#
# http://twitter.com/negipo/status/67572370247913473
#
# ## Usage
#
# ./glitch.rb
#
@kyoto
kyoto / coderwall.coffee
Created July 10, 2011 09:13
Coderwall Badge Script for Blogs (or any other Web Page)
# coderwall.coffee
# Display coderwall.com badges
username = "hermanjunge"
el = $(".coderwall")
$.getJSON "http://www.coderwall.com/#{username}.json?callback=?", (data) ->
el.empty()
for item in data.data.badges
$("<img>")
.attr(
@oyakata
oyakata / Compose.hs
Created September 8, 2011 16:16
Haskell: 関数の合成
module Compose where
-- 合成演算子 .
-- f . g = \x -> f (g x)
twice f = f . f
compose = foldr (.) id [map (*2), filter even]
composed = twice $ compose
composed2 = twice compose
-- これだけはコンパイルが通らない。
-- 理由は、composeにリストを渡した時点でcallableでなく値になってしまうから。