Skip to content

Instantly share code, notes, and snippets.

View digitalsonic's full-sized avatar

DigitalSonic digitalsonic

View GitHub Profile
@digitalsonic
digitalsonic / gist:3747876
Created September 19, 2012 05:42
Try to make an OOM while reading file with an extream large buffer.
package demo;
import java.io.File;
import java.io.FileInputStream;
/**
* Run the demo on Linux with 32-bit JVM
* Add the command line parameters -Xmx1600m -Xms1600m.
*
* readBigBuffer should fail with OOM.
@digitalsonic
digitalsonic / prime.rb
Created September 15, 2012 14:01
求某个范围内素数的个数
# 求某个范围内素数的个数
# 最大值不要超过1亿
def prime max_number
nums = Array.new(max_number + 1, 1)
sqrt_num = Math.sqrt(max_number).to_i
(4...max_number).step(2) { |n| nums[n] = 0 }
(3...sqrt_num).step(2) { |n| (n * 2...(max_number + 1)).step(n) { |m| nums[m] = 0 } if (nums[n] == 1) }
return nums.count(1) - 2 # 去掉nums[0]和nums[1]
end