This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# -*- coding: utf-8 -*- | |
$KCODE = 'u' | |
require 'csv' | |
File.open('tmp.csv', 'wb') do |csv_file| | |
# 输出标明文本编码为 UTF-8 的 BOM | |
csv_file.write("\xEF\xBB\xBF") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Pretty prints a Scala value similar to its source represention. | |
* Particularly useful for case classes. | |
* @param a - The value to pretty print. | |
* @param indentSize - Number of spaces for each indent. | |
* @param maxElementWidth - Largest element size before wrapping. | |
* @param depth - Initial depth to pretty print indents. | |
* @return | |
*/ | |
private def prettyPrint(a: Any, indentSize: Int = 2, maxElementWidth: Int = 30, depth: Int = 0): String = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'eventmachine' | |
require 'em-http-request' | |
require 'patron' | |
f = Time.now | |
arr = [] | |
j = 50 | |
EventMachine.run do | |
(1..50).each{|i| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App.db.collection('apps').find({'name' => 'test_name'},{:timeout => false}){|ptr| ptr.each{|x| puts x['user_id']}} | |
# NOTE in cursor iteration | |
ptr.each{|x| | |
x.user_id # WRONG | |
x['user_id'] # RIGHT | |
} |