Skip to content

Instantly share code, notes, and snippets.

View juno's full-sized avatar
💰
writing code (almost) every weekday

Junya Ogura juno

💰
writing code (almost) every weekday
View GitHub Profile
@juno
juno / PreloadHelper.php
Created July 26, 2008 02:12
Image preloading helper for symfony.
<?php
/**
* Returns a html to preload images using jQuery.
*
* @param array $urls An array of image URLs
* @return string HTML contents
*/
function preload_images($urls)
{
if (!is_array($urls)) {
@juno
juno / DIContainer.php
Created December 15, 2008 08:35
Simple DIContainer examples in PHP
<?php
class DIContainer
{
private $components = array();
/**
* 指定された名前でコンポーネントを登録します。
*
* @param string $name 登録する際の名前
* @param mixed $value コンポーネントとして登録する値
@juno
juno / decompose_conditional_before.php
Created February 13, 2009 07:55
Refactoring: Decompose Conditional (before)
if ($date->before(SUMMER_START) || $date->after(SUMMER_END)) {
$charge = $quantity * $this->winter_rate + $this->winter_service_charge;
} else {
$charge = $quantity * $this->summer_rate;
}
@juno
juno / decompose_conditional_after.php
Created February 13, 2009 07:57
Refactoring: Decompose Conditional (after)
if ($this->notSummer($date)) {
$charge = $this->winterCharge($quantity);
} else {
$charge = $this->summerCharge($quantity);
}
...
/**
* 指定された日付が夏以外かどうかを返します。
@juno
juno / tinyurlify.rb
Created February 14, 2009 08:15
URL shorten script. require: gem install shorturl
#!/usr/bin/env ruby
# -*- coding:utf-8; mode:ruby-mode -*-
require 'rubygems'
require 'shorturl'
ARGF.each do |line|
puts line.gsub(%r|(s?https?://[-_.!~*'a-zA-Z0-9;/?:@&=+$,%#]+)|) {|s| ShortURL.shorten($1)}
end
@juno
juno / generate_pdf.php
Created March 30, 2009 10:14
Japanese PDF generate example with PHP and libharu
<?php
// ドキュメントインスタンスを生成する
$doc = new HaruDoc;
// 日本語エンコーディングを利用する
$doc->useJPEncodings();
// 日本語フォントを利用する
$doc->useJPFonts();
// Jaml(http://github.com/edspencer/jaml) practice.
var sys = require('sys');
require('./Jaml-all');
Jaml.register('simple', function() {
div(
h1("Hello")
);
});
require 'ice_cube'
require 'active_support'
include IceCube
# 開始日を指定してScheduleインスタンスを生成
schedule = Schedule.new(Time.utc(2010, 7, 1))
# 2010年7月の5の付く日をスケジュールに追加
(5..30).step(5) do |day|
@juno
juno / brew install neon error log
Created November 1, 2010 04:18
brew install neon error log
$ brew install neon
==> Downloading http://www.webdav.org/neon/neon-0.29.3.tar.gz
File already downloaded and cached to /Users/juno/Library/Caches/Homebrew
==> ./configure --prefix=/usr/local/Cellar/neon/0.29.3 --disable-debug --enable-shared --disable-static --with-ssl
==> make install
/usr/bin/install -c -d /usr/local/Cellar/neon/0.29.3/include/neon
Installing ne_request.h into /usr/local/Cellar/neon/0.29.3/include/neon
/bin/sh ../libtool --quiet --mode=compile /usr/bin/cc -DHAVE_CONFIG_H -no-cpp-precomp -I.. -O3 -march=core2 -msse4.1 -w -pipe -c ne_request.c -o ne_request.lo
Installing ne_session.h into /usr/local/Cellar/neon/0.29.3/include/neon
Installing ne_utils.h into /usr/local/Cellar/neon/0.29.3/include/neon
@juno
juno / img2base64.rb
Created November 17, 2010 02:40
for ruby 1.9 / Usage: img2base64 [filename]
#!/usr/bin/env ruby
require 'base64'
f = open(ARGV[0])
data = f.read
f.close
puts "data:image/png;base64,#{Base64.encode64(data).gsub(/\n/, '')}"