Which setting cause rip of format in Android Studio? - android-studio

I encounter an annoying issue with Android studio. I have nicely and easy readable formatted piece of code:
But if I press Code - reformat code, my string declaration turns in complete mess:
It would not be a problem if only new line characters were removed, but Code - reformat code also split my strings and make empty line insertions (WTF)
Compare string before reformat:
private static final String
DATABASE_CREATE =
"create table "
+ TABLE_NAME + "("
+ COLUMN_ID + " integer primary key autoincrement, "
+ COLUMN_ITEM_ID + " integer default '0', "
+ COLUMN_SLUG + " text default '',"
+ COLUMN_TITLE + " text default '',"
+ COLUMN_TYPE + " integer default '0', "
+ COLUMN_YOUTUBE_ID + " text default '',"
+ COLUMN_ARTISTS + " text default '',"
+ COLUMN_ARTISTS_SLUG + " text default '',"
+ COLUMN_DESCRIPTION + " text default '',"
+ COLUMN_PICTURE + " text default '',"
+ COLUMN_SOURCE + " text default '',"
+ COLUMN_VIEW_COUNT + " integer '0',"
+ COLUMN_GOOGLE_LINK + " text default '',"
+ COLUMN_OFFLINE_SOURCE + " text default '',"
+ COLUMN_IS_SAVED_OFFLINE + " integer '0', "
+ COLUMN_OFFLINE_PLAYS + " integer default '0',"
+ COLUMN_DOWNLOADING_ID + " integer default '-1',"
+ COLUMN_IS_LIKE + " integer default '0' " +
");";
and string after reformat:
private static final String
DATABASE_CREATE =
"create table " + TABLE_NAME + "(" + COLUMN_ID + " integer primary key autoincrement, " +
"" + COLUMN_ITEM_ID + " integer default '0', " + COLUMN_SLUG + " text " +
"default ''," + COLUMN_TITLE + " text default ''," + COLUMN_TYPE + " integer " +
"default '0', " + COLUMN_YOUTUBE_ID + " text default ''," +
"" + COLUMN_ARTISTS + " text default ''," + COLUMN_ARTISTS_SLUG + " text " +
"default ''," + COLUMN_DESCRIPTION + " text default ''," +
"" + COLUMN_PICTURE + " text default ''," + COLUMN_SOURCE + " text default " +
"''," + COLUMN_VIEW_COUNT + " integer '0'," + COLUMN_GOOGLE_LINK + " text " +
"default ''," + COLUMN_OFFLINE_SOURCE + " text default ''," +
"" + COLUMN_IS_SAVED_OFFLINE + " integer '0', " + COLUMN_OFFLINE_PLAYS + " " +
"integer default '0'," + COLUMN_DOWNLOADING_ID + " integer default '-1'," +
"" + COLUMN_IS_LIKE + " integer default '0' " +
");";
You clearly can see lots of "" which were not present before.
How to fix such strange behaviour?

Related

NodeJS string concatenation unusual behaviour

I am trying to construct this string for printing one message.
"At position #[" + index + "][" + _subIndex + "] TLPHN_DVC_TYP " +
+ _telNum?.TelephoneDeviceType.toString() + " ,allowed " + telephoneDeviceTypeEnum.join(',');
from watch is VsCode:
where index =0;_subIndex =0;telNum.TelephoneDeviceType =Mobile;telephoneEnum=["Mobile","Landline"];
It's returning :
At position #[0][0] TLPHN_DVC_TYP NaN ,allowed Mobile,Landline
Full Code:
if (_telNum?.TelephoneDeviceType && !(telephoneDeviceTypeEnum.indexOf(_telNum.TelephoneDeviceType) > 0)){
console.log( "At position #[" + index + "][" + _subIndex + "] TLPHN_DVC_TYP " +
+ _telNum?.TelephoneDeviceType.toString() + " ,allowed " + telephoneDeviceTypeEnum.join(','));
}
the condition should not satisfy but not sure why it's going inside the if and NaN returning. any suggestion?
It's the two plus signs: "] TLPHN_DVC_TYP " + + _telNum?// ...etc. The second one is parsed as the unary +, or a conversion to number, which obviously fails. Compare:
console.log("foo" + "bar");
console.log("foo" + + "bar");
Added #1:
if (_telNum?.TelephoneDeviceType && !(telephoneDeviceTypeEnum.indexOf(_telNum.TelephoneDeviceType) >= 0)){
console.log( "At position #[" + index + "][" + _subIndex + "] TLPHN_DVC_TYP " +_telNum?.TelephoneDeviceType.toString() + " ,allowed " + telephoneDeviceTypeEnum.join(','));
}

Nodejs, asny to sync

I am quite new to NodeJs and need some help regarding flow.
So, I need to change some lib as it does not work for me. I have asny call and then right a way i have sync code. The thing is that sync code starts executing before asny part return data.
asny:
xmlenc.encrypt(message, options509, function(err, result) {
console.log("error:", err)
message = result
return message;
})
sync right after asyn:
xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<" + envelopeKey + ":Envelope " +
xmlnsSoap + " " +
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
encoding +
this.wsdl.xmlnsInEnvelope + '>' +
((self.soapHeaders || self.security) ?
(
"<" + envelopeKey + ":Header>" +
(self.soapHeaders ? self.soapHeaders.join("\n") : "") +
(self.security && !self.security.postProcess ? self.security.toXML() : "") +
"</" + envelopeKey + ":Header>"
)
:
''
) +
"<" + envelopeKey + ":Body" +
(self.bodyAttributes ? self.bodyAttributes.join(' ') : '') +
(self.security && self.security.postProcess ? ' Id="_0"' : '') +
">" +
genXML() +
"</" + envelopeKey + ":Body>" +
"</" + envelopeKey + ":Envelope>";
How to solve this that the progrem with wait for asyn part to return before moving to sync part.
thank you

Expression was too complex to be solved in reasonable time;

I have just upgraded from Xcode 8.3 to Xcode 9.4 and it kept indexing until it crashed, then it output an error.
Swift - Expression was too complex to be solved in reasonable time;
consider breaking up the expression into distinct sub-expressions
Is this a bug in Xcode 9 and Swift 4.1?
let fromString = convenience.getTimeAsString(timeStamp: timeStampDateAndTime, timeFormat: "HH:mm")
let toString = convenience.getTimeAsString(timeStamp: toTimeStamp, timeFormat: "HH:mm")
var cellData = "Booking: " + booking.BookingNumber + "\n" + "Area: " + booking.Locality + "\n" + "Postcode: " + booking.PostCode + "\n" + "Time: " + fromString + " - " + toString
How I fixed it?
var cellData = " \("Booking: ") \(booking.BookingNumber) \("\n") \("Area: ") \(booking.Locality) \("\n") \("Postcode: ") \(booking.PostCode) \("\n") \("Time: ") \(fromString) \(" - ") \(toString) "

How can I format this String with double x,y,total to two decimal places. output = (x + " + " + y + " = " + total);

How can I format this String with double x,y,total to two decimal places. String output = (x + " + " + y + " = " + total);
String ouput = String.format("%.2f + %.2f = %.2f",x,y,total);
System.out.println(output);
will give you the output with 2 decimal places or you can use DecimalFormat as well.

Get IP Address, Browser Type MVC 5

I need to get local system ip address and browser agent (firefox,chorme,ie,etc..) in MVC 5. Search google Request.ServerVariables["REMOTE_ADDR"] which is not working in MVC5
For getting IP Address use this code:
public static string GetIPAddress(HttpRequestBase request)
{
string ip;
try
{
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ip))
{
if (ip.IndexOf(",") > 0)
{
string[] ipRange = ip.Split(',');
int le = ipRange.Length - 1;
ip = ipRange[le];
}
}
else
{
ip = request.UserHostAddress;
}
}
catch { ip = null; }
return ip;
}
https://stackoverflow.com/a/7348761/4568359
================================================================
And for getting browser info:
System.Web.HttpBrowserCapabilities browser = Request.Browser;
string brw_info = "Browser Capabilities\n"
+ "Type = " + browser.Type + "\n"
+ "Name = " + browser.Browser + "\n"
+ "Version = " + browser.Version + "\n"
+ "Major Version = " + browser.MajorVersion + "\n"
+ "Minor Version = " + browser.MinorVersion + "\n"
+ "Platform = " + browser.Platform + "\n"
+ "Is Beta = " + browser.Beta + "\n"
+ "Is Crawler = " + browser.Crawler + "\n"
+ "Is AOL = " + browser.AOL + "\n"
+ "Is Win16 = " + browser.Win16 + "\n"
+ "Is Win32 = " + browser.Win32 + "\n"
+ "Supports Frames = " + browser.Frames + "\n"
+ "Supports Tables = " + browser.Tables + "\n"
+ "Supports Cookies = " + browser.Cookies + "\n"
+ "Supports VBScript = " + browser.VBScript + "\n"
+ "Supports JavaScript = " +
browser.EcmaScriptVersion.ToString() + "\n"
+ "Supports Java Applets = " + browser.JavaApplets + "\n"
+ "Supports ActiveX Controls = " + browser.ActiveXControls
+ "\n"
+ "Supports JavaScript Version = " +
browser["JavaScriptVersion"] + "\n";
https://msdn.microsoft.com/en-us/library/3yekbd5b.aspx
To get client IP Address
var IPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(IPAddress))
{
IPAddress = Request.ServerVariables["REMOTE_ADDR"];
}
To get client user agent.
var userAgent = Request.UserAgent;
You are looking for something like to get Ip address
HttpRequest.UserHostAddress Property
and check out this for browser detection 51Degrees.Mobi Foundation

Resources