I saw the following code in the DataMapper documentation, the Serial, String.. all align together, Can I do the same thing in Vim?
class Post
include DataMapper::Resource
property :id, Serial # An auto-increment integer key
property :title, String # A varchar type string, for short strings
property :body, Text # A text block, for longer string data.
property :created_at, DateTime # A DateTime, for any date you might like.
end
You can try Tabularize.vim plugin. Run this command:
:Tabularize /:\w\+,\|#/
What you need is a pattern to match the delimiters.
:\w\+, will match :id,, :title,, ...
# will match the comment sign
Related
I am using f-strings for formatting strings and injecting variable values into the string, is there a way to set a format-spec for an entire module in python?
I am aware of Standard Format Specifiers which can be used to specify formats for each string, but how do I do it at once for the whole module?
Eg:
f""" Some random string {value1}, some more text {value2:.2f} ... """
Here I am specifying the format for value2, but I want to set a format for all globally.
f"""% profits are {profit}"""
Had I set format spec to {profit:.2f} this will be set to two decimal places, but I want to set that :.2f globally so that number decimal places can be changed with one variable update.
Something like format-spec = ':.2f' and all the f-string injected values should be displayed as floats with two decimals (if its a numbers).
If I understand you correctly, you want to define a string format one time that is usable throughout a script. I would create a function, callable from anywhere in your script that produces the formatted string as shown below:
def create_string(v_str: str, v_num: float) -> str:
return f""" Some random string {v_str}, some more text {v_num:.2f} ... """
You can then use the create_string function from anywhere in your script and produce the desired output as illustrated below:
print(create_string('Some words here', 2.56))
which yields:
Some random string Some words here, some more text 2.56 ...
I'm trying to split a string (separated with the HTML break tag), without deleting the break tag. I think it's pretty messy to add a break as string after splitting, so is there any function/possibility to keep the separator while "splitting"?
Example:
<HTML><BODY><p>some text<br/>some more text</p></BODY></HTML>
Expected result:
<HTML><BODY><p>some text<br/>
some more text</p></BODY></HTML>
As far as I know SPLIT removes the separator from the results and it doesn't seem like you can change that.
But you could create your own separator by first replacing your <br/> tag with <br/> plus an arbitrary string that is highly unlikely to ever appear in your HTML source, and then split the HTML using this arbitrary string as a separator instead.
types:
begin of t_result,
segment(2000) type c,
end of t_result.
DATA:
source type string,
separator type string,
brtag type string,
repl type string,
result_tab type standard table of t_result,
result_row TYPE t_result.
brtag = '<br/>'.
separator = '|***SEP***|'.
concatenate brtag separator into repl.
source = '<HTML><BODY><p>some text<br/>some more text</p></BODY></HTML>'.
replace all occurrences of brtag in source with repl.
split source at separator into table result_tab.
LOOP AT result_tab INTO result_row.
WRITE:
result_row-segment.
ENDLOOP.
Output of that example report:
<HTML><BODY><p>some text<br/>
some more text</p></BODY></HTML>
The caveat of this solution is that your custom separator, if not chosen with some care, might appear in your HTML source on its own. I therefore would choose an arbitrary string with a special character or two that would be encoded in HTML (like umlauts) and therefore not appear in your source.
Just use the replace command. replace <br/> with <br/>CR_LF
The CR_LF refers to the carriage return linefeed character.
In more complex cases you can use regex expressions in abap.
class ZTEST_SO definition public create public .
public section.
methods t1.
ENDCLASS.
CLASS ZTEST_SO IMPLEMENTATION.
METHOD T1.
data: my_break type string,
my_string type string
value '<HTML><BODY><p>some text<br/>some more text</p></BODY></HTML>'.
my_break = '<br/>' && CL_ABAP_CHAR_UTILITIES=>CR_LF.
replace all occurrences of '<br/>' in my_string with my_break in character mode.
"check my_string in the debugger :)
"<HTML><BODY><p>some text<br/>
"some more text</p></BODY></HTML>
ENDMETHOD.
ENDCLASS.
I'm trying to use Grok expressions in Athena, mostly as a tool to debug Grok expressions in AWS Glue Classifiers.
This works:
CREATE EXTERNAL TABLE example_grok (
myColumn string
)
ROW FORMAT SERDE
'com.amazonaws.glue.serde.GrokSerDe'
WITH SERDEPROPERTIES (
'input.format'='(%{WORD:header},%{WORD:file_type},%{GREEDYDATA:head_rest})|(%{DETAILS:det},%{WORD:icp_number},%{GREEDYDATA:det_rest})',
'input.grokCustomPatterns' = 'DETAILS DET'
)
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
's3://my-secret-bucket/path/';
I would like to specify several custom patterns, but the documentation doesn't have an example, and none of the delimiters that I have tried, either inside or outside of the string, have worked.
For example, these do NOT work
New line delimited (with no leading spaces, those are just for this post):
'input.grokCustomPatterns' =
'POSTFIX_QUEUEID [0-9A-F]{7,12}
HEADER HDR'
As a "json" array:
'input.grokCustomPatterns' = ['POSTFIX_QUEUEID [0-9A-F]{7,12}','HEADER HDR']
With multiple entries:
'input.grokCustomPatterns'='HEADER (HDR)',
'input.grokCustomPatterns'='POSTFIX_QUEUEID [0-9A-F]{7,12}',
Any assistance is appreciated,
AWS responded to the documentation improvement that I requested. A literal \n separates patterns.
To include multiple pattern entries into the input.grokCustomPatterns
expression, use the newline escape character (\n) to separate them, as
follows: 'input.grokCustomPatterns'='INSIDE_QS
([^\"])\nINSIDE_BRACKETS ([^\]])').
Grok Serde
I'm currently using node-postgres to query my DB like so:
SELECT DISTINCT(name) FROM users.names ORDER BY name;
I want to return the lowercase of these names, so I've tried this:
SELECT DISTINCT(lower(name)) FROM users.names ORDER BY lower(name);
...but this just returns null in place of each name.
This solved it:
SELECT DISTINCT(LOWER(tag)) AS tag FROM support.tags ORDER BY LOWER(tag);
The key addition is obviously AS tag, otherwise the 'tag' field was renamed to 'lower' in the results set.
I have something like:
def newProps = new Properties()
def fileWriter = new OutputStreamWriter(new FileOutputStream(propsFile,true), 'UTF-8')
def lineSeparator = System.getProperty("line.separator")
newProps.setProperty('SFTP_USER_HASH', userSftpHome.toString())
newProps.setProperty('GD_SFTP_URI', sftpHost.toString())
fileWriter.write(lineSeparator)
newProps.store(fileWriter, null)
fileWriter.close()
The problem is that store() method escapes ":" or "=" characters with backslash (). I don't want that because I store there some passwords and tokens and need to copy those values strictly in the key=value format.
Also, when I use the configSlurper, it stores the values with single quotes, like:
key='value'
Is there any solution for that? Saving in unescaped key=value format to properties file in Groovy?
You could do this:
def newProps = new Properties()
newProps.setProperty('SFTP_USER_HASH', 'woo')
newProps.setProperty('GD_SFTP_URI', 'ftp://woo.com')
propsFile.withWriterAppend( 'UTF-8' ) { fileWriter ->
fileWriter.writeLine ''
newProps.each { key, value ->
fileWriter.writeLine "$key=$value"
}
}
BUT, so long as you are reading the properties in with load, there should be no need for this as it should de-escape any escaped characters
The JDK's built in Properties class does that escaping by design. According to the Docs:
Then every entry in this Properties table is written out, one per
line. For each entry the key string is written, then an ASCII =, then
the associated element string. For the key, all space characters are
written with a preceding \ character. For the element, leading space
characters, but not embedded or trailing space characters, are written
with a preceding \ character. The key and element characters #, !, =,
and : are written with a preceding backslash to ensure that they are
properly loaded.
You can however, override this behavior by sub-classing the Properties class yourself. You'd need to override the load and store methods yourself and read/write yourself. It would be pretty straight forward; pretty good examples found here: Link