#997 Java +16
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
// We have this enum.
enum Formula {
  case proposition(String)
  indirect case negation(Formula)
  indirect case operation(op: String, lhs: Formula, rhs: Formula)

  var nnf: Formula { /* ... */  }
}

// And now ...

switch formula.nnf {
 case .proposition(_):
   return formula.nnf
 case .negation(_):
   return formula.nnf
 case .operation(_, _, _):
   return formula.nnf
}
By Anonymous, 2018-01-08 11:04:54
        /// <summary>
        /// Builds the suffixs for the request sequence number
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public static string GetSequenceNumber(int i)
        {
            string strCount = string.Empty;
            string increase = string.Empty;
            int count;
            strCount = i.ToString();
            count = strCount.Length;
            //Add 0 infront of the index to make a 4 digit number
            if (count < 5)
            {
                for (int j = 0; j < (4 - count); j++)
                {
                    increase = increase + "0";
                }
                strCount = increase + strCount;
            }
            return strCount;
        }
By Anonymous, 2021-04-21 16:01:46
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 (!response ||
    !response.data ||
    !response.data.success ||
    response.data.success == false ) {
        //process stuff
}

Not talking about the '===' warning, here

By Anonymous, 2020-12-02 12:31:00
  $guard = ($vars->a_payment) + (0) * $price;
  if ($bless >= $guard) {
    $amount = $bless;
  }

Why not to write just 1 line?! $amount = max($bless, $vars->a_payment);

By Anonymous, 2018-02-05 17:27:25
	public static int findSplitVariable(LinkedList<ByteDataRow> matrix) {
		LinkedList<ByteDataRow> list = new LinkedList<ByteDataRow>();
		int maxNoOfZeros = 0;
		int maxNoOfOnes = 0;
		int varId = -1;
		int[] NoOfOnesInColumn = new int[matrix.get(0).getInVars().length];


		for (ByteDataRow bdr : matrix) {
			int tmpNoOfZeros = bdr.getNumberOfZeros();
			if (maxNoOfZeros < tmpNoOfZeros) {
				list.clear();
				list.add(bdr.clone());
				maxNoOfZeros = tmpNoOfZeros;
			} else if (maxNoOfZeros == tmpNoOfZeros) {
				list.add(bdr.clone());
			}
		}

		for (ByteDataRow bdr : list) {
			byte[] vars = bdr.getInVars();
			for (int i = 0; i < vars.length; i++) {
				NoOfOnesInColumn[i] = NoOfOnesInColumn[i]
						+ Byte.compare(vars[i], Byte.parseByte("0"));
				if (NoOfOnesInColumn[i] > maxNoOfOnes) {
					maxNoOfOnes = NoOfOnesInColumn[i];
					varId = i;
				}
			}
		}

		return varId;
	}

	public static int findSplitVariable(LinkedList<ByteDataRow> matrix, int varIdx) {
		LinkedList<ByteDataRow> list = new LinkedList<ByteDataRow>();
		int maxNoOfZeros = 0;
		int maxNoOfOnes = 0;
		int varId = -1;
		int[] NoOfOnesInColumn = new int[matrix.get(0).getInVars().length];

		// Wybierz kostkÍ z najwiÍkszπ liczbπ zer.
		for (ByteDataRow bdr : matrix) {
			int tmpNoOfZeros = bdr.getNumberOfZeros();
			if (maxNoOfZeros < tmpNoOfZeros) {
				list.clear();
				list.add(bdr.clone());
				maxNoOfZeros = tmpNoOfZeros;
			} else if (maxNoOfZeros == tmpNoOfZeros) {
				list.add(bdr.clone());
			}
		}

		for (ByteDataRow bdr : list) {
			byte[] vars = bdr.getInVars();
			for (int i = 0; i < vars.length; i++) {
				NoOfOnesInColumn[i] = NoOfOnesInColumn[i]
						+ Byte.compare(vars[i], Byte.parseByte("0"));
				if (NoOfOnesInColumn[i] > maxNoOfOnes) {
					maxNoOfOnes = NoOfOnesInColumn[i];
					varId = i;
				}
			}
		}

		return varId;
	}

There are two methods findSplitVariable. Second one takes extra parameter (varIdx) that is not used anywhere.

By Paul, 2018-02-17 14:47:37
if (code === null) {
    return null;
} else {
    return code;
}
By crossthedev, 2018-11-19 15:33:47
cd /some/directory
rm -rf *

I regularly see these two lines in Bash scripts I don't understand but some programmers think you need a CD command before any command, and they also don't know that paths can be part of parameters (which explains why they use many CD commands)

By Meeeeee, 2023-01-25 16:50:10
#include<stdio.h>
#include<stdlib.h>	
#include<string.h>	
	int main(void){
	void run_func(char *map[], char *fnt  , char *km , float *x ,  float *y , int line , int row , int lift    );
				char *long_met[3][8] = {{"mile","0.621371"  ,  "yard","1093.61" , "fut","3280.84" , "duim","39370.1" } ,
							{ "mile" ,"1.60934" , "yard","0.0009144" ,  "fut","0.0003048" ,  "duim","0.0000254"},
 			   				{"kilometer","1"  , "meter","1000"  ,   "stmeter","100000" ,   "mmeter","1000000" } }; 
				char *amount[3][4] = { { "gallon" , "0.264172" ,       "quarta" , "1.05669"     } , 
						{"gallon" , " 3.78541"  ,     "quarta" , "0.946353"   },
						{"litr" , "1"  , "mililitr" , "1000"   }};
				char *mass[3][8] = {   {"eng.tonna","0.984207"  ,  "amer.tonna","1.10231" , "stone","157.473" , "funt","2204.62" } ,
   						{ "eng.tonna" , "1.01605" , "amer.tonna", "0.907185" ,  "stone","0.00635029" ,  "funt","0.000453592"},
						{"tonna","1" ,         "kilogram" , "1000"  , "miligram","100000"   , "microgram","1000000"  }}; 
				char **cp;
				char *buf_data;
				char *fnt_sys;
				char *mtr_sys;
				char *word[100];
	while(1){
	int bg  = 0,convert_ch = 3,y = 0, d = 0, numb = 0;
  	float mn =0  , xm = 0 ;
	printf("%s", "enter data for converter: ");
		fgets( (char *) word, 99 ,stdin);
		buf_data = strtok((char *) word, " ");
		if( ! strcmp(buf_data, "funt.sys"   )     ){
		convert_ch = 0;	
		}
		else	if( ! strcmp(buf_data, "metric.sys"    )     ){
			convert_ch = 1;	
		}
		for( bg = 0 ;  buf_data != NULL;  buf_data = strtok(NULL, " ")  , bg++ ) {
			switch(bg){
				case 1:
					if( !strcmp("long_met" , buf_data  )  ){
			  			 y	=   sizeof(*long_met) / sizeof(long_met[0][0]); 
	          	      	                 d	=   sizeof(long_met) /   sizeof(long_met[0][0]); 
			  		        cp  = &long_met[convert_ch][0]  ;
					}
			   		else if(!strcmp("amount" , buf_data  ) ){
			  			 y	= sizeof(*amount) /  sizeof(amount [0][0]); 
		            	                 d	= sizeof(amount) /  sizeof(amount[0][0]); 
				    	        cp = &amount[convert_ch][0] ;
					}
				 	else if(!strcmp("mass" , buf_data  ) ){
				  		 y	= sizeof(*mass ) /  sizeof(mass[0][0]); 
		         		         d	= sizeof(mass ) /  sizeof(mass[0][0]); 
				 		 cp = &mass[convert_ch][0] ; 
					}
					break;
				case 2:
				fnt_sys = buf_data;
					break;
				case 3:
				mtr_sys = buf_data;
					break;
				case 4:
				numb =   atoi(buf_data);
					break;
			}
		}
		if( !y || !d || !cp || convert_ch == 3 || !numb ){
	
			puts("error");
		}
		else{
			run_func( cp,   fnt_sys ,  mtr_sys , &mn ,  &xm , y  , d , convert_ch );
			if( !mn || !xm  ){
		puts("error");
				} else{
			printf("%f\n" , !convert_ch  ?    (mn  /  xm ) * numb :  (  mn  *  xm   ) * numb         );	
			}
		}
	}
	return 0;
	}
	void run_func(char *map[], char *fnt  , char *km , float *x ,  float *y , int line , int row  , int lift    ){
		int m ;
	if(  ( lift )   ){
			row    -= line;	
		}
	for(  m = 0 ; m <= line   ; m++){
		if(!strcmp(fnt,map[m])){
			*x = atof(map[m  + 1] )  ;
			break;
			}
		}
	for( m =   (row  - line) ; m <=  row - 1  ; m++){
		if( !strcmp( km   ,  map[m] ) ){
			*y = atof(map[m  + 1 ] );
			break;
				}
			}
		}
By Gne4do, 2019-02-26 14:38:14
<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
 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
let already_in = True;
while (already_in) {
    let random_index = Math.floor(arr.length * Math.random());
    let already_in = False;
    for (ex of exs) {
        if (ex.id === arr[random_index].id) {
            already_in = True;
        }
    }
}

Yes, this is JavaScript, and yes it didn't work. Found while reviewing some code

By L., 2021-05-17 11:20:12
def get_verified_infos(request):
    try:
        # request logic here
        return data
    except Exception:
        logger.error(
            'Request to XXX was unsuccessful, '
            'Will retry till max recursion! Retrying...'
        )
        return get_verified_infos(request)

Used for OpenID authentication

By Anonymous, 2020-11-04 18:28:11
        protected override void OnStartup(StartupEventArgs e)
        {
            Current.DispatcherUnhandledException += ApplicationUnhandledException;

            base.OnStartup(e);

#if (DEBUG)
            RunInDebugMode(e.Args);
#else
            RunInReleaseMode(e.Args);
#endif
        }

#endregion

        private static void RunInReleaseMode(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;

            try
            {
                SplashScreen screen = new SplashScreen(@"Images\splashscreen.png");
                screen.Show(true, true);

                RunInDebugMode(args);
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }

        private static void RunInDebugMode(string[] args)
        {
            var bootstrapper = new Bootstrapper();
            bootstrapper.Run();
        }
By Anonymous, 2019-07-09 09:44:00