In Phoenix web framework, there is a share directory /priv. By default, it
will only public css,js,images,fonts directory. However, If you want to share
a new directory to save upload image for example, you have to end_point file at
/lib/app_name/end_point.ex . Look at plug Plug.Static, the only: macro
declares which directory, files could be public. Simply, you have to append your
directory name at only:line.
This is my configuration to add a directory named avatar public. This directory
is under /priv/static.
plugPlug.Static,at:"/",from::blog_phoenix,gzip:false,only:~w(avatars css fonts images js favicon.ico robots.txt)### Other no need configurationend
defexport_search_resultrequire'spreadsheet'require'stringio'Spreadsheet.client_encoding='UTF-8'book=Spreadsheet::Workbook.newsheet1=book.create_worksheet#YOUR DATA PROCESSOR HEREfile_name="abc.xls"spreadsheet=StringIO.newbook.writespreadsheetsend_data(spreadsheet.string,:filename=>file_name,:type=>"application/vnd.ms-excel")end
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.
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
resources: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
sudo systemclt restart NetworkManager
After finished this step, firefox should work well
3. Remove cache in Google Chrome
## Go to ~/.cache/google-chromecd ~/.cache/google-chrome/Default
## remove file in Cache directoryrm Cache/*## remove file in Media Cache directoryrm Media\ Cache/*
4. Remove cached in Conkeror
## move to dir of conkeror cachecd ~/.cache/conkeror.mozdev.org/conkeror
## remove all cachedrm-rf*
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.
|-------------------------+--------------------+-------------+------------------------|
| Characteristics | Process | Block | Lambda |
|-------------------------+--------------------+-------------+------------------------|
| Object | yes | no | yes |
|-------------------------+--------------------+-------------+------------------------|
| Number of arguments* | many | 1 | many |
|-------------------------+--------------------+-------------+------------------------|
| Checking number of args | no | identifying | yes |
|-------------------------+--------------------+-------------+------------------------|
| Return behavior | affect outer scope | identifying | not affect outer scope |
|-------------------------+--------------------+-------------+------------------------|
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
|-------+-------+---------+--------|
| | Block | Process | Lambda |
|-------+-------+---------+--------|
| check | no | no | yes |
|-------+-------+---------+--------|
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.