$orderDateTS = strtotime($data['ordertime']);
$nowTS = strtotime('now');
$diff = $nowTS - $orderDateTS;
$diff = $diff / 86400;
$dayDiff = floor($diff);

found in a shopware plugin

By Anon, 2020-04-03 14:16:07
/**
 * Stringify a JSON object
 * @param {*} value JSON value to stringify
 * @returns {string} stringify JSON
 */
function stringify(value) {
    var result = {};
    try {
        result = JSON.stringify(value);
    } catch (e) {
        Logger.error('Error while trying to stringify ' + e);
        result = JSON.stringify(result);
    }
    return result;
}

Stringify a JSON object

By Ihor Did, 2023-04-12 19:36:08
<Image source={ this.props.pickupOrDropoff == "pickup"
                                    ? i.pickup
                                    ? iconBlue
                                    : iconWhite
                                    : i.dropoff 
                                    ? iconBlue
                                    : iconWhite} style={{
                                      height:this.props.pickupOrDropoff == "pickup"
                                    ? i.pickup
                                    ? 30
                                    : i.sign === 'D' ? 30 : 35
                                    : i.dropoff 
                                    ? 30
                                    : i.sign === 'D' ? 30 : 35,
                                    marginRight:10 ,
                                    width: this.props.pickupOrDropoff == "pickup"
                                    ? i.pickup
                                    ? 40
                                    : 40
                                    : i.dropoff 
                                    ? 40
                                    : 40
                                    ,resizeMode:'contain'}}/>

I love when the code is neat...

By Fluttershy, 2019-03-05 11:40:08
    if [ $product == "consul" ]
    then
       aws s3 cp s3://${path}/${product}/prem/${version}/${product}-enterprise_${version}+prem_linux_amd64.zip .
       unzip ${product}-enterprise_${version}+prem_linux_amd64.zip
       rm   ${product}-enterprise_${version}+prem_linux_amd64.zip
    else
       aws s3 cp s3://${path}/${product}/prem/${version}/${product}-enterprise_${version}+prem_linux_amd64.zip .
       unzip ${product}-enterprise_${version}+prem_linux_amd64.zip
       rm   ${product}-enterprise_${version}+prem_linux_amd64.zip
    fi 
By Anonymous, 2019-10-22 15:10:43
// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');

Never, ever define developer environment and debug as default thing! #pdk

By kadet, 2021-03-08 23:28:18
#997 Java +12
final int two_fifty_five_hex = 0xFF
final int two_fifty_five_dec = 255

One is in hex but the other is in decimal! Watch out, make sure you use the correct 255, not the other 255.

By Anonymous, 2020-04-28 14:52:27
public class NullableFloatToNullableDoubleConverter : ITypeConverter<float?, double?>
    {
        public double? Convert(float? source, double? destination, ResolutionContext context)
        {
            if (source == null)
            {
                return null;
            }

            var floatAsString = source.Value.ToString(CultureInfo.InvariantCulture);

            return double.Parse(floatAsString);
        }
    }
By Anonymous, 2019-01-31 12:05:33
if(!isset($obj->{'s5_4-1'})) {
	$obj->{'s5_4-1'} = 0;
}
if(!isset($obj->{'s5_4-2'})) {
	$obj->{'s5_4-2'} = 0;
}
if(!isset($obj->{'s5_4-3'})) {
	$obj->{'s5_4-3'} = 0;
}
if(!isset($obj->{'s5_4-4'})) {
	$obj->{'s5_4-4'} = 0;
}
By Anonymous, 2017-02-14 20:33:40
try:
    raise
except RuntimeError:
    raise

try this in python3

By FranchuFranchu, 2019-03-14 23:10:03
 elsif ( $att =~ m/!!ARRAY!!/ ) {    # Updated to allow us to get data from an Array - 
        &Debug("get_value_from_hash:: parsing the ARRAY attribute - $att");
        my ( $key1, $key2, $key3, $key4, $key5, $key6 ) = split( /\./, $att );

        #&Debug("get_value_from_hash:: key1=$key1, key2=$key2, key3=$key3, key4=$key4, key5=$key5");
        if ( defined $key6 ) {
            if ( $key5 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{ $hash->{$key1}->{$key2}->{$key3}->{$key4} } ) { $value = $item->{$key6}; }
            }
            elsif ( $key4 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{ $hash->{$key1}->{$key2}->{$key3} } ) { $value = $item->{$key5}->{$key6}; }
            }
            elsif ( $key3 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{ $hash->{$key1}->{$key2} } ) { $value = $item->{$key4}->{$key5}->{$key6}; }
            }
            elsif ( $key2 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{ $hash->{$key1} } ) { $value = $item->{$key3}->{$key4}->{$key5}->{$key6}; }
            }
            elsif ( $key1 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{$hash} ) { $value = $item->{$key2}->{$key3}->{$key4}->{$key5}->{$key6}; }
            }
        }
        elsif ( defined $key5 ) {
            if ( $key4 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{ $hash->{$key1}->{$key2}->{$key3} } ) { $value = $item->{$key5}; }
            }
            elsif ( $key3 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{ $hash->{$key1}->{$key2} } ) { $value = $item->{$key4}->{$key5}; }
            }
            elsif ( $key2 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{ $hash->{$key1} } ) { $value = $item->{$key3}->{$key4}->{$key5}; }
            }
            elsif ( $key1 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{$hash} ) { $value = $item->{$key1}->{$key3}->{$key4}->{$key5}; }
            }
        }
        elsif ( defined $key4 ) {
            if ( $key3 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{ $hash->{$key1}->{$key2} } ) { $value = $item->{$key4}; }
            }
            elsif ( $key2 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{ $hash->{$key1} } ) { $value = $item->{$key3}->{$key4}; }
            }
            elsif ( $key1 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{$hash} ) { $value = $item->{$key1}->{$key3}->{$key4}; }
            }
        }
        elsif ( defined $key3 ) {
            if ( $key2 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{ $hash->{$key1} } ) { $value = $item->{$key3}; }
            }
            elsif ( $key1 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{$hash} ) { $value = $item->{$key3}; }
            }
        }
        elsif ( defined $key2 ) {
            if ( $key1 =~ m/!!ARRAY!!/ ) {
                for my $item ( @{$hash} ) { $value = $item->{$key2}; }
            }
        }
    }
    elsif ( $att =~ m/!!HITS\[\d+\]!!/ ) {
        &Debug("get_value_from_hash:: parsing the HITS attribute - $att");
        my $id = $att;
        $id =~ s/!!HITS\[(\d+)\]!!.*/$1/;
        $att =~ s/!!HITS\[\d+\]!!\.//;
        &Debug("get_value_from_hash:: parsing the attribute - $att");
        my ( $key1, $key2, $key3, $key4, $key5, $key6 ) = split( /\./, $att );

        #&Debug("get_value_from_hash:: id=$id, key1=$key1, key2=$key2, key3=$key3, key4=$key4, key5=$key5");
        if ( defined $key6 ) {
            $value = $$hash{hits}{hits}[$id]{$key1}{$key2}{$key3}{$key4}{$key5}{$key6};
        }
        elsif ( defined $key5 ) {
            $value = $$hash{hits}{hits}[$id]{$key1}{$key2}{$key3}{$key4}{$key5};
        }
        elsif ( defined $key4 ) {
            $value = $$hash{hits}{hits}[$id]{$key1}{$key2}{$key3}{$key4};
        }
        elsif ( defined $key3 ) {
            $value = $$hash{hits}{hits}[$id]{$key1}{$key2}{$key3};
        }
        elsif ( defined $key2 ) {
            $value = $$hash{hits}{hits}[$id]{$key1}{$key2};
        }
    }
    elsif ( $att =~ m/!!DELIMITER!!.+!!/ ) {
        &Debug("get_value_from_hash:: parsing the DELIMITER attribute - $att");
        my $delimiter = $att;
        $delimiter =~ s/!!DELIMITER!!(.*)!!.*/$1/;
        $att =~ s/!!DELIMITER!!.+!!//;
        &Debug("get_value_from_hash:: parsing the attribute - $att");
        my ( $key1, $key2, $key3, $key4, $key5, $key6 ) = split( $delimiter, $att );

        #        &Debug("get_value_from_hash:: key1=$key1, key2=$key2, key3=$key3, key4=$key4, key5=$key5, key6=$key6");
        if ( defined $key6 ) {
            $value = $$hash{$key1}{$key2}{$key3}{$key4}{$key5}{$key6};
        }
        elsif ( defined $key5 ) {
            $value = $$hash{$key1}{$key2}{$key3}{$key4}{$key5};
        }
        elsif ( defined $key4 ) {
            $value = $$hash{$key1}{$key2}{$key3}{$key4};
        }
        elsif ( defined $key3 ) {
            $value = $$hash{$key1}{$key2}{$key3};
        }
        elsif ( defined $key2 ) {
            $value = $$hash{$key1}{$key2};
        }
    }
    else {
        &Debug("get_value_from_hash:: parsing the attribute - $att");
        my ( $key1, $key2, $key3, $key4, $key5, $key6 ) = split( /\./, $att );

        #&Debug("get_value_from_hash:: key1=$key1, key2=$key2, key3=$key3, key4=$key4, key5=$key5");
        if ( defined $key6 ) {
            $value = $$hash{$key1}{$key2}{$key3}{$key4}{$key5}{$key6};
        }
        elsif ( defined $key5 ) {
            $value = $$hash{$key1}{$key2}{$key3}{$key4}{$key5};
        }
        elsif ( defined $key4 ) {
            $value = $$hash{$key1}{$key2}{$key3}{$key4};
        }
        elsif ( defined $key3 ) {
            $value = $$hash{$key1}{$key2}{$key3};
        }
        elsif ( defined $key2 ) {
            $value = $$hash{$key1}{$key2};
        }
    }

When you try to debug, why value is not filled, and find this...

By Anonymous, 2022-01-04 07:00:11
 filterForProvincia() {
    console.log('ciao');
 }

The last line of code of a parting Developer

By Anonymous, 2019-07-23 11:31:51
String s = "string";

String.valueOf(s).toString();

// just to make sure it's a damn string
while(!s instanceof String) {
    String.valueOf(s).toString();
}
By Anonymous, 2021-01-23 17:11:10
from django.http import JsonResponse, HttpResponse
import requests

def download_custom_award(request):
    try:
        custom_img = requests.get(request.GET.get('award'))
        response = HttpResponse(custom_img.content, content_type='application/PNG')
        filename = "Your_Award.png"
        response['Content-Disposition'] = 'attachment; filename=%s' % (filename)
        return response
    except Exception as e:
        return JsonResponse({'Status': 404, "message": e.message})

This developer was trying to force the browser to download a custom image rather than show it inline, so he coded an open reverse proxy and attempted to release it to a production web app. Also, all exceptions are trapped and shown to the user in plaintext in their browser.

By Anonymous, 2020-05-26 10:38:31
var state = getCookie("state");
function checkCookie(args) {
  if (state == args) {
    return true;
  } else {
    alert("Request denied. Invalid auth code provided.");
    return false;
  }
}
const tokenElement = document.getElementsByName("dream");
var loginSrv = checkCookie(getAllUrlParams().state);
document.cookie = `state=${getAllUrlParams().state}; path=/`;
tokenElement.innerText = getAllUrlParams().code;
if (getAllUrlParams().state != loginSrv) {
  alert(`Incorrect auth code provided. The correct code is ${state}`);
}

If they provide the wrong oauth state code, tell the user the correct one!

By Demonitized, 2020-08-31 22:12:37
Native XML structure:

<?xml version="1.0" encoding="utf-8" ?>
<tree>
    <node name="root">
        <node name="TELEVISIONS">
            <node name="TUBE"/>
            <node name="LCD"/>
            <node name="PLASMA"/>
        </node>
        <node name="PORTABLE ELECTRONICS">
            <node name="MP3 PLAYERS">
                <node name="FLASH"/>
            </node>
            <node name="CD PLAYERS"/>
            <node name="2 WAY RADIOS"/>
        </node>
    </node>
</tree>

Flattened XML structure (example 1):

<tree>
  <node key="0">root</node>
  <node key="1" parent="0">TELEVISIONS</node>
  <node key="2" parent="1">TUBE</node>
  <node key="3" parent="1">LCD</node>
  <node key="4" parent="1">PLASMA</node>
  <node key="5" parent="0">PORTABLE ELECTRONICS</node>
  <node key="6" parent="5">MP3 PLAYERS</node>
  <node key="7" parent="6">FLASH</node>
  <node key="8" parent="5">CD PLAYERS</node>
  <node key="9" parent="5">2 WAY RADIOS</node>
</tree>

Flattened XML structure (example 2):

<tree>
    <node>
        <name>root</name>
        <depth>0</depth>
    </node>
    <node>
        <name>TELEVISIONS</name>
        <depth>1</depth>
    </node>
    <node>
        <name>TUBE</name>
        <depth>2</depth>
    </node>
    <node>
        <name>LCD</name>
        <depth>2</depth>
    </node>
    <node>
        <name>PLASMA</name>
        <depth>2</depth>
    </node>
    <node>
        <name>PORTABLE ELECTRONICS</name>
        <depth>1</depth>
    </node>
    <node>
        <name>MP3 PLAYERS</name>
        <depth>2</depth>
    </node>
    <node>
        <name>FLASH</name>
        <depth>3</depth>
    </node>
    <node>
        <name>CD PLAYERS</name>
        <depth>2</depth>
    </node>
    <node>
        <name>2 WAY RADIOS</name>
        <depth>2</depth>
    </node>
</tree>
By Anonymous, 2015-11-19 12:32:25