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.
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);
}
// 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.
#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;
}
scrollToEl($el.parent().parent().parent());
Someones idea of how to select an element to scroll to.... Please no.
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
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
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.'
}
})
}
};
He's our company CTO, with 25+ years of experience. Author https://github.com/juang77"
#!/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
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
public static returnTrue(boolean b){
if (b){
return true;
} else {
return true;
}
}
When you want your function always returns the correct value
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
$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...
const setFormFlag(state){
state.formFlag ? state.formFlag = false : state.formFlag = true;
}