January 2012
4 posts
1 tag
Darts, Dice, and Coins →
How do you simulate a dice? In javascript, It would be
function dice() {
return Math.floor(Math.random() * 6) + 1
}
So how about biased dices, for example returns 1 in probability 1/4, returns 2 in probability 1/9, and so on?
If you interested in, read this article.
The moon from earth is about 24.3px wide, for example. The Eiffel Tower from a...
– Antipodean: CSS px is an Angular Measurement
Edit: In CSS3, 1px=1/96in.
1 tag
Continuations: The Internet Is a Human Right →
What is internet? He says Internet is not just a technology, but a set of ground rules which enables us to build network. The network has no global control.
Here Be Monsters →
Three boys had drifted for 51 days without fish gears.
December 2011
4 posts
2 tags
Facebook looks to fix PHP performance with HipHop... →
They tune language rather than their code. They created translator (HipHop) which converts PHP into C++. To debug generated code, they wrote another interpreter for them (HPHPi). HPHPi is painfully slow, so they wrote virtual machine to run them (HPHPVM).
1 tag
Gamasutra - Features - Dirty Coding Tricks →
Several stories from frazzled and overworked programmers.
My favorite story is this.
This scene is familiar to all game developers: It’s the day we’re sending out the gold candidate for our Xbox 1 game. The whole team is playtesting the game all day long, making sure everything looks good. It’s fun, it’s solid, it’s definitely a go in our minds.
In the...
About the Metro design language →
Makes me want to try a Windows 8 phone…
November 2011
1 post
October 2011
4 posts
1 tag
3 tags
September 2011
2 posts
2 tags
3 tags
Four Word Passwords - xkcd #936
mosx:
onethingwell:
Here’s how to generate a quick four-worder from the command line:
shuf -n4 /usr/share/dict/words | tr -d '\n'
Source: Command Line Fu
Unfortunately this only works on Linux. On OS X we could use something like jot (which is mentioned on Command Line Fu as well), but here’s a rather convenient Perl solution:
perl -le 'chomp(@words= <>); print join " ", map...
August 2011
2 posts
4 tags
Removing Font Anti-Aliasing Bookmarklet
Played with -webkit-font-smoothing: none. It’s ugly, but kinda cute.
I wrote a bookmarklet to remove anti-aliasing anywhere. I checked this works on Chrome, but also on Safari it should work.
Edit: Recommend to try this on Google web fonts gallery.
3 tags
July 2011
3 posts
2 tags
2 tags
pdf.js reached its first milestone →
On Firefox. Its rendering on Chrome is still broken due to webkit’s bug but
Don’t you think it is beautiful somehow?
1 tag
June 2011
1 post
1 tag
Advice From An Old Programmer →
dhotson:
Some insightful closing remarks in “Learn Python The Hard Way, 2nd Edition”.
This was a good morning read to me.
May 2011
1 post
1 tag
April 2011
2 posts
3 tags
Climb That Mountain: Running Rails Rspec Tests -... →
Stubbing will win?
March 2011
2 posts
3 tags
February 2011
3 posts
1 tag
Little-known options for the OS X login window →
OS X has supported several “special” login names for a long time. Each is entered into the “Name” field with no password. They are:
>restart
>shutdown
>sleep
>console
1 tag
January 2011
1 post
2 tags
Tools I got from railstutorial.org
I read Rails Tutorial Book online, to dive into
Agile Development with Rails.
I really enjoyed it and filled my tool box with tools to run agile
developments as follows.
Tools for Test Driven Development
rspec + webrat for writing test with nice DSL
autotest to continuing running test
spork to preload application and running test
running test via --drb is another reason to use rspec
...
December 2010
1 post
Refinements in Ruby — Timeless from Magnus Holm →
The great thing about refinements, is that it’s technically impossible to globally leak them. They will always be restricted to the scope you specify, and there’s nothing “above” the file scope. That’s not always true though. Refinements are also enabled in subclasses and reopened classes, even if they are located in different files.
November 2010
1 post
1 tag
October 2010
1 post
September 2010
1 post
4 tags
monoidal: Algorithms and functions →
August 2010
2 posts
2 tags
jQuery anywhere
I wrote bookmarklet to Load jQuery anywhere on the internet.
Source:
javascript:(function (D) {
if (typeof jQuery !== 'undefined') { return; }
var s = D.createElement('script')
, t = D.body;
s.onload = function () { $.noConflict(); };
s.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js";
t.appendChild(s);
})(document)
I want to read jQuery’s source in...
1 tag
Yet Another Boring irb session
It shows how Ruby is stable.
irb(main):001:0> arr = []
=> []
irb(main):002:0> arr.push(arr)
=> [[...]]
irb(main):003:0> arr
=> [[...]]
irb(main):004:0> arr.flatten
ArgumentError: tried to flatten recursive array
from (irb):4:in `flatten'
from (irb):4
from /usr/local/bin/irb:12:in `<main>'
irb(main):005:0> arr.first
=>...
July 2010
21 posts
1 tag
Boring irb session
Today’s Boring irb session is about Hash::[].
>> Hash[]
=> {}
>> Hash[1,2]
=> {1=>2}
>> Hash[1,2,3,4]
=> {1=>2, 3=>4}
>> Hash[[1,2,3,4]]
=> {}
>> Hash[[1,2,3,4].map{|e| [e,e]}]
=> {1=>1, 2=>2, 3=>3, 4=>4}
1 tag
1 tag
On Camping vs Sinatra →
i5m:
Magnus Holm’s email to the Hackety Hack mailing list. His email is written in Ruby so you can download and run it. Mind blown.
And I don’t know %% and %%%%% can be used as quotations.
$ irb
>> %%
foo
%%%%%
=> "\nfoo\n"
2 tags
Enumerable#by
Reinvention of wheel of someone.
module Enumerable
def by(step, &block)
e = each
n = step
Enumerator.new do |y|
loop {
n -= 1
obj = e.next
if n == 0
n = step
y << (block ? block.call(obj) : obj)
end
}
end
end
end
if $0 == __FILE__
p 1.upto(10).by(2).to_a
p 1.upto(100).by(3).select { |i| i % 5 == 0...
1 tag
rbJL.net · 27 · New Array and Enumerable methods... →
flat_map and its alias collect_concat
This method works like map, but if an element is an Enumerable itself, the applied block is also run for each of its child elements (but not recursively).
[[1,2],[3,[4,5]]].flat_map{|i|i} #=> [1, 2, 3, [4,5]]
I do not know (yet), if this is useful (and if it wouldn’t be cooler if it did something like .flatten.map), but we will see…
I...
A Coder's Guide to Coffee →
(via dhotson)
I was about to start subscribing alt.coffee but the group is filled with spam posts…
2 tags
comparing combinator in Ruby
You may enjoy this gist, if you know both Ruby and Haskell.
1 tag
What is Cross Site Request Forgery
This summary is written by knowledge from 30 minutes of reading wikipedia and this blog post. It may include a lot of misunderstanding and incorrectness. Don’t trust it. Correct me if I’m wrong. I write this post to let me understand CSRF.
CSRF is attack to have users of website send request to the website which specified by attacker.
Attacker can do CSRF on an action of website if...
3 tags
1 tag
A Strange Haskell Value (It can be Int and Bool)
I released a Haskell library “has”, for creating type-indexed records in a casual way. Its usage is described here.
I will show another usage of this library. It is too trivial to write
in documentation but attracting to me in its strangeness:
{-# LANGUAGE TypeFamilies,TypeOperators,FlexibleContexts #-}
import Data.Has
data Any = Any
intBool = prjl Any (Any .> (42::Int) &...
3 tags
Bane -- A test harness for socket connections →