Skip to content

Instantly share code, notes, and snippets.

:atom:
writing code everyday

Junya Ogura juno

:atom:
writing code everyday
View GitHub Profile
@juno
juno / PreloadHelper.php
Created Jul 26, 2008
Image preloading helper for symfony.
View PreloadHelper.php
<?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 Dec 15, 2008
Simple DIContainer examples in PHP
View DIContainer.php
<?php
class DIContainer
{
private $components = array();
/**
* 指定された名前でコンポーネントを登録します。
*
* @param string $name 登録する際の名前
* @param mixed $value コンポーネントとして登録する値
@juno
juno / decompose_conditional_before.php
Created Feb 13, 2009
Refactoring: Decompose Conditional (before)
View decompose_conditional_before.php
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 Feb 13, 2009
Refactoring: Decompose Conditional (after)
View decompose_conditional_after.php
if ($this->notSummer($date)) {
$charge = $this->winterCharge($quantity);
} else {
$charge = $this->summerCharge($quantity);
}
...
/**
* 指定された日付が夏以外かどうかを返します。
@juno
juno / tinyurlify.rb
Created Feb 14, 2009
URL shorten script. require: gem install shorturl
View tinyurlify.rb
#!/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 Mar 30, 2009
Japanese PDF generate example with PHP and libharu
View generate_pdf.php
<?php
// ドキュメントインスタンスを生成する
$doc = new HaruDoc;
// 日本語エンコーディングを利用する
$doc->useJPEncodings();
// 日本語フォントを利用する
$doc->useJPFonts();
View jaml-practice.js
// Jaml(http://github.com/edspencer/jaml) practice.
var sys = require('sys');
require('./Jaml-all');
Jaml.register('simple', function() {
div(
h1("Hello")
);
});
View example1.rb
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 Nov 1, 2010
brew install neon error log
View 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 Nov 17, 2010
for ruby 1.9 / Usage: img2base64 [filename]
View img2base64.rb
#!/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/, '')}"
You can’t perform that action at this time.