Can I Output a Raw String in LESS? - less

I am interested in getting a small portion of my LESS file to appear in my processed CSS file without having to be recognized as valid LESS. Is there a way to do that?

LESS has an escape syntax that uses double-quoted strings prefixed with ~, will that work?
In the documentation example:
.class {
filter: ~"ms:alwaysHasItsOwnSyntax.For.Stuff()";
}
gets output as
.class {
filter: ms:alwaysHasItsOwnSyntax.For.Stuff();
}

Related

Perl6 regex not matching end $ character with filenames

I've been trying to learn Perl6 from Perl5, but the issue is that the regex works differently, and it isn't working properly.
I am making a test case to list all files in a directory ending in ".p6$"
This code works with the end character
if 'read.p6' ~~ /read\.p6$/ {
say "'read.p6' contains 'p6'";
}
However, if I try to fit this into a subroutine:
multi list_files_regex (Str $regex) {
my #files = dir;
for #files -> $file {
if $file.path ~~ /$regex/ {
say $file.path;
}
}
}
it no longer works. I don't think the issue with the regex, but with the file name, there may be some attribute I'm not aware of.
How can I get the file name to match the regex in Perl6?
Regexes are a first-class language within Perl 6, rather than simply strings, and what you're seeing here is a result of that.
The form /$foo/ in Perl 6 regex will search for the string value in $foo, so it will be looking, literally, for the characters read\.p6$ (that is, with the dot and dollar sign).
Depending on the situation of the calling code, there are a couple of options:
If you really are receiving regexes as strings, for example read as input or from a file, then use $file.path ~~ /<$regex>/. This means it will treat what's in $regex as regex syntax.
If you will just be passing a range of different regexes in, change the parameter to be of type Regex, and then do $file.path ~~ $regex. In this case, you'd pass them like list_files_regex(/foo/).
Last but not least, dir takes a test parameter, and so you can instead write:
for dir(test => /<$regex>/) -> $file {
say $file.path;
}

Do grammar subparse on a file

Let's say you only want to parse the start of a large file using Perl 6 grammar. In order to avoid reading the whole file into a string, and then call subparse on the string. Is it possible to do a subparse when reading the file?
I could not find any subparsefile() method in the Grammar class, so I guess this is difficult to implement. But it should be possible in theory, see for example How do I search a file for a multiline pattern without reading the whole file into memory?
Currently you can't. Parsing anything at the moment requires the entire string to exist in memory.
Having said that, if you know the maximum number of lines your pattern may expand over, you could do something like:
my $max = 3; # maximum number of lines
for "textfile".IO.lines(:!chomp).rotor( $max => -$max + 1 ) -> #lines {
#lines.join.subparse( $grammar)
# and whatever you would like to do
}
It wouldn't be the fastest way of doing it, but it would not have to read the whole file in memory.

Howto parse runlength encoded binary subformat with antlr

Given the following input:
AA:4:2:#5#xxAAx:2:a:
The part #5# defines the start of a binary subformat with the length of 5. The sub format can contain any kind of character and is likely to contain tokens from the main format. (ex. AA is a keyword/token inside the main format).
I want to build a lexer that is able to extract one token for the whole binary part.
I already tried several approaches (ex. partials, sematic predicates) but I did not get them working together the right way.
Finally I found the solution by myself.
Below are the relevant parts of the lexer definition
#members {
public int _binLength;
}
BINARYHEAD: '#' [0-9]+ '#' { _binLength = Integer.parseInt(getText().substring(1,getText().length()-1)); } -> pushMode(RAW) ;
mode RAW;
BINARY: .+ {getText().length() <= _binLength}? -> popMode;
The solution is based on an extra field that set while parsing the length definition of the binary field. Afterward a semantic predicate is used to restrict the validity of the binary content to the size of that field.
Any suggestion to simplify the parseInt call is welcome.

Generate file name from SHA hash

I want to use the output of a SHA hash to generate a filename. Any recommended way to do that? I tried Base64 encoding, but for some input that results in the filename containing forward slashes. Obviously I would prefer a method whose output will never contain characters reserved by file systems. Converting each byte to a two-digit hex number would work, but something that produces shorter output would be preferable.
You could use Base32
It only uses alpha and numeric characters.
You can use this
function getfilename(){
mt_srand((double)microtime()*10000);
$token=mt_rand(1, mt_getrandmax());
$uid=uniqid(md5($token),true);
if($uid!=false && $uid!='' && $uid !=NULL){ return $filename =sha1($uid);}
}
//create file name
$filename=getfilename();
$filename = substr($filename, 0, 10);
The above code uses the current system time to generate the File Name and also uses mt_rand and MD5 so as to create a unique file name every time the code is run. The final filename is 10 characters, and you can adjust it to whatever number of characters you want.

How to use { } Curly braces in java-script function to be generated by RPG-CGI pgm

How to write a RPG-CGI program to generate a HTML page which contains a java-script program having function xxx() { aaaaaaaaaaaa; ssssssssss; }. When written in using Hex code constant it is being changed to some other symbol in the actual html code in the browser.
Does EBCDIC character set contains { , }, [ , ] , ! symbols.......if no,then how to use it in AS/400 RPG-CGI program ?
You are most likely running into a codepage conversion issue, which in brief means that the AS/400 does not produce the characters as expected by the recipient. Try to run in code page 819 which is ISO-Latin-1
Another option may be to look into using CGIDEV2 though I would try Thorbjørn's option first.