Clang-format multiple conditions new line - clang

If I have a code something like this
void function()
{
return XXXXXXXXX && FFFFFFFFFFFFFF && MMMMMMMMMMMMMM;
}
How can I convert it in something like this
void function()
{
return XXXXXXXXX &&
FFFFFFFFFFFFFF &&
MMMMMMMMMMMMMM;
}

clang-format won't break a line like that unless you have reached the line limit, you can align the operands with:
AlignOperands: Align
you might want to check out
BreakBeforeBinaryOperators : All
You can find descriptions of these here:
https://clang.llvm.org/docs/ClangFormatStyleOptions.html

Related

How to write a loop in REPL mode?

I would like to execute a loop in REPL mode but I am getting a SyntaxError: expecting '('
var methods = eval(ObjC.classes.UIViewController.$methods);
for item in methods { console.log(item) }
Here is an example for iterating and invoking class methods
var UIDevice = ObjC.classes.UIDevice.currentDevice();
UIDevice.$ownMethods
.filter(function(method) {
return method.indexOf(':') == -1 /* filter out methods with parameters */
&& method.indexOf('+') == -1 /* filter out public methods */
})
.forEach(function(method) {
console.log(method, ':', UIDevice[method]())
})
Update:
var UIViewControllerInstance = ObjC.chooseSync(ObjC.classes.UIViewController)[0];
console.log('Sanity check =', UIViewControllerInstance, JSON.stringify(UIViewControllerInstance.$ownMethods, null, 2));
UIViewControllerInstance.$ownMethods
.filter(method => { return method.indexOf(':') == -1 && method.indexOf('+') == -1 })
.forEach(method => {
console.log(method, ':', UIViewControllerInstance[method]())
})
Instead of looking for UIViewController instances on the heap, you have direct access through UIApplication
take a look # https://frida.re/docs/examples/ios/
This problem is related to command line shells and not to Frida or any other REPL tool.
This is a Single command and multiple lines subject of a shell in terminals.
To solve it, all you need to do is to add "\" at the end of each line.
Example:
var methods = eval(ObjC.classes.UIViewController.$methods);\
for (item in methods) { console.log(item) }\

Only accept numerics characters in textbox

I try to do a things very easy but it doesn't works...
I want my textbox accepts only numerics characters. I found a lot of parts of code on internet but none working...
I try this code for example :
private void TxtNumPoste_TextChanged(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) &&
(e.KeyChar != '.'))
{
e.Handled = true;
}
// only allow one decimal point
if ((e.KeyChar == '.') && ((sender as TextBox).Text.IndexOf('.') > -1))
{
e.Handled = true;
}
}
TxtNumPoste is the name of my TextBox.
Is a person sees an error ?
Thanks for your help.

Java compiling wrong old file

I have a java app that runs an infinite while loop. When I click run on eclipse it seems to be reverting to old code that I have changed. The thing is, when I build it updates at random times. The latest time I added System.exit(). I changed the code and it still exits. I have also tried this program in C#. I feel that I am somehow confusing the language runtime with the infinite while loop. The program works on a series of changing boolean values. The main action I am looking at the erratic behavior (this was what was happening before I added System.exit()) is in a method that iterates pixels in a BufferedImage. I am running Ubuntu 14.10. I have tried making a new project and pasting the same code (could it be invisible chars somehow?) I am very confused and would be happy if someone could help.
while(true){
if (bool1 && !exe.isSeparate(image))
{
// change boolean values
// did run System.exit(0)
}
if (bool2 && !exe.isSeparate(image))
{
// change boolean values
// did run System.exit(0)
}
}
boolean isSeparate(BufferedImage image)
{
int x = touchingX;
boolean first = false, second = false, third = false;
int startAt = this.getYStart(image);
for (int y = startAt; y < startAt + 150; y++)
{
Color pixel = new Color(image.getRGB(x, y));
if (!(pixel.getRed() == 255 && pixel.getGreen() == 255 && pixel.getBlue() == 255)
&& !(pixel.getRed() == 0 && pixel.getGreen() == 68 && pixel.getBlue() == 125))
{
if (!first)
{
first = true;
}
if (first && second && !third)
{
third = true;
}
}
else
{
if (first && !second)
{
second = true;
}
}
}
if (first && second && third)
{
return true;
}
return false;
}
I have answered my question. Ironically, it was a logic error.

jshint no error for forin (hasOwnProperty)

Why jshint is not reporting forin (hasOwnProperty) error for the following code? jslint do report error on it but jshint doesn't.
/*jshint forin: true */
(function () {
"use strict";
var obj = {a: 1, b: 2}, i = null;
for (i in obj) {
if (i === 0) {
console.log('blah...');
}
}
}());
Here's the relevant snippet of code from JSHint (modified slightly for formatting):
if (
state.option.forin &&
s &&
(s.length > 1 || typeof s[0] !== "object" || s[0].value !== "if")
) {
warning("W089", this);
}
The important part is s[0].value !== "if". JSHint won't raise an error if the first statement of the for...in body is an if statement, regardless of the condition of that statement.

Formatting Data in Textbox to $###,###,###,##0.00

I have a textbox where I always want data in $###,###,###,##0.00 format (like $25.00 ). Now on typing some data i want to get the same format . For ex if i type 25 it should convert to $25.00 and if i input 'as23afs' (characters) it should convert to $0.00 . How can i do it? Please suggest a solution. If I can make use of Regular expressions how can i do it?
Take a look at those plugins:
http://digitalbush.com/projects/masked-input-plugin/
http://www.meiocodigo.com/projects/meiomask/
http://www.decorplanit.com/plugin/
i was facing the same issue now i fixed that by set the textbox custom Format:
use this code in KeyPress Event :
private void yourtextbox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.Handled = !char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 && e.KeyChar != ',' && e.KeyChar != '$') // 8 is back space
{
if (e.KeyChar == (char)13) // 13 is Enter
{
yourtextbox.Text = string.Format("${0:#,##0.00}", double.Parse(yourtextbox.Text));
}
}
}
Now your Textbox accept only numbers and ',' and '$'
now if you input 'as23afs' (characters) it should convert to $0.00 .
use this code :
yourtextbox.Text = double.Parse("0").ToString("N2");//"N2" to show 00 after ','.
i think that's all i hope this code help everyone looking for currency Format in textbox .
so the complete code should be like that :
public Form1()
{
InitializeComponent();
yourtextbox.Text = double.Parse("0").ToString("N2");//"N2" to show 00 after ','
}
private void yourtextbox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.Handled = !char.IsDigit(e.KeyChar) && e.KeyChar != (char)8 && e.KeyChar != ',' && e.KeyChar != '$') // 8 is back space
{
if (e.KeyChar == (char)13) // 13 is Enter
{
yourtextbox.Text = string.Format("${0:#,##0.00}", double.Parse(yourtextbox.Text));
}
}
}

Resources