Compass `_compass_list` usage - css

I'm trying to figure out how to turn a string into a list in Compass - this is not supported natively in SASS. For example the string "a b c" would become a list with a length of 3… essentially [a, b, c], excepts lists aren't actually arrays.
The _compass_list() function appears to be exactly what I'm looking for according to the documentation: "Returns a list object from a value that was passed. This can be used to unpack a space separated list that got turned into a string by sass before it was passed to a mixin." However, in practice it simply wraps the string in a list (e.g. "a b c" becomes ["a b c"]).
Looking at the source, it's obvious that's exactly what's happening. Perhaps it's a bug?
https://github.com/chriseppstein/compass/blob/stable/lib/compass/sass_extensions/functions/lists.rb#L47
Can anyone explain the proper use of this function to me?

This function's code is identical to the next one's. The next one is said to return a single-element list.
Any advanced lists usage in SASS is a big PITA, unfortunately.
Maybe you could write your own Ruby-to-SASS function that parses a string and turns it into a list?

Related

How do I concatenate strings in arduino?

sorry I am a bit rusty here, how do I concatenate these 2 outputs?
display.println(timeinfo->tm_hour);
display.println(timeinfo->tm_min);
If you just want them to appear in the output one after another on the same line then use print instead of println for the first one. Println adds a newline to the end of the output and print doesn't. It's always good to look stuff like that up before using a function.
If you really want them put together into one string then you will have to show where those strings are coming from. If they are String class objects you can just use + to put them together. If they are proper c-style strings then you will need to use strcat.
How are defining them?
If you have initialized as arrays of characters:
Example: char exampleCString[50] = "This is a C string";
Then you can use strcat() function in C:
strcat(str1,str2);
Note: Make sure "str1" buffer is big enough, because the result goes there.
If on the other hand, you have initialized your strings as objects of String class:
Example: String exampleJavaString="This is a Java String example"
Then just use the + operator to add them:
str1=str1+str2:

Textpad: How to serialize / concat multiple replacements

I have to use Textpad in my environment. To treat a file (on a regular basis) it is necessary to make +/- 20 replacements, some of them regex, some of them not. For most of the replacements I have defined macros (for each replacement one macro, i. e. 1:1). It is possible to "concat" macros or put replacements "in a sequence"? If it is possible: Would this sequence break, if one replacement does not find matching patters (off course, it should not break).
I'm not sure how you would "concat" them aside from recording each macro together (unless you know how to concat the files)... but as your question is about "would it work"... then I'd say yes but you would have to ensure each marco started in the right place.
I'd recommend each macro started and ended with something like Ctrl+Home to ensure a consistent starting / ending place

Convert string argument to regular expression

Trying to get into Julia after learning python, and I'm stumbling over some seemingly easy things. I'd like to have a function that takes strings as arguments, but uses one of those arguments as a regular expression to go searching for something. So:
function patterncount(string::ASCIIString, kmer::ASCIIString)
numpatterns = eachmatch(kmer, string, true)
count(numpatterns)
end
There are a couple of problems with this. First, eachmatch expects a Regex object as the first argument and I can't seem to figure out how to convert a string. In python I'd do r"{0}".format(kmer) - is there something similar?
Second, I clearly don't understand how the count function works (from the docs):
count(p, itr) → Integer
Count the number of elements in itr for which predicate p returns true.
But I can't seem to figure out what the predicate is for just counting how many things are in an iterator. I can make a simple counter loop, but I figure that has to be built in. I just can't find it (tried the docs, tried searching SO... no luck).
Edit: I also tried numpatterns = eachmatch(r"$kmer", string, true) - no go.
To convert a string to a regex, call the Regex function on the string.
Typically, to get the length of an iterator you an use the length function. However, in this case that won't really work. The eachmatch function returns an object of type Base.RegexMatchIterator, which doesn't have a length method. So, you can use count, as you thought. The first argument (the predicate) should be a one argument function that returns true or false depending on whether you would like to count a particular item in your iterator. In this case that function can simply be the anonymous function x->true, because for all x in the RegexMatchIterator, we want to count it.
So, given that info, I would write your function like this:
patterncount(s::ASCIIString, kmer::ASCIIString) =
count(x->true, eachmatch(Regex(kmer), s, true))
EDIT: I also changed the name of the first argument to be s instead of string, because string is a Julia function. Nothing terrible would have happened if we would have left that argument name the same in this example, but it is usually good practice not to give variable names the same as a built-in function name.

Make a list from ls(pattern="") [R]

The ls(pattern="") function is very useful for me, since my list of objects seem to keep growing and growing. I am curious if this feature can be more useful.
For example, let's say i have 4 objects,
a.c<-1
b.c<-2
c.c<-3
d.c<-4
Now i use the useful ls(pattern="") function
ls(pattern=".c")
Now i try to make a list
list(ls(patter=".c"))
But it doesn't give me anything useful( "a.c" "b.c" "c.c" "d.c" ). I want either of these two outputs
1,2,3,4
OR
a.c, b.c, c.c, d.c
A couple of issues:
1) The . in ".c" gets ignored, you need to "escape" it:
ls(pattern="\\.c")
Otherwise it will return all objects with c regardless of having a period.
2) ls returns names of objects as character. To get the value of an object based on its name you need the function get:
lapply(ls(pattern="\\.c"), get)
3) As joran mentioned in the comments, it's much better to keep objects associated with each other in lists:
List.c = list(a.c=1, b.c=2, c.c=3, d.c=4)

R data table issue

I'm having trouble working with a data table in R. This is probably something really simple but I can't find the solution anywhere.
Here is what I have:
Let's say t is the data table
colNames <- names(t)
for (col in colNames) {
print (t$col)
}
When I do this, it prints NULL. However, if I do it manually, it works fine -- say a column name is "sample". If I type t$"sample" into the R prompt, it works fine. What am I doing wrong here?
You need t[[col]]; t$col does an odd form of evaluation.
edit: incorporating #joran's explanation:
t$col tries to find an element literally named 'col' in list t, not what you happen to have stored as a value in a variable named col.
$ is convenient for interactive use, because it is shorter and one can skip quotation marks (i.e. t$foo vs. t[["foo"]]. It also does partial matching, which is very convenient but can under unusual circumstances be dangerous or confusing: i.e. if a list contains an element foolicious, then t$foo will retrieve it. For this reason it is not generally recommended for programming.
[[ can take either a literal string ("foo") or a string stored in a variable (col), and does not do partial matching. It is generally recommended for programming (although there's no harm in using it interactively).

Resources