I have work with spreadsheet gem on ruby, Sometime I do realize that in the
LibreOffice, the content is something like '24%, the character single quote
refers to a string. However, I want a number instead. A possible way to convert
them without programming is Find and Replace. However it does not easy as I
say because the character ' is a special character in LibreOffice, you have to
use regular expression to work with this.
There is a solution to convert string to number in such case is using replace
function name Find and Replace C-h in LibreOffice. In the Search for text,
type ^.; in the Replace with, type $. In the other options, please tick on
Regular expressions. Finally, you can choose replace or replace all.
Given that, you have to work with many decimal number for example: 0.335, 0.345,
0.2, 96.6666. And then you want to round those number 2 digits after decimal.
The most general way is to used toFix(). However, the behavior of toFix() is
not good. Let test with value 0.335 and 0.345.
The better solution is that, we try to use the first two digit after decimal, the only issue is that, these two digit up/down are depend on the third digit, perhaps the fifth one. Number 44 is to solve this issue. Any number x.a-b-c-d which has c-d >= 56, the b will be round up by one.
A good solution come up with a compact function which can help you use in any time.
Rails does support built-in CRUD with RESTful. It provides default url for
developers. However, there could be a time that developer want to add more
method/action to work with exist routes. Hence, this is solution.
This is a default setting for resources of pictures
This is modification with new upload method which use GET protocol.
My browsers always automatically redirect to advertise website. That’s a pain in
my ass. In particular, While I am reading software API, it change my current
pages to another ad pages. Seemingly, someone did change my default dns to
advertise dns server.
1. Change the DNS
Set the current dns to google dns: 8.8.8.8, 8.8.4.4
2. Reset the Network Manager
After finished this step, firefox should work well
There are three ways to group trunk of code in Ruby which are block,
process and lambda. Each of them behave differently from others. This post
is all about the differences of them and its examples and use cases.
Basic usage
Object or not
Block is not an object, cannot execute directly, it need to be passed to a method
Proc and Lambda are objects, its instance can be execute directly
Number of block, proc and lambda passed in parameter field
Block: A method can use only one block which passed in the parameter fields.
Well, obviously, block is a kind of anonymous function. If there are two
passing in parameter field. How could interpreter understand when should it
use this or that block. Meanwhile, a method can only use one block or
anonymous function which is passed in parameter field.
Proc and Lambda: In fact, these two are identical and it’s object
instances. On the other words, you are passing object in parameter field. Hence,
pass them as many as you want.
Return behaviour
Block: return cannot be used within a block. Here is an article about
block break and next behaviours
Lambda: return instruction within a block only suspend instruction execute within
the block. It does not suspend outer method.
Process: return instruction also affect the outer scope. It suspends the
outer method directly.
Checking number of arguments passing to block, process, lambda
During this time, I am in an internship program. There is a big concern, I have
to work with a very big project, and there is no documentation. The number of
tables in project’s database is more than 20, still no documentation.
A big nightmare for an intern one. It’s important to make an entity relationship
diagram, at least with a hope that I can get cope easily with the project.
Configuration file will be loaded at ~/.erdconfig or
...project_rails/.erdconfig, file config in the root of project will take
higher priority than in the home directory.
Generating entity diagram file
Entity diagram will be generated in the root directory of project.
Highchart is a common javascript library which use to display graph with many
beautiful features, however, there is a small need in use of highchart.js. It’s
about having dual yAxis, and how to balance common zero between two yAxis.
There is no built-in feature that can help you deal with this solution but
changing the min, max value via setExtremes() method.
I did write a small method which can help solve this problem, small but
achievable.
github
How to use
Given that, on the html there is a div which is used for highcharts, this div
is only for rendering graph for example $("#graph")
After include the balancezero.js, you can test by running the command on the
web console balanceZeroRoot(dom_element) or for example balanceZeroRoot($("#graph"))
By default, there is exist behavior for show and hide plots, you need to
modify those default behavior to work with balancezero.js. For each kind of
graph, there is exist option name legendItemClick for example
link
In addition, there is also a need to load balanceZeroRoot() right after
data loaded. There are many kind of graph, the code below is an example about
charttype
Note
The demand to have common zero for dual yAxis has been there for 2 years
link
, however there is no good solution which fit for me even the one from the admin
of highcharts, the plugin does not work perfectly.