Regular Expression to remove vendor prefixed CSS - regex

Seems pretty simple, but with RegEx it seems nothing is simple. All I want to do is take an array of CSS properties like this:
[ 'background',
'border',
'font-size',
'margin',
'outline',
'padding',
'vertical-align',
'line-height',
'display',
'list-style',
'quotes',
'content',
'background-color',
'color',
'text-decoration',
'font-style',
'font-weight',
'border-bottom',
'cursor',
'border-collapse',
'border-spacing',
'border-top',
'height',
'box-shadow',
'text-shadow',
'page-break-inside',
'max-width',
'orphans',
'widows',
'page-break-after',
'font-family',
'src',
'speak',
'font-variant',
'text-transform',
'text-rendering',
'-webkit-font-smoothing',
'-moz-osx-font-smoothing',
'box-sizing',
'width',
'-webkit-tap-highlight-color',
'margin-top',
'margin-bottom',
'margin-left',
'touch-action',
'padding-top',
'padding-bottom',
'text-align',
'caption-side',
'border-radius',
'resize',
'min-width',
'-webkit-appearance',
'clear',
'margin-right',
'foat',
'float',
'position',
'overflow',
'clip',
'visibility',
'font',
'text-overflow',
'white-space',
'padding-left',
'padding-right',
'-ms-word-break',
'word-break',
'-webkit-hyphens',
'-moz-hyphens',
'-ms-hyphens',
'hyphens',
'pading-left',
'border-left',
'border-right',
'top',
'left',
'transform',
'-webkit-transform',
'z-index',
'right',
'bottom',
'max-height',
'isplay',
'overflow-x',
'flex-wrap',
'min-height',
'flex',
'order',
'align-items',
'align-self',
'background-image',
'opacity',
'background-size',
'background-repeat',
'data',
'user-select',
'border-color',
'transition',
'pointer-events',
'boder-color',
'border-top-right-radius',
'border-bottom-right-radius',
'border-top-left-radius',
'border-bottom-left-radius',
'border-width',
'border-style',
'-ms-transform' ]
And remove all of the vendor prefixed ones. What would the regular expression look like to only match strings like this -ms-transform and not strings like this border-width?

You can use Array#filter with RegExp#test.
var regex = /^-(webkit|moz|ms|o)-/;
var nonVendorPrefixedProperties = arr.filter(prop => !regex.test(prop));
The vendor prefixes
-webkit-: Chrome, newer versions of Opera
-moz-: Firefox
-o-: Old versions of Opera
-ms-: Internet Explorer
RegEx Explanation:
^: Start of line
-: Match hyphen
(webkit|moz|ms|o): Match vendor prefix webkit, moz, ms or o.
var arr = ['background',
'border',
'font-size',
'margin',
'outline',
'padding',
'vertical-align',
'line-height',
'display',
'list-style',
'quotes',
'content',
'background-color',
'color',
'text-decoration',
'font-style',
'font-weight',
'border-bottom',
'cursor',
'border-collapse',
'border-spacing',
'border-top',
'height',
'box-shadow',
'text-shadow',
'page-break-inside',
'max-width',
'orphans',
'widows',
'page-break-after',
'font-family',
'src',
'speak',
'font-variant',
'text-transform',
'text-rendering',
'-webkit-font-smoothing',
'-moz-osx-font-smoothing',
'box-sizing',
'width',
'-webkit-tap-highlight-color',
'margin-top',
'margin-bottom',
'margin-left',
'touch-action',
'padding-top',
'padding-bottom',
'text-align',
'caption-side',
'border-radius',
'resize',
'min-width',
'-webkit-appearance',
'clear',
'margin-right',
'foat',
'float',
'position',
'overflow',
'clip',
'visibility',
'font',
'text-overflow',
'white-space',
'padding-left',
'padding-right',
'-ms-word-break',
'word-break',
'-webkit-hyphens',
'-moz-hyphens',
'-ms-hyphens',
'hyphens',
'pading-left',
'border-left',
'border-right',
'top',
'left',
'transform',
'-webkit-transform',
'z-index',
'right',
'bottom',
'max-height',
'isplay',
'overflow-x',
'flex-wrap',
'min-height',
'flex',
'order',
'align-items',
'align-self',
'background-image',
'opacity',
'background-size',
'background-repeat',
'data',
'user-select',
'border-color',
'transition',
'pointer-events',
'boder-color',
'border-top-right-radius',
'border-bottom-right-radius',
'border-top-left-radius',
'border-bottom-left-radius',
'border-width',
'border-style',
'-ms-transform'
];
var regex = /^-(webkit|moz|ms)-/;
var nonVendorPrefixedProperties = arr.filter(prop => !regex.test(prop));
console.log(nonVendorPrefixedProperties);
document.getElementById('result').innerHTML = JSON.stringify(nonVendorPrefixedProperties, 0, 4);
<pre id="result"></pre>

Related

DynamoDB: Two document paths overlap with each other; must remove or rewrite one of these paths

I have this update expression :
{
"UpdateExpression": "SET #location = :location, #edited = :edited, #coordinates = :coordinates, #city = :city, #country = :country, #zipCode = :zipCode, #street = :street, coordinates = :coordinates",
"ExpressionAttributeValues": {
":location": "Reston, VA",
":edited": true,
":coordinates": {
"lat": 38.9586307,
"lng": -77.35700279999999
},
":city": "Reston",
":country": "US",
":zipCode": "20190",
":street": "11910 Market St"
},
"ExpressionAttributeNames": {
"#location": "location",
"#edited": "edited",
"#coordinates": "coordinates",
"#city": "city",
"#country": "country",
"#zipCode": "zipCode",
"#street": "street"
}
}
and I am getting this weird error
ERROR: ValidationException: Invalid UpdateExpression: Two document paths overlap with each other; must remove or rewrite one of these paths; path one: [coordinates], path two: [zipCode]
I couldn't find any information online and I can not see where the overlap.
Any help will be appreciated.
coordinates is effectively in your expression twice.

Regular expression for a list of string objects

I have a list as following:
list12 = ['**FIRS0425 SOPL ZTE First Company limited', 'Apple Technology','*ROS Sami']
My code is as following
import re
[item2 for item in list12 for item2 in item.split() if not re.match("^[*A-Z]+(0-9){4}$", item2)]
I got output like :
['First', 'Company', 'limited', 'Apple', 'Technology', 'Sami']
I expect the output to be like :
['SOPL', 'ZTE', 'First', 'Company', 'limited', 'Apple', 'Technology', 'ROS', 'Sami']
I am not good with regular expression. How can I reach to my required solution?
A non-regex way in python,
list12 = ['**FIRS0425 SOPL ZTE First Company limited', 'Apple Technology','*ROS Sami']
str = " ".join(list12)
list21 = str.split()
res = [k.strip('*') for k in list21 if '**' not in k]
print(res)
Output:
['SOPL', 'ZTE', 'First', 'Company', 'limited', 'Apple', 'Technology', 'ROS', 'Sami']
DEMO: http://tpcg.io/s9aBhe
Seems you're looking for
\b([A-Za-z]+)\b
In Python:
import re
list12 = ['**FIRS0425 SOPL ZTE First Company limited', 'Apple Technology','*ROS Sami']
rx = re.compile(r'\b([A-Za-z]+)\b')
result = [word for item in list12 for word in rx.findall(item)]
print(result)
Which yields
['SOPL', 'ZTE', 'First', 'Company', 'limited', 'Apple', 'Technology', 'ROS', 'Sami']

ttk treeview get tags

Hello i try to get the tags attribute
i have this
def treeview(self):
w = self.widget
curItem = w.focus()
print w.item(curItem)
lisswidget = ttk.Treeview(photoFrame)
lisswidget.bind("<<TreeviewSelect>>", treeview)
lisswidget.insert('', 'end', "", open=True, image=IMG, tags="MyTags")
The console return :
{'text': '', 'image': [u'pyimage9'], 'values': '', 'open': 1, 'tags': ['MyTags']}
How i can extract tags ?
Thx
I find it, it's a dictionnary so i do like this :
print w.item(curItem)['tags']

Search for Substring in several fields with MongoDB and Mongoose

I am so sorry, but after one day researching and trying all different combinations and npm packages, I am still not sure how to deal with the following task.
Setup:
MongoDB 2.6
Node.JS with Mongoose 4
I have a schema like so:
var trackingSchema = mongoose.Schema({
tracking_number: String,
zip_code: String,
courier: String,
user_id: Number,
created: { type: Date, default: Date.now },
international_shipment: { type: Boolean, default: false },
delivery_info: {
recipient: String,
street: String,
city: String
}
});
Now user gives me a search string, a rather an array of strings, which will be substrings of what I want to search:
var search = ['15323', 'julian', 'administ'];
Now I want to find those documents, where any of the fields tracking_number, zip_code, or these fields in delivery_info contain my search elements.
How should I do that? I get that there are indexes, but I probably need a compound index, or maybe a text index? And for search, I then can use RegEx, or the $text $search syntax?
The problem is that I have several strings to look for (my search), and several fields to look in. And due to one of those aspects, every approach failed for me at some point.
Your use case is a good fit for text search.
Define a text index on your schema over the searchable fields:
trackingSchema.index({
tracking_number: 'text',
zip_code: 'text',
'delivery_info.recipient': 'text',
'delivery_info.street': 'text',
'delivery_info.city': 'text'
}, {name: 'search'});
Join your search terms into a single string and execute the search using the $text query operator:
var search = ['15232', 'julian'];
Test.find({$text: {$search: search.join(' ')}}, function(err, docs) {...});
Even though this passes all your search values as a single string, this still performs a logical OR search of the values.
Why just dont try
var trackingSchema = mongoose.Schema({
tracking_number: String,
zip_code: String,
courier: String,
user_id: Number,
created: { type: Date, default: Date.now },
international_shipment: { type: Boolean, default: false },
delivery_info: {
recipient: String,
street: String,
city: String
}
});
var Tracking = mongoose.model('Tracking', trackingSchema );
var search = [ "word1", "word2", ...]
var results = []
for(var i=0; i<search.length; i++){
Tracking.find({$or : [
{ tracking_number : search[i]},
{zip_code: search[i]},
{courier: search[i]},
{delivery_info.recipient: search[i]},
{delivery_info.street: search[i]},
{delivery_info.city: search[i]}]
}).map(function(tracking){
//it will push every unique result to variable results
if(results.indexOf(tracking)<0) results.push(tracking);
});
Okay, I came up with this.
My schema now has an extra field search with an array of all my searchable fields:
var trackingSchema = mongoose.Schema({
...
search: [String]
});
With a pre-save hook, I populate this field:
trackingSchema.pre('save', function(next) {
this.search = [ this.tracking_number ];
var searchIfAvailable = [
this.zip_code,
this.delivery_info.recipient,
this.delivery_info.street,
this.delivery_info.city
];
for (var i = 0; i < searchIfAvailable.length; i++) {
if (!validator.isNull(searchIfAvailable[i])) {
this.search.push(searchIfAvailable[i].toLowerCase());
}
}
next();
});
In the hope of improving performance, I also index that field (also the user_id as I limit search results by that):
trackingSchema.index({ search: 1 });
trackingSchema.index({ user_id: 1 });
Now, when searching I first list all substrings I want to look for in an array:
var andArray = [];
var searchTerms = searchRequest.split(" ");
searchTerms.forEach(function(searchTerm) {
andArray.push({
search: { $regex: searchTerm, $options: 'i'
}
});
});
I use this array in my find() and chain it with an $and:
Tracking.
find({ $and: andArray }).
where('user_id').equals(userId).
limit(pageSize).
skip(pageSize * page).
exec(function(err, docs) {
// hooray!
});
This works.

ordered data in django chartit

I am using django-chartit to display a site name on x-axis and its response time on y-axis.
How do I sort the graph with the response time in ascending order. I am using order_by in the queryset but still its not ordering correctly.
Below is my code :
siteresppivotdata = PivotDataPool(
series =
[{'options': {
'source': MonthlySiteResponse.objects.all(),
'categories': ['site_name', ],
'legend_by' : ['site_name'],
},
'terms': {
'total_response_time': Avg('response_time')}}
],
pareto_term = 'total_response_time' ## Added this code for sorting
)
#Step 2: Create the PivotChart object
siteresppivcht = PivotChart(
datasource = siteresppivotdata,
series_options =
[{'options':{
'type': 'bar', ## Show response_time on x-axis and site_name on y-axis with the 'bar' i.e (reverse of the column graph)
'stacking': True},
'terms':[
'total_response_time']}],
chart_options =
{'title': {
'text': 'Monthly Site Response Time'},
'xAxis': {
'title': {
'text': 'Website'}},
'yAxis': {
'title': {
'text': 'Response Time'}}}
)
Also is there a way to show the graph vice-versa (i.e site name on y-axis and response-time on x-axis)