How to find out the keyword in ace-editor - keyword

For ace-editor, I want to select one line and find out all the keywords within the line and output into the console. Which APIs from ace-editor that I can use for this purpose, and how to achieve the goal. Thanks.

you can use session.getTokens method like so
var row = editor.selection.getCursor().row
editor.session.getTokens(row).filter(function(t) {
return t.type == "keyword"
})

Related

ZAPIER output_missing Please define output or return early

I am trying to get a document from a form here, but my script out is missing. Am i doing anything wrong here. This seems to work when there is more than on argument but it is just one it seems not to be working
try:
documents = {}
if "Select which supporting documentation you would like to accompany your motivation letter" in input_data['checkbox']:
documents['doc1']="https://essentialmedicalguidance.s3.eu-central-1.amazonaws.com/brand/Eli+Lilly/Trulicity/VAE_Trulicity+Package+Insert.pdf"
return documents
except:
return {'empty' : True}
The function always has to return (or set) data. In the case where 'Select which...' is not in input_data['checkbox'], then nothing is returned.
Try something like this instead, which will be more consistent (if you add more fields):
result = {}
if 'Select which...' in input_data['checkbox']:
result['doc1'] = 'https://ess...'
return result
This way, your output is still conditional, but something is always returned.

How to find record using $type in mongodb?

I am using ruby on rails with MongoDB. I have one field 'possession' as string type field. I've updated it as 'Integer'.
Now, I want to find old data with specific string(for example, '6') and need to update all as integer values(means 6).
So, instead of doing each loop on all record I will just distinct values and update_all based on distinct values.
Please let me know if anyone has idea about this.
To find data using $type you can use type value as 2 for string. And using forEach function you can update the records.
You can use this query:
db.collection.find({
possession: {
$type: 2
}
}).forEach(function(data){
db.collection.update({
"$set": {
"possession": parseInt(data.possession)
}
})
})
I think #Mayuri has the right idea, but unfortunately did not test their answer. I get an error when I run their code. here is a fix to their solution. I used mongo shell to test...
I also took the liberty of using the $type string name instead of a number code.
db.collection.find({
possession: {
$type: "string"
}
}).forEach(function(data){
db.collection.update({"_id": data._id}, {
"$set": {
"possession": parseInt(data.possession)
}
})
})

Conditional Dynamic finder in grails

so i require something like the dynamic finder should change as per the condition, let me explain by code what i mean
the below code find all employee by status and lastdateattended
def employee = Employee.findAllByStatusAndLastDateAttended("INA",dateObject)
now i have two fields in Employee LastDateAttended and LastDateSigned , and now i want that if a record does not have LastDateAttended, then it should find by LastDateSigned , otherwise LastDateAttended, so another condition is like
def employee = Employee.findAllByStatusAndLastDateAttended("INA",dateObject)
and i somehow wants to join and use both the query based on a condition , can it be achieved ?, if possible please help
I think criteria query make sense here, something like following
Employee.createCriteria().list{
and{
eq('status','INA')
or {
eq('lastDateAttended',dateObject)
eq('lastDateSigned',dateObject)
}
}
}
Employee.list().findAll { emp->
emp.status == "INA" && ( emp.lastDateAttended!=null?
emp.lastDateAttended.equals(dateObject):emp.lastDateSigned.equals(dateObject)
)
}
Employee.findAllByStatusOrLastDateAttendedOrStatusAndLastDateAttended("INA",dateObject)

how to use ilike with Integer in grails

I use EasyGrid plugin and must find values where integer field like '%001%'
initialCriteria {
ilike('id', "%"+params.id+"%")
}
But ilike doesn't work with Integer. How to do it?
I tried to do:
initialCriteria {
ilike('id'.toString(), "%"+params.id+"%")
}
initialCriteria {
ilike('str(id)', "%"+params.id+"%")
}
but it's not work.
If id is an integer in the database, then ilike doesn't really make much sense and there is probably a better way to do what you are trying to do (like adding a type field or something to the domain object, and filter by type)
However, you should be able to do something like this (untested):
initialCriteria {
sqlRestriction "cast( id AS char( 256 ) ) like '%001%'"
}
Following criteria not working if you search from your textbox when user search any text character by mistake like 12dfdsf as your searchable id. It will give you an exception
initialCriteria {
ilike('id', "%"+params.id+"%")
}
For better use you can use following criteria
initialCriteria {
sqlRestriction "id like '%${params?.id}%'"
}
You could do:
String paddedId = params.id.toString().padLeft(3,'0')
initialCriteria {
ilike('id', "%$paddedId%")
}
The solution offered by tim_yates with the sqlRestriction would work in version 1.5.0 of easygrid.
One of the main differences from 1.4.x is that the gorm datasource no longer uses DetachedCriteria, but Criteria - which maps directly to Hibernate's Criteria API.
So you can try it on the last version.
(Keep in mind that the upgrade might break your existing grids. There's also many other changes)
Another small observation is that 'initialCriteria' is not the right place to do stuff like that. (it's not wrong, but there is a 'globalFilterClosure' property for applying column independent filters)
I mixed the code posted by #tim_yates and mine:
String paddedId = params.id.toString().padLeft(3,'0')
def crit = Book.withCriteria {
sqlRestriction "lpad(cast( id AS char( 256 ) ), 3, '0') like '%${paddedId}%'"
}
I've tried with a h2 in-memory db and it works, but I am not sure about two things:
the real usefulness of that
lpad syntax consistence across all db engines
YMMV

jQuery Mobile Filtered List - only match beginning of string

Im using the jQuery mobile search filter list:
http://jquerymobile.com/test/docs/lists/lists-performance.html
Im having somer performance issues, my list is a little slow to filter on some phones. To try and aid performance I want to change the search so only items starting with the search text are returned.
So 'aris' currently finds the result 'paris' but I want this changed. I can see its possible from the documentation below but I dont know how to implement the code.
http://jquerymobile.com/test/docs/lists/docs-lists.html
$("document").ready( function (){
$(".ui-listview").listview('option', 'filterCallback', yourFilterFunction)
});
This seems to demonstrate how you write and call your own function, but ive no idea how to write it! Thanks
http://blog.safaribooksonline.com/2012/02/14/jquery-mobile-tip-write-your-own-list-view-filter-function/
UPDATE - Ive tried the following in a seperate js file:
$("document").ready( function (){
function beginsWith( text, pattern) {
text= text.toLowerCase();
pattern = pattern.toLowerCase();
return pattern == text.substr( 0, pattern.length );
}
$(".ui-listview").listview('option', 'filterCallback', beginsWith)
});
might look something like this:
function beginsWith( text, pattern) {
text= text.toLowerCase();
pattern = pattern.toLowerCase();
return pattern == text.substr( 0, pattern.length );
}
Basically you compare from 0 to "length" of what you're matching to the source. So if you pass in "test","tester" it will see you're passing in a string of length 4 and then substr "tester" from 0,4, which gives you "test". Then "test" is equal to "test"... so return true. Lowercase them to make it case insensitive.
Another trick to improve filter performance, only filter once they've entered more than 1 character.
edit it appears jQueryMobile's filter function expects that "true" means it was not found... so it needs to be backwards. return pattern != text.substr( 0, pattern.length );
This worked for me. I am using regular expression here so sort of different way to achieve the same thing.
But the reason why my code didn't work initially was that the list item had a lot of spaces at the beginning and at the end (found that it got added on it's own while debugging).
So I do a trim on the text before doing the match. I have a feeling Jonathan Rowny's implementation will also work if we do text.trim() before matching.
$(".ui-listview").listview('option', 'filterCallback', function (text, searchValue) {
var matcher = new RegExp("^" + searchValue, "i");
return !matcher.test(text.trim());
});

Resources