i tried the below code.
{
"Topic": "If statement",
"C": "if ( condition )\r\n { code ;}\r\nelse if( condition )\r\n { code; }\r\nelse \r\n { code; }",
"C++": "if ( condition )\r\n { code ;}\r\nelse if( condition )\r\n { code; }\r\nelse \r\n { code; }",
"JAVA": "if ( condition )\r\n { code ;}\r\nelse if( condition )\r\n { code; }\r\nelse \r\n { code; }",
"PHP": "if ( condition )\r\n { code ;}\r\nelse if( condition )\r\n { code; }\r\nelse \r\n { code; }",
"JS": "if ( condition )\r\n { code ;}\r\nelse if( condition )\r\n { code; }\r\nelse \r\n { code; }",
"PL/SQL": "if (conditio) then \r\n {code;}\r\nelsif (conditon) then \r\n {code;}\r\nelse \r\n {code;}",
"VBNET": "If condition Then\r\n code\r\nElse If condition Then\r\n code\r\nElse\r\n code\r\nEnd If",
"PYTHON": "if ( condition ):\r\n code\r\nelif ( condition ):\r\n code\r\nelse: \r\n code"
},
But new line is not showing.1
From here:
The textarea formater shows text with carriage returns intact (great for multiline text), this formatter will also adjust the height of rows to fit the cells contents when columns are resized.
{title:"Example", field:"example", formatter:"textarea"}
Related
Can someone please clarify below issue.
Below validation throw NULL pointer error when pass null in myVar. It is because of !myVar.isEmpty()
if (myVar!= null || !myVar.isEmpty() ) {
some code///
}
Below works though as expected,
if (myVar!= null) {
if (!myVar.isEmpty()) {
some code///
}
Any other way of having both steps together.
If .isEmpty() is used on a string, then you can also just use Groovy
"truth" directly, as null and also empty strings are "false".
[null, "", "ok"].each{
if (it) {
println it
}
}
// -> ok
if ( myVar!= null && !myVar.isEmpty() ) {
//some code
}
the same as
if ( !( myVar== null || myVar.isEmpty() ) ) {
//some code
}
and to make it shorter - it's better to add method like hasValues
then check could be like this:
if( myVar?.hasValues() ){
//code
}
and finally to make it groovier - create a method boolean asBoolean()
class MyClass{
String s=""
boolean isEmpty(){
return s==null || s.length()==0
}
boolean asBoolean(){
return !isEmpty()
}
}
def myVar = new MyClass(s:"abc")
//in this case your check could be veeery short
//the following means myVar!=null && myVar.asBoolean()==true
if(myVar) {
//code
}
I am working on a function to find a field from any form based on the label text. I'd like to return different attributes of the field so that I can use them later.
Originally, I just needed the value of the field, so I used the work here to return the value of a field based on the label:
function itsg_get_value_by_label( $form, $entry, $label ) {
foreach ( $form['fields'] as $field ) {
$lead_key = $field->label;
if ( strToLower( $lead_key ) == strToLower( $label ) ) {
return $entry[ $field->id ];
}
}
return false;
}
I get my value by setting a variable and passing in the field label that I'm looking for:
$mobile_phone = itsg_get_value_by_label( $form, $entry, "Mobile Phone" );
Later on, as I continued to work on my solution, I found that I also needed to find those fields and return the ID. Initially, I wrote the same function and just returned the ID, but I'd like to make the solution more efficient by rewriting the function to return multiple field attributes in an array, as such:
function get_field_atts_by_label( $form, $entry, $label ) {
foreach ( $form['fields'] as $field ) {
$lead_key = $field->label;
if ( strToLower( $lead_key ) == strToLower( $label ) ) {
$field_atts = array(
'value' => $entry[ $field->id ],
'id' => $field->id,
);
return $field_atts;
}
}
return false;
}
My problem now is that I am not quite sure how to retrieve the specific attributes from my function and set them to a variable.
Well, I'll go ahead and answer my own question. Such a simple solution to this one. Had a momentary brain fart.
$mobile_phone = get_field_atts_by_label( $form, $entry, "Mobile Phone" );
$mobile_phone_id = $mobile_phone['id'];
$mobile_phone_value = $mobile_phone['value'];
I made a helper which is meant to help me debug my app.
It firsts display a header.
Then it tries to run a block of code which returns a fews arguments (array of objects).
Those arguments are used in a string format which is displayed when the block ran fine.
If the block caused an exception, the exception gets displayed.
The problem is, nothing gets displayed at all when I call the helper (I'm very new to that feature).
What's wrong?
#{
Layout = "~/Views/Shared/_Layout.cshtml";
}
#using MygLogWeb.Classes.Fox
<span>test</span>
#helper TryMethod(
string header
, Func<object[]> act
, string successFormat
)
{
#Html.Raw(String.Format(
#"<h2>{0}</h2>"
, HttpUtility.HtmlEncode(header)
));
try
{
var args = act();
if (successFormat == null)
{
#Html.Raw(#"<span class='Success'>OK</span>");
}
else
{
#Html.Raw(String.Format(
#"<span class='Success'>{0}</span>"
, HttpUtility.HtmlEncode(String.Format(
successFormat
, args
))
));
}
}
catch (Exception exe)
{
#Html.Raw(String.Format(
#"<span class='Error'>{0}</span>"
, HttpUtility.HtmlEncode(exe.Message)
));
}
}
<span>test</span>
#{
TryMethod(
"Cust.Columns"
, () => {
return new object[]
{
Cust.Columns.Count
};
}
, "Count: {0}"
);
}
<span>test</span>
The problem is not with the helper method itself but with the execution.
When you execute like this:
#{
TryMethod(...);
}
the code is executed but it's a code block but not written to output.
Use this syntax instead:
#(TryMethod(...))
this should work.
I have a custom multi-select drop-down element in one of my kendo grid header columns titled "Status". Each selection in the drop-down represents many statuses, but they are grouped together for simplicity, and so we can show groups of like statuses.
Since this is a custom filter, I know I have to manipulate the kendo filter manually, and this seems to be giving me fits.
When any selection is changed in my custom drop-down, I fire off a function to modify the filters (the section where I spin through the status array has been truncated for easier reading):
// Apply the status filters from the multi-select drop down
function applyStatusFilter(statusValues) {
var gridData = $("#accountsGrid").data("kendoGrid");
var currentFilterObj = gridData.dataSource.filter();
var currentFilters = currentFilterObj ? currentFilterObj.filters : []; // If there are no current filters, set to empty array
var statusFilters = { logic: "or", filters: [] };
var statusArray = statusValues.split(','); // Convert status selections to array
// Remove any pre-existing status filters from the existing filter
if (currentFilters && currentFilters.length > 0) {
for (var i = 0; i < currentFilters.length; i++) {
if (currentFilters[i].field == 'status') {
currentFilters.splice(i, 1);
//break;
}
}
}
if (statusArray[0].length > 0) {
$.each(statusArray, function (key, value) {
if (value == 'AC') {
statusFilters.filters.push({
field: "status",
operator: "eq",
value: "A"
});
statusFilters.filters.push({
field: "status",
operator: "eq",
value: "G"
});
statusFilters.filters.push({
field: "status",
operator: "eq",
value: "O"
});
if (value == 'OH') {
statusFilters.filters.push({
field: "status",
operator: "eq",
value: "G"
});
statusFilters.filters.push({
field: "status",
operator: "eq",
value: "H"
});
statusFilters.filters.push({
field: "status",
operator: "eq",
value: "I"
});
}
});
}
currentFilters.push(statusFilters);
gridData.dataSource.filter({
logic: "and",
filters: currentFilters
});
}
This isn't working as expected, although it's still a work in progress. There are two main issues; when I call this function, I want to remove all current "status" related filters, then rebuild. I can't clear all filters, as I need to maintain other column filters that might be applied. My remove status filters block doesn't seem to be working.
Second big issue, is how to properly combine two filter objects; when one can be a nested blocked of status filters using "or" logic, then combining it to any possible existing filters using "and" logic between the two filter objects.
About your first issue. There are sure several ways to remove all current "status" related filters, but I have built a recursive function that clear the filters for a given column.
function clearFilter(filter, columnToClear) {
if (filter == undefined)
return filter;
if (filter.logic != undefined) {
filter.filters = $.map(filter.filters, function (val) {
if (val.field == undefined && typeof (val.filters) == "object" && typeof (val.logic) == "string") {
val.filters = clearFilter(val.filters, columnToClear)
if (val.filters.length == 0)
val = null;
return val;
}
else if (val.field != columnToClear)
return val;
});
if (filter.filters.length == 0)
filter = null;
}
else {
filter = $.map(filter, function (val) {
if (val.field != columnToClear)
return val;
});
}
return filter;
}
In your case the function should be called as:
clearFilter(currentFilterObj, "status");
I have two TCP-server apps that are based on the same code, but for some reason exhibit different behavior and i'm ready to pull my hair out trying to figure out why. The code pattern is as follows:
public class TcpServer
{
public static void Start( bool bService )
{
..
oTcpListnr= new TcpListener( ip, iOutPort );
aTcpClient= new ArrayList( );
bListen= true;
oTcpListnr.Start( );
thOutComm= new Thread( new ThreadStart( AcceptTcpConn ) );
thOutComm.Name= "App-i.AcceptTcpConn";
thOutComm.Start( );
..
}
public static void Stop( )
{
bListen= false;
if( thOutComm != null )
{
thOutComm.Join( iTimeout );
thOutComm= null;
}
if( oTimer != null )
{
oTimer.Change( Timeout.Infinite, Timeout.Infinite );
oTimer.Dispose( );
}
}
public static void AcceptTcpConn( )
{
TcpState oState;
Socket oSocket= null;
while( bListen )
{
try
{
// if( oTcpListnr.Pending( ) )
{
oSocket= oTcpListnr.AcceptSocket( );
oState= new TcpState( oSocket );
if( oSocket.Connected )
{
Utils.PrnLine( "adding tcp: {0}", oSocket.RemoteEndPoint.ToString( ) );
Monitor.Enter( aTcpClient );
aTcpClient.Add( oState );
Monitor.Exit( aTcpClient );
oSocket.SetSocketOption( SocketOptionLevel.IP, SocketOptionName.DontFragment, true );
oSocket.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.DontLinger, true );
// / oSocket.BeginReceive( oState.bData, 0, oState.bData.Length, SocketFlags.None, // no need to read
// / new AsyncCallback( AsyncTcpComm ), oState ); // for output only
}
else
{
Utils.PrnLine( "removing tcp: {0}", oSocket.RemoteEndPoint.ToString( ) );
Monitor.Enter( aTcpClient );
aTcpClient.Remove( oState );
Monitor.Exit( aTcpClient );
}
}
// Thread.Sleep( iTcpWake );
}
#region catch
catch( Exception x )
{
bool b= true;
SocketException se= x as SocketException;
if( se != null )
{
if( se.SocketErrorCode == SocketError.Interrupted )
{
b= false;
if( oSocket != null )
Utils.PrnLine( "TcpConn:\tclosing tcp: {0} ({1})", oSocket.RemoteEndPoint.ToString( ), se.SocketErrorCode );
}
}
if( b )
{
Utils.HandleEx( x );
}
}
#endregion
}
}
}
I omitted exception handling in Start/Stop methods for brevity. Variation in behavior is during program termination: one app shuts down almost immediately while the other gets stuck in oTcpListnr.AcceptSocket( ) call. I know that this is a blocking call, but in that case why does it not present an issue for the 1st app?
Usage of this class cannot be any simpler, e.g. for a command-line tool:
class Program
{
public static void Main( string[] args )
{
TcpServer.Start( false );
Console.Read( );
Console.WriteLine( "\r\nStopping.." );
TcpServer.Stop( );
Console.WriteLine( "\r\nStopped. Press any key to exit.." );
Console.Read( );
}
}
Whether any clients have connected or not does not make a difference, 2nd app always gets stuck.
I found a potential solution (commented lines) by checking TcpListener.Pending( ) prior to .AcceptSocket( ) call, but this immediately affects CPU utilization, therefore an inclusion of smth like Thread.Sleep(.) is a must. Altogether though I'd rather avoid this approach if possible, because of extra connection wait times and CPU utilization (small as it is).
Still, the main question is: what may cause the same exact code to execute differently? Both apps are compiled on .NET 4 Client Profile, x86 (32-bit), no specific optimizations. Thank you in advance for good ideas!
Finally found the root cause: I missed a couple of important lines [hidden in a #region] in the Stop( ) method, which starts the ball rolling. Here's how it should look:
public static void Stop( )
{
bListen= false;
if( thOutComm != null )
{
try
{
oTcpListnr.Stop( );
}
catch( Exception x )
{
Utils.HandleEx( x );
}
thOutComm.Join( iTimeout );
thOutComm= null;
}
if( oTimer != null )
{
oTimer.Change( Timeout.Infinite, Timeout.Infinite );
oTimer.Dispose( );
}
}
The call to TcpListener.Stop( ) kicks out the wait-cycle inside .AcceptSocket( ) with "A blocking operation was interrupted by a call to WSACancelBlockingCall" exception, which is then "normally ignored" (check for SocketError.Interrupted) by the code that i originally had.