Jun 17, 2010

iPhone 4 BLACK wearing Bumpers

Did you order iPhone 4? I ordered a black model. And I want to get Bumpers for iPhone 4. Writing Bumpers, Apple show us only white model wearing them. I couldn't have imagined the black model with Bumpers. So, I asked a designer to create the image. He created this.





You can see the large image here.

http://www.ariesplus.com/wordp/iphone/407.html

Which color do you like?

Jun 14, 2010

Use JavaScript-like "with" syntax in Ruby

JavaScript has "with" syntax. At first, I write a code without "with".


console.log(Math.cos(1/2)); //=> 0.8775825618903728
console.log(Math.sqrt(2)); //=> 1.4142135623730951



Then, I write with "with".


with(Math) {
console.log(cos(1/2)); //=> 0.8775825618903728
console.log(sqrt(2)); //=> 1.4142135623730951
}



On the other hand, Ruby has not "with" syntax.


puts Math.cos(1/2) #=> 1.0
puts Math.sqrt(2) #=> 1.4142135623731



Look! I can use "with" in Ruby!


with(Math) {
puts cos(1/2) #=> 1.0
puts sqrt(2) #=> 1.4142135623731
}



To do this, I wrote "with" function.


def with(obj, &block)
obj.instance_eval(&block)
end



So, I can use "with" syntax.


with(Math) {
puts cos(1/2) #=> 1.0
puts sqrt(2) #=> 1.4142135623731
}



Of course, other type of object is OK. String, Intger and so on.


with("I love Ruby.") {
puts reverse #=> .ybuR evol I
puts gsub(/Ruby/, "YUI") #=> I love YUI.
}



with(1) {
puts succ #=> 2
}

Jun 13, 2010

To buy, or not to buy: that is the question.

Pre-order of iPhone 4 start from the day after tomorrow in Japan. I can't make up my mind to buy. I bought Kindle DX two month ago and iPad last month. So I used a lot of money. As a developer, the high-resolution should be noted.


By the way, which is better, white or black? I thought iPhone should be black. But the white model is cool as for iPhone 4. Black or white: that is the question.


Oct 19, 2009

Amazon.com Larger Font Bookmarklet

I like to read book reviews in Amazon.com with iPhone.
Amazon.com show optimized pages for iPhone.
I think its font size is so small.
Then I made a bookmarklet.

Amazon.com larger font bookmarklet

You can view pages with larger font when you run this bookmarklet.



var e = document.getElementsByTagName('div');
var n = e.length;
for (var i = 0; i < n; i++) {
e[i].style.fontSize = '14px';
}

Oct 12, 2009

Making Web Application with Haskell #3

I make a web application with Haskell.
It's a simple application.
You input your name, then the application output your name.
See below.






The other day I made the application with Network.CGI.
Today I make it with Text.XHtml wich is included in GHC.



import Network.CGI
import Text.XHtml

inputForm :: Html
inputForm = form << [paragraph << "Who are you?",
textfield "name",
submit "" "send"]

greet :: String -> Html
greet n = h1 << ("Hello, " ++ n ++ "!")

page :: String -> Html -> Html
page t b = header << thetitle << t +++ body << b

cgiMain :: CGI CGIResult
cgiMain = do name <- getInput "name"
let x = maybe inputForm greet name
output $ renderHtml $ page "Hello" x

main :: IO ()
main = runCGI $ handleErrors cgiMain



This code is simpler than the previous code.

Oct 9, 2009

Making Web Application with Haskell #2

I make a web application with Haskell.
It's a simple application.
You input your name, then the application output your name.
See below.






The other day I made the application without any library.
Today I make it with Network.CGI wich is included in GHC.



import Network.CGI

inputForm :: String -> String
inputForm script = concat [
"<form action=\"", script, "\" method=\"GET\">",
"<p>Who are you?</p>",
"<input type=\"text\" name=\"name\" />",
"<input type=\"submit\" value=\"send\" />",
"</form>"]

putName :: String -> String
putName name = concat ["<h1>Hello, ", name, "!</h1>"]

body :: Maybe String -> String -> String
body name script =
case name of
Just x -> putName x
Nothing -> inputForm script

html :: Maybe String -> String -> String
html name script = concat [
"<html>",
"<head><title>Hello</title></head>",
"<body>",
body name script,
"</body>",
"</html>"]

cgiMain :: CGI CGIResult
cgiMain = do
setHeader "Content-type" "text/html; charset = UTF-8"
script <- scriptName
name <- getInput "name"
output $ html name script

main :: IO ()
main = runCGI (handleErrors cgiMain)



Complete!

Oct 7, 2009

Making Web Application with Haskell #1

I make a web application with Haskell.
It's a simple application.
You input your name, then the application output your name.
See below.






Today I make the application without any library.
I use standard input and output.



import System.Environment

inputForm :: String -> String
inputForm script = concat [
"<form action=¥"", script, "¥" method=¥"GET¥">",
"<p>Who are you?</p>",
"<input type=¥"text¥" name=¥"name¥" />",
"<input type=¥"submit¥" value=¥"send¥" />",
"</form>"]

getName :: String -> String
getName q = drop 5 q

main = do
putStrLn "Content-type: text/html; charset = UTF-8¥n"
putStrLn "<html>"
putStrLn "<head><title>Hello</title></head>"
putStrLn "<body>"
script <- getEnv "SCRIPT_NAME"
query <- getEnv "QUERY_STRING"
case query of
"" -> putStrLn $ inputForm script
_ -> putStrLn $ concat ["<h1>Hello, ", getName query, "!</h1>"]
putStrLn "</body>"
putStrLn "</html>"



Complete!

Oct 3, 2009

Sum from 1 to 10 without loop

Can you sum from 1 to 10 without loop? It's a programming quiz which is in now in Japan.

You may solve it with inject method in Ruby.


puts (1..10).inject(:+)


Is it not interesting? Then, I write it with continuation.


n, s = callcc {|$c| [1, 0] }
n, s = $c.call [n.succ, n + s] if n <= 10
puts s


Additionally, you can use recursion without loop.

Jun 27, 2009

Conway's Game of Life on your iPhone

You can try Conway's Game of Life on your iPhone.
It's some kind of artificial life simulation.

Life for iPhone (iTunes)







Life for iPhone (iTunes)

You will be able to keep seeing its mysterious pattern.

Jun 16, 2009

Fibonacci in Ruby

a method for Fibonacci number:

def fib(n)
if n < 2
1
else
fib(n - 2) + fib(n - 1)
end
end


result:

puts fib(10) #=> 89

Jun 12, 2009

I came back!

I'll write in this blog again.


class Programmer
def says(message)
puts message
end
end

shunsuk = Programmer.new
shunsuk.says "I came back!"

Nov 16, 2008

I Moved this blog

I move into WordPress from Blogger.

Protean [Henggen-Zizhai]

Nov 14, 2008

Difference between "do end" and "{ }" in Ruby

"{ }" has a stronger connection than "do end".


def foobar a, b
if block_given?
yield a, b
else
puts a * b
end
end



foobar is called with block.


foobar 2, 3 do |a, b|
puts a + b #=> 5
end



b is called with block.


def b
yield
end

foobar 2, b { 3 } #=> 6

Nov 13, 2008

Birthday Party

Today is my niece's birthday.
We're going to meet her.

Nov 12, 2008

Great Help of Vim

Type ":help!" when you get panick.

Sep 3, 2008

A Google Chrome's tab is on a process.

I tried this on a tab.

<html>
<body>
<button onclick="alert('not freese');">check</button>
<button onclick="for (var i = 0; ; i++) { };">freeze</button>
</body>
</html>


The tab froze.
But other tabs didn't freeze.


Then I tried this.

<html>
<body>
<button onclick="alert('not freese');">check</button>
<button onclick="for (var i = 0; ; i++) { alert(i); };">freeze</button>
</body>
</html>


Google Chrome can stop this script.
IE, Firefox and Safari can't stop this.

Aug 30, 2008

Help me! (JavaScript)

Regular expression.

<html>
<body>
<pre style="color:blue">
target
</pre>
<script type="text/javascript">
var m = document.body.innerHTML.match(/<pre[\w\s:;="]*>((.|\n)*)<\/pre>/g);
alert(m);
</script>
</body>
</html>

Firefox and Safari are OK.
But IE6 and IE7 are NG.
Why?

Aug 27, 2008

Boot Up Yourself with Ruby

I'm reading a book written about Ruby.
It's for biginers and easy to read.

Aug 22, 2008

Radiant CMS

I use Radiant CMS.
It's made of Ruby on Rails.

http://radiantcms.org/

It's difficult to use it.
I want some functions such as preview and file uploading.

Aug 17, 2008

You Can Do

You can do only what you can do.