How to swap text based on patterns at once with sed?
Maybe something like this: sed ‘s/ab/~~/g; s/bc/ab/g; s/~~/bc/g’ Replace ~ with a character that you know won’t be in the string.
Maybe something like this: sed ‘s/ab/~~/g; s/bc/ab/g; s/~~/bc/g’ Replace ~ with a character that you know won’t be in the string.
I’ll explain the main use cases of implicits below, but for more detail see the relevant chapter of Programming in Scala. Implicit parameters The final parameter list on a method can be marked implicit, which means the values will be taken from the context in which they are called. If there is no implicit value … Read more
Can I use ES6’s arrow function syntax with generators? You can’t. Sorry. According to MDN The function* statement (function keyword followed by an asterisk) defines a generator function. From a spec document (my emphasis): The function syntax is extended to add an optional * token: FunctionDeclaration: “function” “*”? Identifier “(” FormalParameterList? “)” “{” FunctionBody “}”
There is no semantic difference in the generic constraint language between whether a class ‘implements’ or ‘extends’. The constraint possibilities are ‘extends’ and ‘super’ – that is, is this class to operate with assignable to that other one (extends), or is this class assignable from that one (super).
It depends on how you want to access the import when you refer to it. from urllib import request # access request directly. mine = request() import urllib.request # used as urllib.request mine = urllib.request() You can also alias things yourself when you import for simplicity or to avoid masking built ins: from os import … Read more
The difference is that when you use from, the __cause__ attribute is set and the message states that the exception was directly caused by. If you omit the from then no __cause__ is set, but the __context__ attribute may be set as well, and the traceback then shows the context as during handling something else … Read more
Yes, they do completely different things. pass simply does nothing, while continue goes on with the next loop iteration. In your example, the difference would become apparent if you added another statement after the if: After executing pass, this further statement would be executed. After continue, it wouldn’t. >>> a = [0, 1, 2] >>> … Read more
I actually like MY JavaScript files to be validated, but I definitely don’t want to validate and deal with trivial warnings with third party libraries. That’s why I think that turning off validation all together is too drastic. Fortunately with Eclipse, you can selectively remove some JavaScript sources from validation. Right-click your project. Navigate to: … Read more
It makes it easier to generate source code, and also to write code which can be easily extended at a later date. Consider what’s required to add an extra entry to: int a[] = { 1, 2, 3 }; … you have to add the comma to the existing line and add a new line. … Read more
Use next: (1..10).each do |a| next if a.even? puts a end prints: 1 3 5 7 9 For additional coolness check out also redo and retry. Works also for friends like times, upto, downto, each_with_index, select, map and other iterators (and more generally blocks). For more info see http://ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html#UL.