Skip to content

Instantly share code, notes, and snippets.

@maraigue
maraigue / CodeJP2014golf.md
Last active August 29, 2015 14:05
CodeJP 2014のコードゴルフの私の回答
# https://github.com/maraigue/cpp-chinese-postman を
# JR全線(jr-all.edges)を対象に解いた結果
# 路線網の分割には jr-all-division-example.edges を利用
#
# JR全線:19860.5km(間違いがあるかも)
# 二度乗車する区間(以下の一覧の合計):5729.7km
# 合計:25590.2km
#
# 以下の一覧における距離の単位は「0.1km」
# ------------------------------------------------------------
@maraigue
maraigue / explore.rb
Created December 15, 2014 15:01
格子状のマップを上下左右に動いてゴールを目指すプログラム
def create_field(str)
str = str.gsub(/\A\n+|\n+\z/, "")
str.split("\n").map{ |line| line.split(//) }
end
def find_start_goal(field)
result = {}
field.each_with_index do |line, i|
line.each_with_index do |cell, j|
if cell == "S" || cell == "G"
#include <iostream>
class Hoge{
const int v;
public:
Hoge(int x) : v(x * 5) {} // 問題なく動作
//Hoge(int x) { v = x * 5; } // 不可
int value(){ return v; }
};
@maraigue
maraigue / PDFfill.rb
Last active August 29, 2015 14:13
「1ページに、指定されたPDFの複数ページを印刷する」形式のPDFを作る
#!/usr/bin/env ruby
require 'tmpdir'
require 'fileutils'
# このスクリプトができること
#
# 「1ページに、指定されたPDFの複数ページを印刷する」形式のPDFを作る。
# 隙間なく敷き詰められる。
# 「横に何列並べるか」と「元のPDFのページの縮小率」が指定できる。
@maraigue
maraigue / TheTumblrThemeLikeATwitter.html
Created August 14, 2008 06:31 — forked from june29/TheTumblrThemeLikeATwitter.html
Fixed source of gist:4089 [Tumblr theme (design like Twitter)]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss"/>
<link rel="shortcut icon" href="{Favicon}">
<link type="text/css" rel="stylesheet" media="screen" href="http://libelabo.jp/stylesheets/screen.css"/>
<title>{Title}</title>
<style type="text/css">
@maraigue
maraigue / tinyurl.rb
Created September 14, 2008 06:02
TinyURL library for Ruby
require 'net/http'
require 'cgi'
Net::HTTP.version_1_2
module TinyURL
module_function
# Makes a URL short via TinyURL.com.
# returned value is the key of TinyURL.com.
@maraigue
maraigue / toshigo.rb
Created January 16, 2009 09:46
年子平方数
class Integer
def toshigo?
# return nil if self <= 0
s = self.to_s
l = s.length
return false if l % 2 != 0
((s[0...(l/2)].to_i) - (s[(l/2)..-1].to_i)).abs == 1
end
@maraigue
maraigue / TumblrTheme[h-hiro.tumblr.com].html
Created January 19, 2009 05:03
h-hiro.tumblr.com で用いているテーマ
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<!-- DEFAULT COLORS -->
<meta name="color:Background" content="#fff"/>
<meta name="color:Title" content="#444"/>
<meta name="color:Description" content="#777"/>
<meta name="color:Post Title" content="#6498cc"/>
<meta name="color:Text" content="#444"/>
@maraigue
maraigue / URLencode-Ruby1.9.rb
Created January 28, 2009 05:36
Ruby1.9勉強中:URLエンコード
#!/usr/bin/env ruby1.9
# -*- coding: utf-8 -*-
def URLencode(str)
str.force_encoding("binary").gsub(/\W+/){ |x| x.unpack("C*").map{ |y| sprintf("%%%02X", y) }.join }
end
puts URLencode("ほげ")