Does there exist some inclusion mechanism whereby snippet expansion results in the expansion of other snippets?
For example, something along the lines of:
'Part 1' :
'prefix': 'part1'
'body' : 'part 1 stuff'
'Part 2' :
'prefix': 'part2'
'body' : 'part 2 stuff'
'Composer' :
'prefix': 'compose'
'body' : """
composers stuff
${include: part1}
${include: part2}
"""
'description' : 'expands to self and parts 1 and 2'
No, Atom snippets aren't that fancy. But as a workaround, you could use the names of the other snippets to indicate further expansions:
'Part 1':
'prefix': 'part1'
'body': 'part 1 stuff'
'Part 2':
'prefix': 'part2'
'body': 'part 2 stuff'
'Composer':
'prefix': 'compose'
'description': 'expands to self and snippet names for parts 1 and 2'
'body': """
composers stuff
part1$1
part2$2
"""
Type compose then Tab:
composers stuff
part1|
part2
(pipe indicates cursor)
Press Tab again:
composers stuff
part 1 stuff|
part2
Go to the end of part2, then press Tab again:
composers stuff
part 1 stuff
part 2 stuff|
(You need to manually go to the end because once you expand the part1 snippet, the tab stops in the compose snippet go away. But I specified both tab stops in the compose snippet to indicate that they're sub-snippets and so that you can skip expanding part1 if needed. This is especially doable if you set another keybind for snippets:next-tab-stop instead of Tab; the use of the same key always bothered me personally anyway.)
Related
I am trying to update Dynamo Table using expression, I am trying to generate keys dynamically. The issue looks like if they key has space in it, expressions don't evaluate properly.
Following in my update implementation:
update_expression = 'SET {}'.format(','.join(f'#{p}=:{p}' for p in row_as_dict))
expression_attribute_values = {f':{p}': v for p, v in row_as_dict.items()}
expression_attribute_names = {f'#{p}': p for p in row_as_dict}
if result_set.get('Item') and result_set.get('Item').get(primary_key):
TABLE.update_item(
Key={
primary_key: row_as_dict[primary_key],
sort_key: row_as_dict[sort_key]
},
UpdateExpression=update_expression,
ExpressionAttributeValues=expression_attribute_values,
ExpressionAttributeNames=expression_attribute_names
)
if i print the values for update_expression and expression_attribute_values and expression_attribute_names i get following output.
update_expression
SET #Ref No=:Ref No,#FT/Hot=:FT/Hot,#Irfan watch List=:Irfan watch List,#F.Soahil watchList=:F.Soahil watchList,#HR Responible=:HR Responible,#Pipeline(Adv/Ref)=:Pipeline
(Adv/Ref),#Source=:Source,#Date Submitted=:Date Submitted,#Name=:Name,#Candidate Location=:Candidate Location,#Tech =:Tech ,#Current Company=:Current Company,#Exp=:Exp,#Position being considered for=:Position being considered for,#Proj. / Gen Hiring=:Proj. / Gen Hiring,#Comments / Latest Status / Next Step=:Comments / Latest Status / Next Step,#Status=:Status,#hiring status=:hiring status,#Link to Lever=:Link to Lever,#LinkedIn Link / Resume=:LinkedIn Link / Resume,#Interview Feedback Google Doc=:Interview Feedback Google Doc,#Email=:Email
expression_attribute_values
{':Ref No': '1', ':FT/Hot': 'NaN', ':Irfan watch List': 'NaN', ':F.Soahil watchList': 'NaN', ':HR Responible': 'Khurram', ':Pipeline\r\n(Adv/Ref)': 'Referred', ':Source': 'Usman Khan', ':Date Submitted': '17-Dec', ':Name': 'Asif Mahmood Mughal Zain', ':Candidate Location': 'ISL', ':Tech ': 'Spark. Hadoop\r\nSQL, Big Data', ':Current Company': 'Zain Telecom', ':Exp': '18+', ':Position being considered for': 'Senior SA', ':Proj. / Gen Hiring': 'General', ':Comments / Latest Status / Next Step': 'Muhammaf Naseer Recommneded\r\nAdeel Ashraf Recommended\r\nFaheem Khan Recommended\r\n\r\nAccepted offer.will join on 6 jan', ':Status': 'Joined', ':hiring status': 'Hired', ':Link to Lever': 'Link to Lever', ':LinkedIn Link / Resume': 'Asif Mehmood Mughal', ':Interview Feedback Google Doc': 'Link to Feedback', ':Email': 'some_email1#test.com'}
expression_attribute_names
{'#Ref No': 'Ref No', '#FT/Hot': 'FT/Hot', '#Irfan watch List': 'Irfan watch List', '#F.Soahil watchList': 'F.Soahil watchList', '#HR Responible': 'HR Responible', '#Pipeline\r\n(Adv/Ref)': 'Pipeline\r\n(Adv/Ref)', '#Source': 'Source', '#Date Submitted': 'Date Submitted', '#Name': 'Name', '#Candidate Location': 'Candidate Location', '#Tech ': 'Tech ', '#Current Company': 'Current Company', '#Exp': 'Exp', '#Position being considered for': 'Position being considered for', '#Proj. / Gen Hiring': 'Proj. / Gen Hiring', '#Comments / Latest Status / Next Step': 'Comments / Latest Status / Next Step', '#Status': 'Status', '#hiring status': 'hiring status', '#Link to Lever': 'Link to Lever', '#LinkedIn Link / Resume': 'LinkedIn Link / Resume', '#Interview Feedback Google Doc': 'Interview Feedback Google Doc', '#Email': 'Email'}
The Error generated is
An error occurred (ValidationException) when calling the UpdateItem operation: ExpressionAttributeValues contains invalid key: Syntax error; key: ":hiring status"
You can't have spaces in your attribute keys/values in the expression. So :hiring status needs to be something like :hiring_status.
Go Dynamof!
You might be very interested in dynamof. Its a library purposed to do exactly what your trying to do. At the very least you can take a peak and check out how it handles dynamically creating all the expressions.
I suggest you take a look at the args module.
It has the functions that do what your trying to do. The args module gets some help from another module (the request builder) in dynamof that is responsible for some preprocessing of the entire action's arguments so the args module's functions get an easy to use and parse RequestTree object.
Answer...
I would just use dynamof - but I'm biased. If you want to write it yourself, heres a little example on how its been done straight from dynamof.
def UpdateExpression(request: RequestTree):
def expression(attr):
if attr.func is not None:
return attr.func.expression(attr)
return f'{attr.alias} = {attr.key}'
key_expressions = [expression(key) for key in request.attributes.values]
key_expression = ', '.join(key_expressions)
return f'SET {key_expression}'
NOTE: The attr.alias is whats used to handle the special name cases - like spaces. Its set in the request builder module mentioned above.
disclaimer: I wrote dynamof
I have a nested dictionary
users={'user502':{'firstname':'James' , 'lastname':'Jones'}}
User can search for first or last name and be able to update to something else. I wrote the following code:
name_change=input('Enter name to change: ')
for key,value in users.items():
for k,v in value.items():
if name_change==v:
#print('name found in', value.get(name_change))
#print('name found in', value.get(k))
print('name found in', k)
updated_name=input('What would be the new name: ')
users.update(k=updated_name)
break
else:
print('name not found')
I am getting RuntimeError: dictionary changed size during iteration error. I did some research on update and also looked at this stackoverflow discussion Update value in nested dictionary - Python
I am not able to figure out how to point the code to pick first name or last name based on whatever user enters. Some hints would be helpful.
Thanks in advance.
**From other discussion it seems like in Python 3 it does not work because of '3.x because keys returns an iterator instead of a list.'
I tried to do a pop first and then update
updated_name=input('What would be the new name: ')
# users[k][v]=updated_name
x= value.get(k)
users.pop(x)
users[x]=updated_name
However now I get KeyError: 'James'
This code is doing what I wanted. May be my question was not clear sorry about that
print('Actual-', users)
name_change=input('Enter name to change: ')
for key,value in users.items():
for k,v in value.items():
if name_change==v:
#print('name found in', value.get(name_change))
#print('name found in', value.get(k))
print('name found in', k)
updated_name=input('What would be the new name: ')
value[k]=updated_name
break
else:
print('name not found')
print("modified name:", users)
Output:
Actual- {'user502': {'lastname': 'Jones', 'firstname': 'James'}}
Enter name to change: Jones
name found in lastname
What would be the new name: January
modified name: {'user502': {'lastname': 'January', 'firstname': 'James'}}
I am working on a regular expression to extract some text from files downloaded from a newspaper database. The files are mostly well formatted. However, the full text of each article starts with a well-defined phrase ^Full text:. However, the ending of the full-text is not demarcated. The best that I can figure is that the full text ends with a variety of metadata tags that look like: Subject: , CREDIT:, Credit.
So, I can certainly get the start of the article. But, I am having a great deal of difficulty finding a way to select the text between the start and the end of the full text.
This is complicated by two factors. First, obviously the ending string varies, although I feel like I could settle on something like: `^[:alnum:]{5,}: ' and that would capture the ending. But the other complicating factor is that there are similar tags that appear prior to the start of the full text. How do I get R to only return the text between the Full text regex and the ending regex?
test<-c('Document 1', 'Article title', 'Author: Author Name', 'https://a/url', 'Abstract: none', 'Full text: some article text that I need to capture','the second line of the article that I need to capture', 'Subject: A subject', 'Publication: Publication', 'Location: A country')
test2<-c('Document 2', 'Article title', 'Author: Author Name', 'https://a/url', 'Abstract: none', 'Full text: some article text that I need to capture','the second line of the article that I need to capture', 'Credit: A subject', 'Publication: Publication', 'Location: A country')
My current attempt is here:
test[(grep('Full text:', test)+1):grep('^[:alnum:]{5,}: ', test)]
Thank you.
This just searches for the element matching 'Full text:', then the next element after that matching ':'
get_text <- function(x){
start <- grep('Full text:', x)
end <- grep(':', x)
end <- end[which(end > start)[1]] - 1
x[start:end]
}
get_text(test)
# [1] "Full text: some article text that I need to capture"
# [2] "the second line of the article that I need to capture"
get_text(test2)
# [1] "Full text: some article text that I need to capture"
# [2] "the second line of the article that I need to capture"
I'm using WP-GeSHi in WordPress, and largely I'm very happy with it. There are, however, a few minor scenarios where the color highlighting is too aggressive when a keyword is:
a variable name (denoted by a leading #)
part of another word (e.g. IN in INSERTED)
the combination (part of a variable name, e.g. JOIN and IN in #JOINBING)
inside square brackets (e.g. [status])
Certain keywords are case sensitive, and others are not. The below screenshot sums up the various cases where this goes wrong:
Now, the code in GeSHi.php is pretty verbose, and I am by no means a PHP expert. I'm not afraid to get my hands a little dirty here, but I'm hoping someone else has made corrections to this code and can provide some pointers. I already implemented a workaround to prevent ##ROWCOUNT from being highlighted incorrectly, but this was easy, since ##ROWCOUNT is defined - I just shuffled the arrays around so that it was found before ROWCOUNT.
What I'd like is for GeSHi to completely ignore keywords that aren't whole words (whether they are prefixed by # or immediately surrounded by other letters/numbers). JOIN should be grey, but #JOIN and JOINS should not. I'd also like it to ignore keywords that are inside square brackets (after all, this is how we tell Management Studio to not color highlight it, and it's also how we tell the SQL engine to ignore reserved words, keywords, and invalid identifiers).
You can do this by adding a PARSER_CONTROL control to the end of the array:
'PARSER_CONTROL' => array(
'KEYWORDS' => array(
1 => array( // "1" maps to the main keywords near the start of the array
'DISALLOWED_BEFORE' => '(?![\(\w])',
'DISALLOWED_AFTER' => '(?![\(\w])'
),
5 => array( // "5" maps to the shorter keywords like "IN" that are further down
'DISALLOWED_BEFORE' => '(?![\(\w])',
'DISALLOWED_AFTER' => '(?![\(\w])'
),
)
)
Edit
I've modified your gist to move some of the keywords you added to SYMBOLS back to KEYWORDS (though in their own group and with your custom style), and I updated the PARSER_CONTROL array to match the new keyword array indexes and also to include the default regex that geshi generates. Here is the link:
https://gist.github.com/jamend/07e60bf0b9acdfdeee7a
According to me, what you are doing would take a lot of time. So, I suggest that you install a different plugin:
It has better features and supports more languages and in a better way. So, it would remove all these problems.
EDIT:
Hey, I tried out the same code with latest version and got following result-
EDIT:
So, if you don't want to use another plugin, then I'll tell you about the coding:
First open \wp-content\plugins\wp-geshi-highlight\geshi\geshi\tsql.php in your text editor.
Then, locate the array 'KEYWORDS' or search for it.
Add 6 to the last of it (after 5) and add your custom keywords in it. For example:
5 => array(
'ALL', 'AND', 'ANY', 'BETWEEN', 'CROSS', 'EXISTS', 'IN', 'JOIN', 'LIKE', 'NOT', 'NULL',
'OR', 'OUTER', 'SOME',
),
6 => array( //This line has been added by me
'status' //This line has been added by me
) //This line has been added by me
Note: I have just shown array element 5 (already present) and array element 6 (which I have made).
Then, to make it case-sensitive add below code to the last of 'CASE_SENSITIVE' array:
6 => true
The 'CASE_SENSITIVE' array should look like this:
'CASE_SENSITIVE' => array(
GESHI_COMMENTS => false,
1 => false,
2 => false,
3 => false,
4 => false,
5 => false,
6 => true //This line has been added by me
),
Now, you will have to add styling to the custom keywords. This can be achieved by adding below line to the 'KEYWORDS' element of 'STYLES' array. The starting of 'STYLES' array should look like this:
'STYLES' => array(
'KEYWORDS' => array(
1 => 'color: #0000FF;',
2 => 'color: #FF00FF;',
3 => 'color: #AF0000;',
4 => 'color: #AF0000;',
5 => 'color: #808080;',
6 => 'color: #0000FF;' //This line has been added by me
),
You can solve your problems by above guidelines, but for the part in which the plugin highlights incomplete words, I have found only one solution, that you update your plugin to latest version, because it solves this problem.
I have this array in a Drupal 7 installation, it outupts the term list that belongs to a specific vocabulary id:
<?php print render($content['taxonomy_vocabulary_3']); ?>
Now, what this does it outputs the result in a list, I would like to output it in a comma separated line.
Now, I suppose that I could do that with a foreach statement?
I´ve tried this, after reading the documentation, but it outputted nothing:
foreach($taxonomy_vocabulary_3 as $id=>$tag) {
echo "$tag, " ;
}
I´ve looked into what the Devel module told me about that array, and it showed me this:
taxonomy_vocabulary_3 (Array, 1 element)
und (Array, 2 elements)
0 (Array, 1 element)
tid (String, 3 characters ) 141
1 (Array, 1 element)
tid (String, 3 characters ) 320
But as you can see it shows the term id in each case, and not the term name...
What do you suggest? Thanks!!
You can load the term and then print it's title.
foreach($vocabulary as $tid) {
$term = taxonomy_term_load($tid);
// print whatever you want from this object.
print $term->title . ', ';
}
taxonomy_term_load
What you got is a build array - so that means that
$content['taxonomy_vocabulary_3']['#theme']
will be the theme function used to render the vocabulary. If you want to change the output you have two good solutions.
override the standard theme function in your theme - this will alter the output of all the calls to that theme function - in this case how all vocabularies is rendered.
Change the #theme value to a theme function of your liking - this could be a custom theme function you define in your theme.
For help on how to render the terms, you can take a look at how the original theme function is implemented - you can look it up at the Drupal API documentation.