I tried to create a template which insert a transaction with the current date
# -*- mode: snippet -*-
# name: breakfast
# key: breakfast
# condition: t
# --
2019-09-05 * ""
Assets:DebtWechat CNY
Expenses:Food:Breakfast
How could change 2019-09-05 to a insert-current-date function?
You can embed elisp code in your snippet. For your example, you could use something like
`(format-time-string "%Y-%m-%d")` * ""
Related
This is my ansible script
- name: show1
debug:
msg: "{{response.stderr_lines}}"
Here is the output
msg:
- Using endpoint [https://us-central1-aiplatform.googleapis.com/]
- CustomJob [projects/123456/locations/us-central1/customJobs/112233445566] is submitted successfully.
- ''
- Your job is still active. You may view the status of your job with the command
- ''
- ' $ gcloud ai custom-jobs describe projects/123456/locations/us-central1/customJobs/112233445566'
- ''
- or continue streaming the logs with the command
- ''
- ' $ gcloud ai custom-jobs stream-logs projects/123456/locations/us-central1/customJobs/112233445566'
Here I want to extract custom Job ID which is 112233445566
I used the select module like below
- name: show
debug:
msg: "{{train_custom_image_unmanaged_response.stderr_lines | select('search', 'describe') | list }}"
and it gives me this output
msg:
- ' $ gcloud ai custom-jobs describe projects/123456/locations/us-central1/customJobs/112233445566'
But I just want the job id as specified above. Any idea about that ?
Thanks.
You selected the line you are interested in. From that now you want to isolate the job id number in the end. You can do that using a regular expression like so:
- set_fact:
line: "{{train_custom_image_unmanaged_response.stderr_lines | select('search', 'describe') | list }}"
- debug:
msg: "{{ line | regex_search('.*/customJobs/(\\d+)', '\\1') }}"
This will give you all the digits in the end of the line after /customJobs/. See https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#searching-strings-with-regular-expressions
I've a huge yaml fixture like this. Is there a tidy sed one liner which can remove all the (key:value) for the products field?
- model: something
pk: 777
fields:
created: 2015-06-10 10:16:41.142044+00:00
modified: 2017-01-11 14:31:03.030313+00:00
name: something
products: [932, 3153, 3154]
- model: something2
...
I see I can use something like this, but how to delete up and until the first occurance of ']'?
sed '/^ products:/ d' < old.yaml > new.yaml
I have a very short (<20 rows) data set that looks like:
Effective_Date Pct
-------------- ---
01JAN2000 50%
...
11FEB2014 55%
13JUL2014 65%
I'd like to write a macro which takes a date, Eval_Date and returns the Pct which was effective on that date. To be clear, I know that this can be done with some kind of PROC SQL construction, but I want to write a function-style macro that can be used in the data step.
For example, %pct('12jul2014'd) should evaluate to 55%.
Assuming your source dataset is effpct and pct is numeric, formatted as percent., use it to create a format containing every day and the effective percent:
/* Merge without a by statement, using firstobs=2 to do a look-ahead join to
determine the 'effective to' date */
data pct_fmt ;
retain fmtname 'EFFPCT' type 'N' ;
merge effpct
effpct (firstobs=2 keep=effective_date rename=(effective_date=to_date)) ;
if missing(to_date) then to_date = date() ; /* Take last record up to current date */
do start = effective_date to (to_date - 1) ;
label = pct ;
output ;
end ;
run ;
/* 'Compile' the format */
proc format cntlin=pct_fmt ; run ;
/* Abstract put(var,format) into a function-style macro */
%MACRO PCT(DT) ;
put(&DT,EFFPCT.) ;
%MEND ;
/* Then use it in a datastep... */
data want ;
input date date9. ;
eff_pct = %PCT(date) ;
format eff_pct percent9. ;
datalines ;
01JAN2000
13FEB2014
20JUL2014
;
run ;
Or alternatively, use %SYSFUNC and putn to be able to convert a date to percent outside of a datastep, e.g. in a title statement :
%MACRO PCT2(DT) ;
%SYSFUNC(putn(%SYSFUNC(putn(&DT,EFFPCT.)),percent.))
%MEND ;
title "The effective pct on 09JUL2013 was %PCT2('09jul2013'd)" ;
Currently running a simple sinatra app, using passenger, and using pgbouncer for connection pooling to a database on the same server as the app. Currently I am intermittently getting a PG error that the prepared statement "a\d" doesn't exist.
A PG::Error occurred in #:
ERROR: prepared statement "a2" does not exist
the ruby code that is executed before the error
def self.get_ownership_record(id, key)
self.where("user_id=? AND key=?", id, key ).first
end
pgbouncer config
; #########################################################
; ############# SECTION HEADER [DATABASES] ################
; #########################################################
[databases]
fakedatabase=fake
[pgbouncer]
; ----- Generic Settings --------------------------
; -------------------------------------------------
logfile=/opt/local/var/log/pgbouncer/pgbouncer.log
pidfile=/opt/local/var/run/pgbouncer/pgbouncer.pid
listen_addr=*
listen_port=5444
; unix_socket_dir=/tmp
user=_webuser
auth_file=/Users/Shared/data/global/pg_auth
auth_type=trust
pool_mode=transaction
; max_client_conn=100
; default_pool_size=20
; reserve_pool_size=0
; reserve_pool_timeout=5
; server_round_robin=0
; ----- Log Settings ------------------------------
; -------------------------------------------------
; syslog=0
; syslog_ident=pgbouncer
; syslog_facility=daemon
; log_connections=1
; log_disconnections=1
; log_pooler_errors=1
; ----- Console Access Control --------------------
; -------------------------------------------------
admin_users=admin,nagios
; -------------------------------------------------
; server_reset_query=DISCARD ALL;
server_check_delay=0
server_check_query=SELECT 1;
; server_lifetime=3600
; server_idle_timeout=600
; server_connect_timeout=600
; server_login_retry=15
Is my only solution, to turn off prepared statements?
database.yml
production:
adapter: postgresql
database: fakedatabase
username: admin
host: localhost
port: 5444
reconnect: true
prepared_statements: false
EDIT
I have updated the pgbouncer.ini to use session pooling
pool_mode=session
and uncommented
server_reset_query=DISCARD ALL;
and I am still seemingly, randomly getting errors involving prepared statements, but this time
An ActiveRecord::StatementInvalid occurred in #:
PG::Error: ERROR: bind message supplies 2 parameters, but prepared statement "a1" requires 0
I have turned on statement level logging in my postgresql logs and will report back with more details if possible.
follwing Richard Huxton advice, and after some trial and error.
my final setup looks like
database.yml
had to set prepared_statements to true
production:
adapter: postgresql
database: fakedatabase
username: admin
host: localhost
port: 5444
reconnect: true
prepared_statements: true
pgbouncer.ini
had to uncomment server_reset_query=DISCARD ALL;
and set pool_mode=session
; #########################################################
; ############# SECTION HEADER [DATABASES] ################
; #########################################################
[databases]
fakedatabase=fake
[pgbouncer]
; ----- Generic Settings --------------------------
; -------------------------------------------------
logfile=/opt/local/var/log/pgbouncer/pgbouncer.log
pidfile=/opt/local/var/run/pgbouncer/pgbouncer.pid
listen_addr=*
listen_port=5444
; unix_socket_dir=/tmp
user=_webuser
auth_file=/Users/Shared/data/global/pg_auth
auth_type=trust
pool_mode=session
; max_client_conn=100
; default_pool_size=20
; reserve_pool_size=0
; reserve_pool_timeout=5
; server_round_robin=0
; ----- Log Settings ------------------------------
; -------------------------------------------------
; syslog=0
; syslog_ident=pgbouncer
; syslog_facility=daemon
; log_connections=1
; log_disconnections=1
; log_pooler_errors=1
; ----- Console Access Control --------------------
; -------------------------------------------------
admin_users=admin,nagios
; -------------------------------------------------
server_reset_query=DISCARD ALL;
server_check_delay=0
server_check_query=SELECT 1;
; server_lifetime=3600
; server_idle_timeout=600
; server_connect_timeout=600
; server_login_retry=15
basically allow prepared statements in a session pool mode with the default server reset query.
Perhaps reading the FAQ would help? Unless you have a good reason not to, session-pooling should be sensible.
In my case access to postgres directory and run "DEALLOCATE ALL" resolve the problem.
If you use heroku, like this
> heroku pg:psql -a app_name
app_name::DATABASE=> DEALLOCATE ALL
You can use transaction pooling, provided that you PREPARE and EXECUTE the prepared query inside the same transaction (to avoid pgBouncer running the server_reset_query in between).
I'm trying to define a rule where one element is the perfect candidate for the common terminal rule ID. When I launch the editor to test with sample code, the ID rule is not matched for the string "ABC":
Define : ABC : Holder_1
I get "mismatched input 'ABC' expecting RULE_ID".
Is there something in my grammar conflicting with the ID rule to cause this error?
This is my grammar file:
grammar com.testco.Test with org.eclipse.xtext.common.Terminals
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
generate defwiz "http://www.testco.com/Test"
Define_Holder:
'Definition' ':' holder_name=ID ':' holder_number=HOLDER_NUMBER (':' attribute=define_attr)? (':' pad=holder_pad)?
;
holder_pad:
HEX
;
Type:
TYPE_TERM ':' type_value=TYPE_VAL
;
//***************** TERMINALS *****************
terminal TYPE_TERM:
'Type_' INT+
;
terminal PROFILE:
(PROFILE_ID)(PROFILE_ID)'.'(PROFILE_ID)(PROFILE_ID)
;
terminal HOLDER_NUMBER returns ecore:: EString:
'Holder_' INT+;
terminal HEX returns ecore:: EString :
('0'..'9'|'A'..'F')
;
terminal PROFILE_ID : '^'?('a'..'z'|'A'..'Z') ('a'..'z'|'A'..'Z'|'0'..'9')*;
//***************** ENUMS *****************
enum define_attr:
BINARY='Binary' |
SCRAMBLE='Scramble' |
FORCESIZE='ForceSize' |
FIXEDSIZE='FixedSize'
;
Your rule PROFILE_ID shadows the ID rule for almost every case (except for the underscore).
Yes, it's likely that lexer scans ABC as HEX terminal. Try to define the latter, for example, as follows:
terminal HEX returns ecore:: EString :
'0x' ('0'..'9'|'A'..'F')
;