Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Here is a sample comment I'm trying to sanitize:
"<p><strong>hello</strong><em></em> <em>there</em> whats up?</p><p><ul><li>this </li><li>is a</li><li>list</li></ul><p>and then there was more</p><p><ol><li>do this</li><li>do that</li></ol><p><img src=\"https://google.com\" alt=\"\"><br></p></p></p>"
I tried sanitizing with this command:
sanitize comment.text, tags: %w(p, strong, em, a, blockquote, img, ol, ul, li), attributes: %w(href, target, title)
Output is:
"hello there whats up?<li>this </li><li>is a</li><li>list</li>and then there was more<li>do this</li><li>do that</li>"
As you can see the li elements aren't nested in their respective ordered and unordered lists, and all the other tags I tried to permit are removed too.
When using the special array creators (such as %w() you don't want to use commas:
%w(p, strong, em, a, blockquote, img, ol, ul, li)
# => ["p,", "strong,", "em,", "a,", "blockquote,", "img,", "ol,", "ul,", "li"]
Remove those and things should start working for you. (You'll note that li worked, because as the last element, it didn't contain a trailing comma)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 5 years ago.
Improve this question
I'm a super beginner with latex, so please be patient and don't assume I know anything, thanks!
Using Overleaf.com I'm trying to create a CV based on this template:
https://www.latextemplates.com/template/awesome-resume-cv
However, the "skills" section does not behave the way I expected it: if I write a long list of skills, the words go beyond the page limit on the right instead of starting a new line. How do I fix this?
I tried by using \\ to end the line, but that gives a syntax error.
Thank you!
I just tried to follow the problem you describe. In order to do that I created to sample lists of skills:
\cvskill
{Sample} % Category
{Sample A, Sample B, Sample C, Sample D, Sample E, Sample F, Sample G, Sample H, Sample I, Sample J, Sample K, Sample L, Sample M, Sample N, Sample O} % Skills
\cvskill
{Sample 2} % Category
{Averylongskillnamethatmayexceedthepage A, Averylongskillnamethatmayexceedthepage B, Averylongskillnamethatmayexceedthepage C, Averylongskillnamethatmayexceedthepage D, Averylongskillnamethatmayexceedthepage E, } % Skills
After compiling the skills section looks as follows:
So according to my view line breaks are added correctly. In case you are annoyed by slightly overarching text items like "Sample K" you can add a \newline before the corresponding item to force a manual line break.
The \ command is no 'line ending' symbol and even the command \\ which does exactly this should not work, as the cvskill command internally uses a tabular environment, which accepts the \newline command but not \\.
In case I missed to solve your problem please provide a more extensive problem description including a valid and recreateable example! Otherwise it's very complicated to narrow down the exact issue you have.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
"Rubymonk Is Pretty Brilliant".match(/ ./, 9)
How is the answer "P" calculated from this regex?
use the match method on the string
passes two arguments, a regular expression and the position in the string to begin the search.
returns the character 'P'
The criteria you posted from the Rubymonk grader answer this succinctly:
passes two arguments, a regular expression and the position in the
string to begin the search
But let's examine that in more detail. match is being passed two arguments:
/ ./, a regular expression
9, the starting position in the string
The regular expression tells us that we're looking for a space () followed by any character (.).
The starting position tells us to start at position 9 (I). So instead of applying that regex against "Rubymonk Is Pretty Brilliant", we're applying it against "Is Pretty Brilliant".
In the string "Is Pretty Brilliant", where is the first place we encounter a space followed by another character? "Is[ P]retty Brilliant", right? Thus match finds a result of P (that's space-P, matching the regex, not just P.)
To see this more clearly and to experiment further with regexes, you can try it in an irb session or in your browser using Rubular.
(Just google for RegEx + ruby, You will find explanation of regex syntax)
/ANYTHING-HERE/
Will look for ANYTHING-HERE in the text.
In Your example its (/ ./,9):
/SPACE DOT/
So it will look for space followed by single character (Dot -> single character).
9 will be "I" from the string. And that is not space, so it will go on 2 characters right. Will find space, and then will find single character "P".
That is the result.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have following strings:
1) Beach Cottage (CP)
2) Beach Cottage (AP)
3) Cotta (GAP)
And I want to get substing between ( ) that is from first CP
Try this for example:
str = "Beach Cottage (CP)"
str.match(/(\((.*)\))/)[2]
you can use scan also with regx:
str = "Beach Cottage (CP)"
needed_sub_str = str.scan(/\((.*)\)/)
puts "expected sub string :: #{needed_sub_str}"
Output ::
expected sub string :: CP
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
In the spirit of:
Hidden Features of C#
Hidden Features of Java
Hidden Features of ASP.NET
Hidden Features of Python
Hidden Features of HTML
and other Hidden Features questions
What are the hidden features of Erlang that every Erlang developer should be aware of?
One hidden feature per answer, please.
Inheritance! http://www.erlang.se/euc/07/papers/1700Carlsson.pdf
Parent
-module(parent).
-export([foo/0, bar/0]).
foo() ->
io:format("parent:foo/0 ~n", []).
bar() ->
io:format("parent:bar/0 ~n", []).
Child
-module(child).
-extends(parent).
-export([foo/0]).
foo() ->
io:format("child:foo/0 ~n", []).
Console
23> parent:foo().
parent:foo/0
ok
24> parent:bar().
parent:bar/0
ok
25> child:foo().
child:foo/0
ok
26> child:bar().
parent:bar/0
ok
The magic commands in the shell. The full list is in the manual, but the ones I use most are:
f() - forget all variables
f(X) - forget X
v(42) - recall result from line 42
v(-1) - recall result from previous line
e(-1) - reexecute expression on previous line
rr(foo) - read record definitions from module foo
rr("*/*") - read record definitions from every module in every subdirectory
rp(expression) - print full expression with record formating
Parameterized Modules! From http://www.lshift.net/blog/2008/05/18/late-binding-with-erlang and http://www.erlang.se/euc/07/papers/1700Carlsson.pdf
-module(myclass, [Instvar1, Instvar2]).
-export([getInstvar1/0, getInstvar2/0]).
getInstvar1() -> Instvar1.
getInstvar2() -> Instvar2.
And
Eshell V5.6 (abort with ^G)
1> Handle = myclass:new(123, 234).
{myclass,123,234}
2> Handle:getInstvar1().
123
3> Handle:getInstvar2().
234
user_default.erl - you can build your own shell builtins by having a compiled user_default.beam in your path which can be pretty nifty
beam_lib:chunks can get source code from a beam that was compiled with debug on which can be really usefull
{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(Beam,[abstract_code]).
io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]).
Ports, external or linked-in, accept something called io-lists for sending data to them. An io-list is a binary or a (possibly deep) list of binaries or integers in the range 0..255.
This means that rather than concatenating two lists before sending them to a port, one can just send them as two items in a list. So instead of
"foo" ++ "bar"
one do
["foo", "bar"]
In this example it is of course of miniscule difference. But the iolist in itself allows for convenient programming when creating output data. io_lib:format/2,3 itself returns an io list for example.
The function erlang:list_to_binary/1 accepts io lists, but now we have erlang:iolist_to_binary/1 which convey the intention better. There is also an erlang:iolist_size/1.
Best of all, since files and sockets are implemented as ports, you can send iolists to them. No need to flatten or append.
That match specifications can be built using ets:fun2ms(...) where the Erlang fun syntax is used and translated into a match specification with a parse transform.
1> ets:fun2ms(fun({Foo, _, Bar}) when Foo > 0 -> {Foo, Bar} end).
[{{'$1','_','$2'},[{'>','$1',0}],[{{'$1','$2'}}]}]
So no fun-value is ever built, the expression gets replaced with the match-spec at compile-time. The fun may only do things a match expression could do.
Also, ets:fun2ms is available for usage in the shell, so fun-expressions can be tested easily.
.erlang_hosts gives a nice way to share names across machines
Not necessarily "hidden", but I don't see this often. Anonymous functions can have multiple clauses, just like module functions, i.e.
-module(foo).
-compile(export_all).
foo(0) -> "zero";
foo(1) -> "one";
foo(_) -> "many".
anon() ->
fun(0) ->
"zero";
(1) ->
"one";
(_) ->
"many"
end.
1> foo:foo(0).
"zero"
2> foo:foo(1).
"one"
3> foo:foo(2).
"many"
4> (foo:anon())(0).
"zero"
5> (foo:anon())(1).
"one"
6> (foo:anon())(2).
"many"
The gen___tcp and ssl sockets have a {packet, Type} socket option to aid in decoding a number of protocols. The function erlang:decode_packet/3 has a good description on what the various Type values can be and what they do.
Together with a {active, once} or {active, true} setting, each framed value will be delivered as a single message.
Examples: the packet http mode is used heavily for iserve and the packet fcgi mode for ifastcgi. I can imagine that many of the other http servers use packet http as well.
.erlang can preload libraries and run commands on a shells startup, you can also do specific commands for specific nodes by doing a case statement on node name.
If you want to execute more than one expression in a list comprehension, you can use a block. For example:
> [begin erlang:display(N), N*10 end || N <- lists:seq(1,3)].
1
2
3
[10,20,30]
It is possible to define your own iterator for QLC to use. For example, a result set from an SQL query could be made into a QLC table, and thus benefit from the features of QLC queries.
Besides mnesia tables, dets and ets have the table/1,2 functions to return such a "Query Handle" for them.
Not so hidden, but one of the most important aspects, when chosing Erlang as platform for development:
Possibility of enhanced tracing on live nodes (in-service) and being one of the best in debugging!
You can hide an Erlang node by starting it with:
erl -sname foo -hidden
You can still connect to the node, but it won't appear in the list returned by nodes/0.
Matching with the append operator:
"pajamas:" ++ Color = "pajamas:blue"
Color now has the value "blue". Be aware that this trick has it’s limitations - as far as I know it only works with a single variable and a single constant in the order given above.
Hot code loading. From wiki.
Code is loaded and managed as "module" units, the module is a compilation unit. The system can keep two versions of a module in memory at the same time, and processes can concurrently run code from each.
The versions are referred to the "new" and the "old" version. A process will not move into the new version until it makes an external call to its module.