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
scrollToEl($el.parent().parent().parent());

Someones idea of how to select an element to scroll to.... Please no.

By Anonymous, 2019-09-27 15:20:17
if(typeof(sortOrder) != "boolean"){        
    return items;
}
filtered.sort(function (a, b) {
    if(sortOrder == true){
        return (CustomOrder(a.status) > CustomOrder(b.status) ? 1 : -1);
    }
    else if(sortOrder == false){
        return (CustomOrder(a.status) < CustomOrder(b.status) ? 1 : -1);
    }
});

The status property is a string ("Started", "Running", "Failed", "Finished", etc.), and CustomOrder is a function with a switch that just returns a predefined integer for each string. I switched CustomOrder to just be a simple lookup table object, and the sort call was changed to filtered.sort((a, b) => CustomOrder[a.status] - CustomOrder[b.status]);

By Anonymous, 2017-12-13 00:06:25
        if "[trait]" in lines[i]:
            in_trait = True
        elif "[/trait]" in lines[i]:
            in_trait = False
        elif "[object]" in lines[i]:
            in_object = True
        elif "[/object]" in lines[i]:
            in_object = False
        elif "[stage]" in lines[i]:
            in_stage = True
        elif "[/stage]" in lines[i]:
            in_stage = False
        elif "[cfg]" in lines[i]:
            in_cfg = True
        elif "[/cfg]" in lines[i]:
            in_cfg = False
        elif "[goal]" in lines[i]:
            in_goal = True
        elif "[/goal]" in lines[i]:
            in_goal = False
#... 150 more lines of this

Basically, linting a config file with a DOM tree, using Python

By Anonymous, 2019-12-28 23:35:11

// enum - full enumeration of knapsack solutions
// (C) Joshua Knowles

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>

FILE *fp;  // file pointer for reading the input files
int Capacity;     // capacity of the knapsack (total weight that can be stored)
int Nitems;    // number of items available
int *item_weights;  // vector of item weights
int *item_values;  // vector of item profits or values
int *temp_indexes;  // list of temporary item indexes for sorting items by value/weight
int QUIET=0; // this can be set to 1 to suppress output

extern void read_knapsack_instance(char *filename);
extern void print_instance();
extern void sort_by_ratio();
extern int check_evaluate_and_print_sol(int *sol,  int *total_value, int *total_weight);
void enumerate();
int next_binary(int *str, int Nitems);

int main(int argc, char *argv[])
{
  read_knapsack_instance(argv[1]);
  print_instance();
  enumerate();
  return(0);
}

void enumerate()
{
  // Do an exhaustive search (aka enumeration) of all possible ways to pack
  // the knapsack.
  // This is achieved by creating every binary solution vector of length Nitems.
  // For each solution vector, its value and weight is calculated.


  int i;  // item index
  int solution[Nitems+1];   // (binary) solution vector representing items packed
  int best_solution[Nitems+1];  // (binary) solution vector for best solution found
  int best_value; // total value packed in the best solution
  double j=0;
  int total_value, total_weight; // total value and total weight of current knapsack solution
  int infeasible;  // 0 means feasible; -1 means infeasible (violates the capacity constraint)

  // set the knapsack initially empty
  for(i=1;i<=Nitems;i++)
    {
      solution[i]=0;
    }
  QUIET=1;
  best_value=0;

 while(!(next_binary(&solution[1], Nitems)))
    {

      /* ADD CODE IN HERE TO KEEP TRACK OF FRACTION OF ENUMERATION DONE */

          // calculates the value and weight and feasibility:
      infeasible=check_evaluate_and_print_sol(solution, &total_value, &total_weight);  
      /* ADD CODE IN HERE TO KEEP TRACK OF BEST SOLUTION FOUND*/

    }
 /* ADD CODE TO PRINT OUT BEST SOLUTION */

}


int next_binary(int *str, int Nitems)
{
  // Called with a binary string of length Nitems, this 
  // function adds "1" to the string, e.g. 0001 would turn to 0010.
  // If the string overflows, then the function returns 1, else it returns 0.
  int i=Nitems-1;
  while(i>=0)
    {
      if(str[i]==1)
	{
	  str[i]=0;
	  i--;
	}
      else
	{
	  str[i]=1;
	  break;
	}
    }
  if(i==-1)
    {
      return(1);
    }
  else
    {
      return(0);
    }
}

A genuine UoM lab.

By Joshua Knowles, 2018-02-23 10:58:03
try {
    synchronized(this) {
        Object obj = null;

        if (obj.hashCode() == -1) {
            obj = new Object();
        }
    }
} catch (Throwable t) {
    throw t;
} finally {
    try {
        synchronized(this) {
            Object obj = null;

            if (obj.hashCode() == -1) {
                obj = new Object();
            }
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        try {
            synchronized(this) {
                Object obj = null;

                if (obj.hashCode() == -1) {
                    obj = new Object();
                }
            }
        } catch (Throwable t) {
            throw t;
        } finally {
            System.exit(1);
        }
    }
}

Cool code

By Conclure, 2020-10-30 02:26:02
        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
# Create vpc peering connection
response = ec2.delete_vpc_peering_connection(peer_connection_id)

a part of AWS Landing Zone solution

By Amazon Solutions, 2019-07-10 12:49:42
def _take_items_from_list_and_put_them_into_string(self, list):
    string = ''
    for element in list:
        string += element + ','
    if len(string) > 0 and string[-1] == ',':
        string = string[0:-1]
    return string
By JK, 2017-12-13 13:54:43
          //////////////////////////////////////////
          // Add ROI coordinates into Environment
          //////////////////////////////////////////
          AddROIcoordinatesIntoEnvironment();

It really helped me understand the code.

By Anonymous, 2022-05-30 00:49:45
  ierr = pxmlIn->GetData(pcTag, *pTData);
  *pbDataValid = bool((ierr==0)&&(iLen>0));  // enabled if: not empty string and vaild (number?)
  if (*pbDataValid)  iErr += ierr;
By Anonymous, 2020-04-07 14:44:12

"  ".split(" ");

Very weird code found multiple times in old code base.

By heldt, 2017-12-12 12:03:14

class Timer extends React.Component{
    state ={
        time: 10
    };
    setInvt = () =>{
        let t = this.state.time
        if(t<=1){
            clearInterval(this.invertal)
        }
        this.setState({time: t-1})
    }
    componentDidMount(){
        this.invertal = setInterval(this.setInvt, 1000)
    }

    render(){
        return (<label>{this.state.time}</label>)
    }
}

export {Timer}
By Anonymous, 2021-07-30 21:13:46
    foreach ($desired_components as $name => $junk) {
      list($component_value, $component_comments) = self::unpackPair($desired_components[$name]);
      $desired_components[$name] = self::packPair(round($component_value, 2), $component_comments);
    }
By Anonymous, 2018-01-10 09:01:18
 Map<Object, List<Element>> groupeUniqueMap =values.stream().collect(Collectors.groupingBy(this::getCompositeGroupKey, Collectors.toList()));
      if(groupeUniqueMap.containsKey(Arrays.asList(null,null,null,null,null,null,null)))
        return values;
      return doReturn();
By ThisIsFine, 2020-07-02 18:41:35