This code is working nice... I dont have problem.
var urls = from lnks in document.DocumentNode.Descendants()
where (lnks.Name == "a" && lnks.Attributes["href"] != null &&
(lnks.Attributes["href"].Value.ToString().Contains("jpg")
|| lnks.Attributes["href"].Value.ToString().Contains("png")
|| lnks.Attributes["href"].Value.ToString().Contains("bmp")
|| lnks.Attributes["href"].Value.ToString().Contains("jpeg")
|| lnks.Attributes["href"].Value.ToString().Contains("gif"))
)
select new
{
Url = lnks.Attributes["href"].Value
};
But This one always return null:
var urls = from lnks in document.DocumentNode.Descendants()
where (lnks.Name == "a" || lnks.Name == "img") &&
(lnks.Attributes["href"] != null || lnks.Attributes["src"] != null) &&
(
lnks.Attributes["href"].Value.ToString().Contains("jpg")
|| lnks.Attributes["href"].Value.ToString().Contains("png")
|| lnks.Attributes["href"].Value.ToString().Contains("bmp")
|| lnks.Attributes["href"].Value.ToString().Contains("jpeg")
|| lnks.Attributes["href"].Value.ToString().Contains("gif")
|| lnks.Attributes["src"].Value.ToString().Contains("jpg")
|| lnks.Attributes["src"].Value.ToString().Contains("png")
|| lnks.Attributes["src"].Value.ToString().Contains("bmp")
|| lnks.Attributes["src"].Value.ToString().Contains("jpeg")
|| lnks.Attributes["src"].Value.ToString().Contains("gif")
)
select new
{
Url = lnks.Attributes["src"] != null ? lnks.Attributes["src"].Value : lnks.Attributes["href"].Value
};
What's my mistake ? and is this a correct way to take images ?
This is the code for image nodes. Make a function out of it and you can use it for any node:
GetLinksFromDocument(document, nodeName, linkAttributeName)
using HtmlAgilityPack;
var urls = new List<string>();
var prefixList = new[] { "jpg", "jpeg", "png", "bmp", "gif" };
var document = new HtmlWeb().Load("http://jwillmer.de");
var imageNodes = document.DocumentNode.Descendants("img");
var imageLinks = imageNodes.Where(node => node.Attributes.Contains("src"))
.Select(node => node.Attributes["src"].Value);
urls.AddRange(imageLinks.Where(link => prefixList.Any(link.EndsWith)));
Related
checkVersion() {
if (typeof window !== 'undefined' && window && window.navigator && window.navigator !== undefined) {
let agent = window.navigator.userAgent, start = agent.indexOf("OS");
if ((agent.indexOf("iPhone") > -1 || agent.indexOf("iPad") > -1) && start > -1) {
return window.Number(agent.substr(start + 3, 3).replace("_", "."))
}
return 0;
}
},
const checkVersion = Common.checkVersion();
require("../assets/style.css");
require("../assets/style2.css");
require("../assets/sprite.css");
require("../assets/ondemandpagestyle.css");
require("../assets/newstyle.css");
require("../assets/landingpage.css");
if (checkVersion <= 14) {
require("../assets/styleIOSUpgrade.css");
}
Here u see I have require the last CSS file conditionally(according to IOS version) , here i have used CheckVersion function to detect the Ios version and according to it and i have require the different CSS file
checkVersion() {
if (typeof window !== 'undefined' && window && window.navigator && window.navigator !== undefined) {
let agent = window.navigator.userAgent, start = agent.indexOf("OS");
if ((agent.indexOf("iPhone") > -1 || agent.indexOf("iPad") > -1) && start > -1) {
return window.Number(agent.substr(start + 3, 3).replace("_", "."))
}
return 0;
}
},
const checkVersion = checkVersion();
require("../assets/style.css");
require("../assets/style2.css");
require("../assets/sprite.css");
require("../assets/ondemandpagestyle.css");
require("../assets/newstyle.css");
require("../assets/landingpage.css");
if (checkVersion <= 14) {
require("../assets/styleIOSUpgrade.css");
}
U can use above code to require CSS file conditionally
I have a computed property (filteredSyms) that depends on the asynchronous computed property (allSynonyms). I am using async-computed plugin for this:
https://www.npmjs.com/package/vue-async-computed.
However, when the data gets updated the computed property doesn't wait until the result of the async property update. Therefore, I receive not up to date information. Then after the async property actually return new value computed property doesn't run update again.
How can I make it work the way that computer property waits until there is a result from the async computed property?
The code is below:
asyncComputed: {
async allSynonyms() {
let allSyns = await this.$axios.$post('/db/sym/synonyms', this.model.syms);
return allSyns;
}
},
computed: {
filteredSyms() {
let that = this;
let allSyn = this.allSynonyms;
let exactMatch = this.symsByRating.filter(
function (v) {
let isExactMatch = v.title.toLocaleLowerCase().indexOf(that.searchString.toLocaleLowerCase()) >= 0;
return !that.idsToFilter.includes(v.id) && isExactMatch
&& (!that.currentBodyPart || v.bodyParts.indexOf(that.currentBodyPart) >= 0)
&& that.hasMoreSubsyms(v)
&& (!allSyn || !that.containsObject(v, allSyn))
&& (v.sex == that.model.sex || v.sex == 'NA');
});
let partialList = [];
exactMatch.forEach(ex => partialList.push({n: 100, sym: ex}));
for (let sym of this.symsByRating ) {
let searchWords = this.searchString.toLocaleLowerCase().split(' ');
let symWords = sym.title.toLocaleLowerCase().split(' ');
let n = 0;
let isPartialMatch = false;
symLoop:for (let symWord of symWords) {
symWord = symWord.substring(0, symWord.length - 1);
for (let searchWord of searchWords) {
// don't count last letters of the words
searchWord = searchWord.substring(0, searchWord.length - 1);
if (searchWord.length > 2 && symWord.indexOf(searchWord) >= 0) {
n++;
isPartialMatch = true;
}
}
}
if (exactMatch.indexOf(sym) < 0 && isPartialMatch
&& (!this.currentBodyPart || sym.bodyParts.indexOf(this.currentBodyPart) >= 0)
&& this.hasMoreSubsyms(sym)
&& (!allSyn || !this.containsObject(sym, allSyn))
&& (sym.sex == that.model.sex || sym.sex == 'NA')) {
partialList.push({n: n, sym: sym});
}
}
partialList.sort(function(obj1, obj2) {
return obj2.n - obj1.n;
});
if (this.searchString && this.searchString != '') {
partialList = this.filterSynonyms(partialList);
}
let fs = partialList.map(ws => ws.sym);
console.dir(fs);
return fs;
}
}
A lot of stuff is going on the filtered method, but I guess the main point here that it is using this.allSynonyms to do the check but it is not updated at the time filteredSyms is executed.
Thanks for your suggestions!
(I haven't really tested this out, but it should work.)
vue-async-computed does provide the status in this.$asyncComputed.allSynonyms.success.
try adding this.$asyncComputed.allSynonyms.success as a dependencies to filteredSyms and it should update when success state change.
This is continuing from an old thread here https://groups.google.com/forum/#!topic/firepad-io/73dKYaUwTn4)
The aim is to clean the database for documents which have many revisions over a long period
I need help writing a function that issue a FB command to delete all revisions which are 'nd' days older than the 'ns' snapshot.
I am not sure of both the Firebase syntax for this command and how to access the relevant firebase keys properly.
Any help will be greatly appreciated
Thx!
ended up solving this
PR: https://github.com/firebase/firepad/pull/264
code:
FirebaseAdapter.prototype.deleteOldRevisions_ = function(query) {
var self=this;
query.once('value', function(s) {
if (typeof s.val() === 'undefined' || s.val() === null || !s.hasChildren()) return;
s.forEach(function(rev) {
utils.log('removing old revision: '+rev.key);
rev.ref.remove();
});
setTimeout(function() { self.deleteOldRevisions_(query); }, 100); // delete the next one
});
}
FirebaseAdapter.prototype.monitorHistory_ = function() {
var self = this;
// Get the latest checkpoint as a starting point so we don't have to re-play entire history.
self.ref_.child('checkpoint').once('value', function(s) {
//utils.log(new Date().toISOString() + ': got checkpoint');
if (self.zombie_) { return; } // just in case we were cleaned up before we got the checkpoint data.
var revisionId = s.child('id').val(), op = s.child('o').val(), author = s.child('a').val();
if (op !== null && revisionId !== null && author !== null &&
op !== undefined && revisionId !== undefined && author !== undefined) {
self.pendingReceivedRevisions_[revisionId] = { o: op, a: author };
self.checkpointRevision_ = revisionFromId(revisionId);
self.monitorHistoryStartingAt_(self.checkpointRevision_ + 1);
} else {
self.checkpointRevision_ = 0;
self.monitorHistoryStartingAt_(self.checkpointRevision_);
}
// delete revisions older than one week before last checkpoint
if (revisionId) {
var historyRef=self.ref_.child('history');
historyRef.child(revisionId+'/t').once('value', function(s) {
if (typeof s.val() !== 'undefined' && s.val() !== null) {
var weekBefore=s.val()-(24*60*60*1000*7);
//utils.log('checkpoint revision: '+self.checkpointRevision_);
//utils.log('checkpoint time: ' + new Date(s.val()));
//utils.log('remove before: ' + new Date(weekBefore));
self.deleteOldRevisions_(historyRef.orderByChild('t').endAt(weekBefore));
}
});
}
});
};
I need to filter the listing or records according to selection in dropdownlists.
I have three dropdowns that needs to filter the records reactively in collaboration with each other. i.e value selection in one dropdownlist should filter the records effected by other dropdownlist values.
var filterAndLimitResults = function (cursor) {
if (!cursor) {
return [];
}
var raw = cursor.fetch();
var currentChosenCategory = chosenCategory.get();
var currentChosenCity = chosenCity.get();
var currentJtype = chosenJtype.get();
console.log(currentChosenCategory);
console.log(currentChosenCity);
// filter category
var filtered = [];
if (!currentChosenCategory || currentChosenCategory == "" && !currentChosenCity || currentChosenCity == "" && !currentJtype || currentJtype == "")
{
filtered = raw;
// console.log(filtered);
}
else {
filtered = _.filter(raw, function (item) {
if(currentChosenCategory){
return item.ccategory === currentChosenCategory ;
}
if(currentChosenCity){
return item.city === currentChosenCity ;
console.log(item.city === currentChosenCity);
}
});
}
var currentLimit =limit.get();
//enforce the limit
if (currentLimit ) {
filtered = _.first(filtered, currentLimit );
}
return filtered;
};
the above code is doing both filtering the dropdowns and limit the number of records so as to give infinite scrolling.
Edit For Text Based Search
Here is my eventmap for seach box
"keyup #search-title":function(e,t){
if(e.which === 27){
searchTitle.set("");
}
else {
var text = $(e.target.val);
searchTitle.set(text)
console.log(searchTitle.set(text));
}
}
This is what iam doing in the filteredAndLimitResults
if(!(!currentSearchTitle || currentSearchTitle == "")) {
filtered = _.filter(filtered, function (item) {
return item.title === currentSearchTitle ;
console.log(item.title === currentSearchTitle);
});
}
when i am typing something in the search box. all the records vanishes and when in press esc it comes back to as it was. in console.log i can see that on everytime i press a key it returns the collection.
You need to enforce the filters one after the other. Try like that:
var filterAndLimitResults = function (cursor) {
if (!cursor) {
return [];
}
var raw = cursor.fetch();
var currentChosenCategory = chosenCategory.get();
var currentChosenCity = chosenCity.get();
var currentJtype = chosenJtype.get();
console.log(currentChosenCategory);
console.log(currentChosenCity);
// filter category
var filtered = [];
if (!currentChosenCategory || currentChosenCategory == "" || currentChosenCategory === "All categories")
{
filtered = raw;
// console.log(filtered);
}
else {
filtered = _.filter(raw, function (item) {
if(currentChosenCategory){
return item.ccategory === currentChosenCategory ;
}
});
}
// filter city
if (!(!currentChosenCity || currentChosenCity == "" || currentChosenCity === "All cities"))
{
filtered = _.filter(filtered, function (item) {
if(currentChosenCity){
return item.city === currentChosenCity ;
console.log(item.city === currentChosenCity);
}
});
}
// filter JType
if (!(!currentJtype || currentJtype == "" || currentJtype === "All Jtypes"))
{
filtered = _.filter(filtered, function (item) {
if(currentJtype){
//update the item.ccategory with the right field
return item.ccategory === currentJtype ;
}
});
}
var currentLimit =limit.get();
//enforce the limit
if (currentLimit ) {
filtered = _.first(filtered, currentLimit );
}
return filtered;
};
I want to limit the number of words a person can enter into a body of a content type.
And show the word count to the user.
What is the best way to do this.
The easiest solution would be to install this drupal module:
https://drupal.org/project/maxlength
If you are looking to do this manually you can try this solution:
Add this to your form field definition:
'#attributes' => array('onKeyPress' => "return textareaMaxLength(this, event, $sms_max_len);"),
Add a new JS file to your theme:
drupal_add_js(drupal_get_path('module', 'mymodule'). '/myfile.js');
Myfile.js:
function textareaMaxLength(field, evt, limit) {
var evt = (evt) ? evt : event;
var charCode =
(typeof evt.which != "undefined") ? evt.which :
((typeof evt.keyCode != "undefined") ? evt.keyCode : 0);
if (!(charCode >= 13 && charCode <= 126)) {
return true;
}
return (field.value.length < limit);
}
Credit for script/reference:
https://drupal.org/node/80122