Control Goroutines amount via bufferred channel

最近还是在写爬虫,然后发现用goroutine是很快,但是很容易就碰到并发数过多被服务器限制的问题。虽然说让goroutine在起来前睡一小会能解决一些问题,但是终归感觉这样的办法不靠谱。继续翻文档发现bufferred channel用在这不错。

Continue reading

Posted in Happy coding | Tagged , | Leave a comment

Golang and JSON API

最近在尝试用golang做爬虫类的东西,避免不了需要处理JSON API。其间碰到了些问题,记在这里以便下次查阅。

Continue reading

Posted in Happy coding | Tagged , | 1 Comment

goroutines + channel

channel是golang里面一个比较有意思的东西,可以把它看成是一个semaphone(无缓存版队列)或者FIFO(有缓存版队列)。这篇文章只是把最近用到的一些东西归纳了一下,就算是给自己留份存档吧。

Continue reading

Posted in Happy coding | Tagged , | 1 Comment

Save base64 image with carrierwave and bootstrap-wysiwyg

tl;dr

The pasted image will be converted to base64 encoded format, which will hit response size limitation of server. This article is talking about save image to file with carrierwave.

The source code is available at github repo

Next is the full version.

Continue reading

Posted in Happy coding | Tagged , , , | 1 Comment

Ajax loading multi series to jqPlot

The Ajax example of jqPlot only shows how to plot on series data, but the request I have met needs multi series.
The solution is easy, just record here for later reference.

In the example, The function used to load ajax data is ajaxDataRenderer, which returns array of data.
For multi series, just return more than one data array. Here is a sample data set:

[
  [
    [1,1],[2,2],[3,3],[4,4],[5,5]
  ],
  [
    [5,1],[4,2],[3,3],[2,4],[1,5]
  ]
]
Posted in Happy coding | Tagged , , | Leave a comment

Some failed attempts on PNaCl

Google has released his PNaCl project on Google I/O 2013, which can allow user to write portable native client application.
The portable native client application can be translated to native client program and executed on supported architecture.

The official toolchain contains clang frontend, which can only be used to compile C/C++ code to PNaCl application.
But the PNaCl application is a subset of LLVM so I have tried some other languages have LLVM frontend.
I am still working on the solution, and this article is just recording some failed attempts.

Continue reading

Posted in Happy coding | Tagged | 1 Comment

Uploading multiple attachments with carrierwave/mongoid/nested_form

Recently I have met a requirement that need to upload multiple attachments to a rails project. After some investigations, I choose carrierwave finally. Also, I selected nested_form to manage uploading and deleting multiple attachments.

Continue reading

Posted in Happy coding | Tagged , | Leave a comment

Using Rails with Redis

I have met an issue recently that the Rails site always returns 502 error for some page. After some investigation, I have found that the problem is caused by a long time query of database, which exceeds the timeout value of unicorn configuration, then the unicorn worker process will be killed and the Nginx returns 502 to user.

So the solution for this kind prblem is to put the job into some background task, and use some other method to inform the frontend when job done. Finally I choose the Redis for this task.

Continue reading

Posted in Happy coding | Tagged , | Leave a comment

iOS Code Snippets – UITableView

Just created a project on BitBucket to save some iOS code snippets, and the first project is a simple UITableViewController one. The code is placed at http://goo.gl/0ZrcA. The text above is the introduction text for that project, please reference the code for detailed information.
Continue reading

Posted in Happy coding | Tagged , | Leave a comment

@property and its attributes

Recently working on iOS project, and have met some problems while using the attributes of @property.
I have searched some documents and here is my idea about this.

Continue reading

Posted in Happy coding | Tagged , | Leave a comment