socket.on('newMessage', (messageObj) => {
	if (roomNumber === messageObj.roomNumber) {

		console.log("message received:" + messageObj.message);
		$('#messages').append($('<li>').text(messageObj.userName + ' : ' + messageObj.message));

	}
});

socket.in wasn't behaving as advertised (broadcasting to all rooms). I decided to take matters into my own hands.

By Andrew, 2017-12-13 02:57:58
    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

// 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
#include <stdio.h>
#include<stdlib.h>
#include<time.h>

void randy(int array[] ){
int i = 0  , d = 0;
		for(i = 1 ; i <= 23 ; i++){
			
			array[i] =  1 + (rand() % 365 ); 
		}
	}

int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}



int find (int arr[]){
 int d = 0;
 	
 	for(d = 1  ;d <=23 ; d++ ){
 		
		 if(arr[d] == 	 arr[d + 1]){
		 	return 1;
		 }
	 }
	
	return 0;
}

int main(void){
	 double count_birthday = 0;
	int  people[24];
  
	srand(time(NULL));
	
	int c = 0 ;
	long double ip = 0;
	
	
	
	while(ip++ <= 1000000 ){
		

		randy(people);
		qsort (people, 25, sizeof(int), compare);
		if(find (people) == 1 ){
			count_birthday++;
		}

	}

printf("%.2lf", 	count_birthday  / 10000  );
return 0;
}
By lazy_8, 2020-03-04 13:14:05
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 "[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
local Plr = game.Players.LocalPlayer

for i,v in pairs(game.ReplicatedStorage.DataStorage[Plr.Name].Data["Slot1"].AccessoriesList:GetChildren()) do
v.Value = "Unlocked"
end
for i,v in pairs(game.ReplicatedStorage.DataStorage[Plr.Name].Data["Slot1"].StanceList:GetChildren()) do
v.Value = "Unlocked"
end
for i,v in pairs(game.ReplicatedStorage.DataStorage[Plr.Name].Data["Slot1"].RunningList:GetChildren()) do
v.Value = "Unlocked"
end
for i,v in pairs(game.ReplicatedStorage.DataStorage[Plr.Name].Data["Slot1"].FlyingList:GetChildren()) do
v.Value = "Unlocked"
end
for i,v in pairs(game.ReplicatedStorage.DataStorage[Plr.Name].Data["Slot1"].FightingStyles:GetChildren()) do
v.Value = "Unlocked"
end
for i,v in pairs(game.ReplicatedStorage.DataStorage[Plr.Name].Data["Slot1"].MoveList:GetChildren()) do
v.Value = "Unlocked"
end
for i,v in pairs(game.ReplicatedStorage.DataStorage[Plr.Name].Data["Slot1"].ClothingList:GetChildren()) do
v.Value = "Unlocked"
end

Bad unlock script for Roblox

By JayRain, 2020-03-14 03:01:24
let verificaAdmin_Role = (req, res, next) => {

    let usuario = req.usuario;

    if (usuario.role === 'ADMIN_ROLE') {
        next();
    } else {
        return res.status(409).json({
            ok: false,
            err: {
                message: 'El usuario no es administrador.'
            }
        })
    }

};

By rootweiller, 2020-06-18 18:30:41
#53 C++ +6
int chromosome::getScore()
{
    return this->getScore();
}
By Anonymous, 2015-11-05 15:41:39
#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )";

export KUBECONFIG="${DIR}/my_secret_stuff/kube.conf";

Example on how to get location of the script right

By Piotr, 2020-05-11 12:45:57
case (RSel)
      4'b0000:begin
                R1e = 1'b0;   R2e = 1'b0;  R3e = 1'b0;  R4e = 1'b0;  
              end
      4'b0001:begin
                R1e = 1'b0;   R2e = 1'b0;  R3e = 1'b0;  R4e = 1'b1; 
              end
      4'b0010:begin
                R1e = 1'b0;   R2e = 1'b0;  R3e = 1'b1;  R4e = 1'b0; 
              end
      4'b0011:begin
                R1e = 1'b0;   R2e = 1'b0;  R3e = 1'b1;  R4e = 1'b1; 
              end
      4'b0100:begin
                R1e = 1'b0;   R2e = 1'b1;  R3e = 1'b0;  R4e = 1'b0;
              end
      4'b0101:begin
                R1e = 1'b0;   R2e = 1'b1;  R3e = 1'b0;  R4e = 1'b1;  
              end
      4'b0110:begin
                R1e = 1'b0;   R2e = 1'b1;  R3e = 1'b1;  R4e = 1'b0; 
              end
      4'b0111:begin
                R1e = 1'b0;   R2e = 1'b1;  R3e = 1'b1;  R4e = 1'b1;  
              end
      4'b1000:begin
                R1e = 1'b1;   R2e = 1'b0;  R3e = 1'b0;  R4e = 1'b0;  
              end
      4'b1001:begin
                R1e = 1'b1;   R2e = 1'b0;  R3e = 1'b0;  R4e = 1'b1;
              end
      4'b1010:begin
                R1e = 1'b1;   R2e = 1'b0;  R3e = 1'b1;  R4e = 1'b0; 
              end
      4'b1011:begin
                R1e = 1'b1;   R2e = 1'b0;  R3e = 1'b1;  R4e = 1'b1; 
              end
      4'b1100:begin
                R1e = 1'b1;   R2e = 1'b1;  R3e = 1'b0;  R4e = 1'b0; 
              end
      4'b1101:begin
                R1e = 1'b1;   R2e = 1'b1;  R3e = 1'b0;  R4e = 1'b1; 
              end
      4'b1110:begin
                R1e = 1'b1;   R2e = 1'b1;  R3e = 1'b1;  R4e = 1'b0; 
              end
      4'b1111:begin
                R1e = 1'b1;   R2e = 1'b1;  R3e = 1'b1;  R4e = 1'b1;
              end
     
    endcase
    
    case (TSel)
          4'b0000:begin
                    T1e = 1'b0;  T2e = 1'b0; T3e = 1'b0;  T4e = 1'b0;
                  end
          4'b0001:begin
                    T1e = 1'b0;  T2e = 1'b0; T3e = 1'b0;  T4e = 1'b1;
                  end
          4'b0010:begin
                    T1e = 1'b0;  T2e = 1'b0; T3e = 1'b1;  T4e = 1'b0;
                  end
          4'b0011:begin
                    T1e = 1'b0;  T2e = 1'b0; T3e = 1'b1;  T4e = 1'b1;
                  end
          4'b0100:begin
                    T1e = 1'b0;  T2e = 1'b1; T3e = 1'b0;  T4e = 1'b0;
                  end
          4'b0101:begin
                    T1e = 1'b0;  T2e = 1'b1; T3e = 1'b0;  T4e = 1'b1;
                  end
          4'b0110:begin
                    T1e = 1'b0;  T2e = 1'b1; T3e = 1'b1;  T4e = 1'b0;
                  end
          4'b0111:begin
                    T1e = 1'b0;  T2e = 1'b1; T3e = 1'b1;  T4e = 1'b1;
                  end
          4'b1000:begin
                    T1e = 1'b1;  T2e = 1'b0; T3e = 1'b0;  T4e = 1'b0;
                  end
          4'b1001:begin
                    T1e = 1'b1;  T2e = 1'b0; T3e = 1'b0;  T4e = 1'b1;
                  end
          4'b1010:begin
                    T1e = 1'b1;  T2e = 1'b0; T3e = 1'b1;  T4e = 1'b0;
                  end
          4'b1011:begin
                    T1e = 1'b1;  T2e = 1'b0; T3e = 1'b1;  T4e = 1'b1;
                  end
          4'b1100:begin
                    T1e = 1'b1;  T2e = 1'b1; T3e = 1'b0;  T4e = 1'b0;
                  end
          4'b1101:begin
                    T1e = 1'b1;  T2e = 1'b1; T3e = 1'b0;  T4e = 1'b1; 
                  end
          4'b1110:begin
                    T1e = 1'b1;  T2e = 1'b1; T3e = 1'b1;  T4e = 1'b0;
                  end
          4'b1111:begin
                    T1e = 1'b1;  T2e = 1'b1; T3e = 1'b1;  T4e = 1'b1;
                  end
        endcase

Just write assign {R1e, R2e, R3e, R4e} = Rsel assign {T1e, T2e, T3e, T4e} = Tsel

By dawidogg, 2023-04-01 16:40:34
public static returnTrue(boolean b){
    if (b){
        return true;
    } else {
        return true;
    }
}

When you want your function always returns the correct value

By kayvan goli, 2017-12-13 14:49:39
foreach($bookings as $booking) {
	$status = $apiController->getBookingStatus($booking);
	if($status->error == 1) {
		switch($status->message) {
			case "FIND_PRV_KO": continue; //Wrong parameters
			case "ERR_PREN_NOTFOUND": continue; //Request booking cannot be found
			case "ERR_PRV_NOTFOUND": continue; //Check-in not carried out
			default: continue;
		};
		continue;
	}
	//DO SOME STUFF...
}

Found this on a production website

By Samuel, 2021-03-29 17:52:33
$MaxSizeGB = [math]::Round($MaxSize/1024/1024/1024,2)
Write-Output "    the maximum size is $MaxSizeGB GB"

At least [math] is used. So close, and yet so far...

By Anonymous, 2020-04-03 20:59:34
const setFormFlag(state){
    state.formFlag ? state.formFlag = false : state.formFlag = true;
}
By Apeiron, 2018-07-27 20:43:23