blog已搬家

前几天把blog给搬到github上去了,新链接是 http://hzmangel.github.io/
此处文章不再更新,但是站点目前还会保留。

发表在 杂九杂十^_^ | 留下评论

Control Goroutines amount via bufferred channel

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

继续阅读

发表在 Happy coding | 标签为 , | 留下评论

Golang and JSON API

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

继续阅读

发表在 Happy coding | 标签为 , | 留下评论

goroutines + channel

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

继续阅读

发表在 Happy coding | 标签为 , | 一条评论

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.

继续阅读

发表在 Happy coding | 标签为 , , , | 留下评论

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]
  ]
]
发表在 Happy coding | 标签为 , , | 留下评论

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.

继续阅读

发表在 Happy coding | 标签为 | 留下评论

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.

继续阅读

发表在 Happy coding | 标签为 , | 留下评论

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.

继续阅读

发表在 Happy coding | 标签为 , | 留下评论

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.
继续阅读

发表在 Happy coding | 标签为 , | 留下评论