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...
scrollToEl($el.parent().parent().parent());
Someones idea of how to select an element to scroll to.... Please no.
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]);
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
// 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.
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
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();
}
# Create vpc peering connection
response = ec2.delete_vpc_peering_connection(peer_connection_id)
a part of AWS Landing Zone solution
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
//////////////////////////////////////////
// Add ROI coordinates into Environment
//////////////////////////////////////////
AddROIcoordinatesIntoEnvironment();
It really helped me understand the code.
ierr = pxmlIn->GetData(pcTag, *pTData);
*pbDataValid = bool((ierr==0)&&(iLen>0)); // enabled if: not empty string and vaild (number?)
if (*pbDataValid) iErr += ierr;
" ".split(" ");
Very weird code found multiple times in old code base.
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}
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);
}
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();