Tell Less to Not Freak Out in Certain Special Cases and Ignore Weird Characters

Tell LESS to not freak out in certain special cases and ignore weird characters

You can tell LESS to ignore characters like @ by using escaped strings like below:

It is basically like doing var a = "1+2"; in any programming language. It treats it as a string and doesn't perform any extra operations. But in LESS when we just provide "@RIGHT@", it gets printed with the quotes, to avoid the quotes we need to use the tilda character in front.

@right: ~"@RIGHT@";
@left: ~"@LEFT@";

div.somecls {
margin-@{right}: 15px;

&:after {
content: "\f061";
font-family: FontAwesome;
position: absolute;
border-@{left}: 10px;
top: 20px;
}
}
div.@{left}{
color: blue;
}

Demo


Update:

As mentioned in comments, earlier the above method would not work when the property-value pair is like @{left}: 10px. That is, when compiled it would not produce output as @LEFT@: 10px. This issue has now been fixed.

Git error when trying to push -- pre-receive hook declined

You should ask whoever maintains the repo at git@mycogit/cit_pplus.git.

Your commits were rejected by the pre-receive hook of that repo (that's a user-configurable script that is intended to analyze incoming commits and decide if they are good enough to be accepted into the repo).

It is also a good idea to ask that person to update the hook, so it would print the reasons for the rejection.

If the maintainer is you yourself, then it looks like you've got a problem with your setup on the server-side. Please share more information then.

how do i use ignore(), sync(), or clear() to clear out any data before using get line()?

Your code is almost correct, with couple of exceptions.

  1. you should not test for eof as a loop condition, see Why is iostream::eof inside a loop condition considered wrong?

  2. Declaring DynStrStk stringStk; inside the loop seems very fishy, as at the exit from the loop the variable cease to exist.

Here is a very simple program that uses a std::stack<std::string> instead, and which works, so the problem is probably in your DynStrStk implementation. There is no need to use cin.clear or cin.ignore as long as you're not mixing up cin and getline (in this latter case cin leaves a new line in the buffer which may end up "eaten" by `getline" in case you don't clear the stream).

#include <iostream>
#include <stack>
#include <string>
#include <fstream>

int main()
{
std::stack<std::string> stringStk; // stack of strings
std::ifstream normFile("test.txt"); // input file
std::ofstream output("out.txt"); // output file

std::string catchNewString;
while(getline(normFile,catchNewString)) // read and push to stack
{
stringStk.push(catchNewString); // push to stack
}

while(!stringStk.empty()) // dump the stack into the file
{
output << stringStk.top() << std::endl; // write it
stringStk.pop(); // remove
}
}

Again, you are not losing anything with the getline, nothing is lost in the buffer. There is an error probably when you loop over the individual characters in the string, in void parseFile(ifstream &inFile, fstream &normFile). One more thing: you use parseFile(inFile, normFile); then immediately createStack(normFile, outFile);. However, the normFile will have its position at the end (this is done by parseFile()), don't you need to rewind it before invoking createStack()?

try normFile.seekg(0, ios::beg); adter parseFile() and before createStack(). If it's not working, then try moving as much code as possible in independent functions and test each function step by step, or use a debugger and see live what's going on.

How can I check if a string represents an int, without using try/except?

If you're really just annoyed at using try/excepts all over the place, please just write a helper function:

def RepresentsInt(s):
try:
int(s)
return True
except ValueError:
return False

>>> print RepresentsInt("+123")
True
>>> print RepresentsInt("10.0")
False

It's going to be WAY more code to exactly cover all the strings that Python considers integers. I say just be pythonic on this one.



Related Topics



Leave a reply



Submit