format
What’s the best way to format a phone number in Python?
for library: phonenumbers (pypi, source) Python version of Google’s common library for parsing, formatting, storing and validating international phone numbers. The readme is insufficient, but I found the code well documented.
How to add literal strings in a DateTime format?
Yes, you need to escape the word by putting it in ‘ marks dddd, d MMM, yyyy ‘at’ HH:mm Custom DateTime string formatting
Is it possible to specify custom error log format on Nginx?
You can’t specify your own format, but in nginx build-in several level’s of error_log-ing. Syntax: error_log file [ debug | info | notice | warn | error | crit ] Default: ${prefix}/logs/error.log Specifies the file where server (and fastcgi) errors are logged. Default values for the error level: in the main section – error in … Read more
How can I use a dynamic format string with the format! macro?
Short answer: it cannot be done. Long answer: the format! macro (and its derivatives) requires a string literal, that is a string known at compilation-time. In exchange for this requirement, if the arguments provided do not match the format, a compilation error is raised. What you are looking for is known as a template engine. … Read more
What does `:location => …` and `head :ok` mean in the ‘respond_to’ format statement?
render … :location => @user will set the HTTP location header to inform the client of the location of the newly created resource (that is, its URL) head :ok sets render to return an empty response (so just the header, no body) with status 200. head :ok is shorthand for render nothing: true, status: :ok. … Read more
Python format size application (converting B to KB, MB, GB, TB)
Fixed version of Bryan_Rch’s answer: def format_bytes(size): # 2**10 = 1024 power = 2**10 n = 0 power_labels = {0 : ”, 1: ‘kilo’, 2: ‘mega’, 3: ‘giga’, 4: ‘tera’} while size > power: size /= power n += 1 return size, power_labels[n]+’bytes’
How to get the given date string format(pattern) in java?
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.regex.Matcher; import java.util.regex.Pattern; public class NewClass { private static final String[] formats = { “yyyy-MM-dd’T’HH:mm:ss’Z'”, “yyyy-MM-dd’T’HH:mm:ssZ”, “yyyy-MM-dd’T’HH:mm:ss”, “yyyy-MM-dd’T’HH:mm:ss.SSS’Z'”, “yyyy-MM-dd’T’HH:mm:ss.SSSZ”, “yyyy-MM-dd HH:mm:ss”, “MM/dd/yyyy HH:mm:ss”, “MM/dd/yyyy’T’HH:mm:ss.SSS’Z'”, “MM/dd/yyyy’T’HH:mm:ss.SSSZ”, “MM/dd/yyyy’T’HH:mm:ss.SSS”, “MM/dd/yyyy’T’HH:mm:ssZ”, “MM/dd/yyyy’T’HH:mm:ss”, “yyyy:MM:dd HH:mm:ss”, “yyyyMMdd”, }; /* * @param args */ public static void main(String[] args) { String yyyyMMdd = “20110917”; parse(yyyyMMdd); … Read more
Common Lisp’s equivalent of \r inside the format function?
Characters for return and linefeed \r is the character #\return in Common Lisp. \n is the character #\linefeed in Common Lisp. The following ends the string “Hello world.” with return and linefeed. (format t “Hello world.~C~C” #\return #\linefeed) #\newline is whatever the platform uses as a line division. On Unix machines this is often the … Read more
warning: format not a string literal and no format arguments
This warning is gcc’s way of telling you that it cannot verify the format string argument to the printf style function (printf, fprintf… etc). This warning is generated when the compiler can’t manually peek into the string and ensure that everything will go as you intend during runtime. Lets look at a couple of examples. … Read more