class {
    public State state;
    //enums cant take double values...
    public struct State
    {
        public const float IDLE = 0f;
        public const float WALKING = 0.5f;
        public const float RUNNING = 1f;
    }
    protected void Stop()
    {
        SetSpeed(State.IDLE);
    }
    protected void SetSpeed(float f)
    {
        agent.speed = f;
        if (agent.speed > 1f && agent.speed < 5f)
        {
            f = State.WALKING;
            agent.Resume();
        }
        else if (agent.speed > 5f)
        {
            f = State.RUNNING;
            agent.Resume();
        }
        else
        {
            f = State.IDLE;
            agent.Stop();
        }
    }
}

Who needs static float when you can have a constant in a nested struct, as a bonus State state has 0 references in the project

By SwagridOfficial, 2018-01-05 13:39:24
def possibilities():
    alphabets=(n,o,r,t,h,e,a,s,u,w,m,y)
    combinations=list()
    for n in range(9,-1,-1):
            for o in range(9,-1,-1):
                    for r in range(9,-1,-1):
                            for t in range(9,-1,-1):
                                    for h in range(9,-1,-1):
                                            for e in range(9,-1,-1):
                                                    for a in range(9,-1,-1):
                                                            for s in range(9,-1,-1):
                                                                    for u in range(9,-1,-1):
                                                                            for w in range(9,-1,-1):
                                                                                    for m in range(9,-1,-1):
                                                                                            for y in range(9,-1,-1):
                                                                                                    if len(set([n,o,r,t,h,e,a,s,u,w,m,y]))==12:
                                                                                                    north=10000*n + 1000*o +100*r +10*t +h
                                                                                                    east=1000*e +100*a +10*s +t
                                                                                                    south=10000*s + 1000*o +100*u +10*t +h
                                                                                                    west=1000*w + 100*e +10*s +t
                                                                                                    earth= 10000*e + 1000*a + 100*r +10*t +h
                                                                                                    if north +east +south +west == earth:
                                                                                                            combinations.append((north,east,south,west,earth))

    return combinations
By Dusk Code, 2018-04-25 11:47:49
import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while (1):

    _, frame = cap.read()

    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    lower_green = np.array([40, 50, 50])
    upper_green = np.array([80, 102, 200])

    # Threshold the HSV image to get only green colors
    mask = cv2.inRange(hsv, lower_green, upper_green)

    total_pixels = mask.shape[0] * mask.shape[1]
    print "Number of pixels: %", total_pixels

    pixel_counter = 0
    x_counter = 0
    y_counter = 0
    for y in xrange(640):
        for x in xrange(480):
            pixel = mask[x, y]
            if pixel == 255:
                pixel_counter += 1
                x_counter += x
                y_counter += y
    x_center = x_counter / pixel_counter
    y_center = y_counter / pixel_counter
    print x_center, y_center

    cv2.line(frame, (x_center+15, y_center), (x_center+2, y_center), (235, 218, 100), 1)
    cv2.line(frame, (x_center-15, y_center), (x_center-2, y_center), (235, 218, 100), 1)
    cv2.line(frame, (x_center, y_center+15), (x_center, y_center+2), (235, 218, 100), 1)
    cv2.line(frame, (x_center, y_center-15), (x_center, y_center-2), (235, 218, 100), 1)

    cv2.circle(frame, (x_center, y_center), 4, (235, 218, 100), 2)

    cv2.imshow('frame', frame)

    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break

cv2.destroyAllWindows()

track the green color

By Vik.victory, 2017-06-23 19:11:14
while (true) {
  if ($current === $requested) {
     break;
  }
  if (! in_array($requested, $available)) {
     break;
  }
  session()->put('locale', $requested);
  break;
}
By Ed, 2020-08-05 15:26:32
function isEmpty(value) {
    if (value === '') {
        return false;
    } else if (value === 0) {
        return false;
    } else if (value === null) {
        return false;
    } else if (value === undefined) {
        return false;
    } else {
        return true;
    }
    return true;
}

javascript empty value check

By mr.js, 2017-12-13 11:43:20
http://localhost:52108/Trade/Details/1953452?class=pull-left
By Anonymous, 2018-01-05 10:23:21
// check if user is valid or not
ValidUserValidationResult userValidationResult = validUserValidator.validateUser(validationRequest);
By Anonymous, 2020-12-09 17:45:18
   // Test read access of memory
   try
   {
      c = ( (char*) pvMemory )[0];
      c = ( (char*) pvMemory )[iNLen - 1];
   }

   catch( ... ) {
      return -1;
   }
By Anonymous, 2022-10-19 16:28:05
$arrival_time = $obj->{'s1_6-2-'.strval($i).'date'} . ' ' . $obj->{'s1_6-2-'.strval($i).'time'} . ':00';
By Anonymous, 2017-02-14 20:31:36
    @SuppressWarnings("unchecked")
    private void addEndpointsTags(JsonArray tagsArray) throws IOException {
        if (registeredHandlers == null || registeredHandlers.isEmpty()) {
            return;
        }
        TreeSet<String> handlerNamesSorted = new TreeSet<>(registeredHandlers.keySet());
        handlerNamesSorted.forEach(key -> {
            StringBuilder sb = new StringBuilder();
            sb.append("{\"name\":\"");
            sb.append(key);
            sb.append("\",\"request\":{\"name\":\"");
            try {
                ServiceMethodHandler handler = registeredHandlers.get(key);
                Class<? extends Message> requestClass = (Class<? extends Message>)
                        findSubClassParameterType(handler, 0);
                Class<? extends Message> responseClass = (Class<? extends Message>)
                        findSubClassParameterType(handler, 1);
                sb.append(requestClass.getSimpleName());
                sb.append("\",\"type\":\"");
                sb.append(requestClass.getSimpleName());
                sb.append("\",\"values\":[");
                sb.append(getProtobufClassFieldDescriptions(requestClass, new HashSet<>()));
                sb.append("]},\"response\":{\"name\":\"");
                sb.append(responseClass.getSimpleName());
                sb.append("\",\"type\":\"");
                sb.append(responseClass.getSimpleName());
                sb.append("\",\"values\":[");
                sb.append(getProtobufClassFieldDescriptions(responseClass, new HashSet<>()));
                sb.append("]},\"metadata\":{\"stream\":\"false\"}}");
            } catch (Exception e) {
                logger.error("Error inspecting handlers", e);
                return;
            }
            String tag = sb.toString();
            tagsArray.add(new JsonPrimitive("e-" + binaryEncode(tag)));
        });
    }
By Brian, 2019-08-13 15:13:37
@EventHandler
	public void onCpUse(PlayerMoveEvent e) {
		Player player = e.getPlayer();
		if(Main.main.state != Gamestate.JUMP) return;
		if(!Main.main.alive.contains(player)) return;
		Location loc = e.getPlayer().getLocation();
		  loc.setY(loc.getY() -1);
		  Block standingOnBlock = loc.getBlock();
		  int currentCP = Main.main.checkpointTracker.get(player);
			int nextCP = currentCP+1;
		  if(standingOnBlock.getType() == Material.EMERALD_BLOCK) {
			  Main.main.lm.setLocation(Main.main.map + "x" + nextCP + "x" + player.getName(), player.getLocation());
			  standingOnBlock.setType(Material.BEDROCK);
				giveCPEquip(player, nextCP);
					Main.main.checkpointTracker.put(player, nextCP);
					Main.main.scoreboard.setIngameScoreboard(player);
					player.sendMessage(Main.main.pr + "�aDu hast den " + nextCP + ". Checkpoint erreicht!");
					if(Main.main.particleTracker.containsKey(player)) {
						player.spawnParticle(Main.main.particleTracker.get(player), player.getLocation(), 10);
					}
			 		player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 10, 1);
		  }
	}
	public void giveCPEquip(Player p, int cp) {
		Inventory i = p.getInventory();
		ItemStack cp1Helmet = Main.main.utils.create(Material.LEATHER_HELMET, 1);
		ItemStack cp1Chest = Main.main.utils.create(Material.LEATHER_CHESTPLATE, 1);
		ItemStack cp1Leggings = Main.main.utils.create(Material.LEATHER_LEGGINGS, 1);
		ItemStack cp1Boots = Main.main.utils.create(Material.LEATHER_BOOTS, 1);
		
		ItemStack cp2Sword = Main.main.utils.createSharp1Item(Material.STONE_SWORD, 1);
		
		ItemStack cp3Apples = Main.main.utils.create(Material.GOLDEN_APPLE, 3);
		
		ItemStack cp4Chest = Main.main.utils.create(Material.CHAINMAIL_CHESTPLATE, 1);
		ItemStack cp4Leggings = Main.main.utils.create(Material.CHAINMAIL_LEGGINGS, 1);
		
		ItemStack cp5Helmet = Main.main.utils.create(Material.IRON_HELMET, 1);
		ItemStack cp5Boots = Main.main.utils.create(Material.IRON_BOOTS, 1);
		
		//6 Add extra Herzen
		
		ItemStack cp7Sword = Main.main.utils.create(Material.DIAMOND_SWORD, 1);
		
		ItemStack cp8Sword = Main.main.utils.create(Material.SHIELD, 1);
		
		
		ItemStack cp1Helmet1 = Main.main.utils.create(Material.DIAMOND_HELMET, 1);
		ItemStack cp1Chest1 = Main.main.utils.create(Material.DIAMOND_CHESTPLATE, 1);
		ItemStack cp1Leggings1 = Main.main.utils.create(Material.DIAMOND_LEGGINGS, 1);
		ItemStack cp1Boots1 = Main.main.utils.create(Material.DIAMOND_BOOTS, 1);
		
		ItemStack cp2Sword1 = Main.main.utils.createSharp1Item(Material.DIAMOND_SWORD, 1);
		
		ItemStack cp3Apples1 = Main.main.utils.create(Material.SHIELD, 1);
		
		ItemStack cp4Leggings1 = Main.main.utils.create(Material.NETHERITE_LEGGINGS, 1);
		
		ItemStack cp5Helmet1 = Main.main.utils.create(Material.NETHERITE_HELMET, 1);
		ItemStack cp5Boots1 = Main.main.utils.create(Material.NETHERITE_BOOTS, 1);
		
		//6 Add extra Herzen
		
		ItemStack cp7Sword1 = Main.main.utils.create(Material.NETHERITE_CHESTPLATE, 1);
		
		ItemStack cp8Sword1 = Main.main.utils.createSharp1Item(Material.NETHERITE_SWORD, 1);
		
		
		ItemStack cp1Helmet2 = Main.main.utils.create(Material.GOLDEN_HELMET, 1);
		ItemStack cp1Chest2 = Main.main.utils.create(Material.GOLDEN_CHESTPLATE, 1);
		ItemStack cp1Leggings2 = Main.main.utils.create(Material.GOLDEN_LEGGINGS, 1);
		ItemStack cp1Boots2 = Main.main.utils.create(Material.GOLDEN_BOOTS, 1);
		
		ItemStack cp2Sword2 = Main.main.utils.createSharp1Item(Material.STONE_SWORD, 1);
		
		ItemStack cp3Apples2 = Main.main.utils.create(Material.GOLDEN_APPLE, 3);
		ItemStack cp3Apple2 = Main.main.utils.create(Material.SHIELD, 1);
		
		ItemStack cp4Leggings2 = Main.main.utils.create(Material.IRON_LEGGINGS, 1);
		
		ItemStack cp5Helmet2 = Main.main.utils.create(Material.IRON_HELMET, 1);
		ItemStack cp5Boots2 = Main.main.utils.create(Material.IRON_BOOTS, 1);
		
		//6 Add extra Herzen
		
		ItemStack cp7Sword2 = Main.main.utils.create(Material.IRON_CHESTPLATE, 1);
		
		ItemStack cp8Sword2 = Main.main.utils.createSharp1Item(Material.IRON_SWORD, 1);
		
		
		
		if(!Main.main.random) {
		if(Main.main.rn ==0) {
		if(cp == 1) {
			i.addItem(cp1Helmet);
			i.addItem(cp1Chest);
			i.addItem(cp1Leggings);
			i.addItem(cp1Boots);
		}else if(cp == 2) {
			i.addItem(cp2Sword);
		}else if(cp == 3) {
			i.addItem(cp3Apples);
		}else if(cp == 4) {
			i.addItem(cp4Chest);
			i.addItem(cp4Leggings);
		}else if(cp == 5) {
			i.addItem(cp5Helmet);
			i.addItem(cp5Boots);
		}else if(cp == 6) {
			p.setMaxHealth(24);
			p.sendMessage(Main.main.pr + "�aDu hast zwei Extraherzen erhalten!");
		}else if(cp == 7) {
			i.addItem(cp7Sword);
		}else if(cp == 8) {
			i.addItem(cp8Sword);
			if(Main.main.fallTracker.get(p) == 0) {
				p.sendMessage(Main.main.pr + "Du hast das Ziel ohne JumpFail erreicht!");
				p.getInventory().addItem(Main.main.utils.create(Material.DIAMOND_HELMET, 1));
			}
			Bukkit.broadcastMessage(Main.main.pr + "�5" + p.getName() + " �a hat das Ziel erreicht!");
			Main.main.cd.cancelIngameTask();
			Main.main.cd.startDeathmatchCD();
		}
	}else if(Main.main.rn == 1) {
		if(cp == 1) {
			i.addItem(cp1Helmet1);
			i.addItem(cp1Chest1);
			i.addItem(cp1Leggings1);
			i.addItem(cp1Boots1);
		}else if(cp == 2) {
			i.addItem(cp2Sword1);
		}else if(cp == 3) {
			i.addItem(cp3Apples1);
		}else if(cp == 4) {
			i.addItem(cp4Leggings1);
		}else if(cp == 5) {
			i.addItem(cp5Helmet1);
			i.addItem(cp5Boots1);
		}else if(cp == 6) {
			p.setMaxHealth(24);
			p.sendMessage(Main.main.pr + "�aDu hast zwei Extraherzen erhalten!");
		}else if(cp == 7) {
			i.addItem(cp7Sword1);
		}else if(cp == 8) {
			i.addItem(cp8Sword1);
			if(Main.main.fallTracker.get(p) == 0) {
				p.sendMessage(Main.main.pr + "Du hast das Ziel ohne JumpFail erreicht!");
				p.getInventory().addItem(Main.main.utils.create(Material.GOLDEN_APPLE, 10));
			}
			Bukkit.broadcastMessage(Main.main.pr + "�5" + p.getName() + " �a hat das Ziel erreicht!");
			Main.main.cd.cancelIngameTask();
			Main.main.cd.startDeathmatchCD();
		}
	}else if(Main.main.rn == 2) {
		if(cp == 1) {
			i.addItem(cp1Helmet2);
			i.addItem(cp1Chest2);
			i.addItem(cp1Leggings2);
			i.addItem(cp1Boots2);
		}else if(cp == 2) {
			i.addItem(cp2Sword2);
		}else if(cp == 3) {
			i.addItem(cp3Apples2);
			i.addItem(cp3Apple2);
		}else if(cp == 4) {
			i.addItem(cp4Leggings2);
		}else if(cp == 5) {
			i.addItem(cp5Helmet2);
			i.addItem(cp5Boots2);
		}else if(cp == 6) {
			p.setMaxHealth(24);
			p.sendMessage(Main.main.pr + "�aDu hast zwei Extraherzen erhalten!");
		}else if(cp == 7) {
			i.addItem(cp7Sword2);
		}else if(cp == 8) {
			i.addItem(cp8Sword2);
			if(Main.main.fallTracker.get(p) == 0) {
				p.sendMessage(Main.main.pr + "Du hast das Ziel ohne JumpFail erreicht!");
				p.getInventory().addItem(Main.main.utils.create(Material.GOLDEN_APPLE, 10));
			}
			Bukkit.broadcastMessage(Main.main.pr + "�5" + p.getName() + " �a hat das Ziel erreicht!");
			Main.main.cd.cancelIngameTask();
			Main.main.cd.startDeathmatchCD();
		}	
	}
		}else {
		    Random random = new Random();
		    List<Material> materials = Arrays.asList(Material.values());
		    int size = materials.size()-1;
		    Material ran = materials.get(random.nextInt(size));
		    p.getInventory().addItem(new ItemStack(ran, 1));
		    if(cp == 8) {
		    	if(Main.main.fallTracker.get(p) == 0) {
					p.sendMessage(Main.main.pr + "Du hast das Ziel ohne JumpFail erreicht!");
					p.getInventory().addItem(Main.main.utils.create(Material.DIAMOND_HELMET, 1));
				}
				Bukkit.broadcastMessage(Main.main.pr + "�5" + p.getName() + " �a hat das Ziel erreicht!");
				Main.main.cd.cancelIngameTask();
				Main.main.cd.startDeathmatchCD();
		    }
		}
	}

This beautiful code snippet was found in one of the repositories of people who sell their products on Fiverr. As you may have noticed only the functionally of code is beautiful but also the formatting style.

By Anonymous, 2021-07-06 23:38:00
// Method put on each input component to unregister
  // itself from the form
  detachFromForm: function detachFromForm(component) {
    var componentPos = this.inputs.indexOf(component);

    if (componentPos !== -1) {
      this.inputs = this.inputs.slice(0, componentPos).concat(this.inputs.slice(componentPos + 1));
    }

    this.validateForm();
  },

oh boy

By Anonymous, 2017-12-21 10:48:00
function focused(evt, errors) {
	let form = evt.target

	const output = errors.map((error)=> {

		// Find first component with error on form and set focus to it

		let focusedInput = (Object.keys(error) == "phonebookId") ? Object.keys(error) :
			(Object.keys(error) == "phonebook_str") ? Object.keys(error) :
				(Object.keys(error) == "message") ? Object.keys(error) :
					(Object.keys(error) == "image") ? Object.keys(error) :
						(Object.keys(error) == "buttonLink") ? Object.keys(error) :
							(Object.keys(error) == "messageSms") ? Object.keys(error) : false
		return focusedInput.shift()
	})

	const selector = output.shift()
	form.querySelector('[id="' + selector + '"]').focus()

	return selector

Shitcode

By Anonymous, 2021-05-28 01:16:05
  <div ng-repeat="recipient in $ctrl.resource.invoiceRecipients track by $index">
    <div>
      {{$ctrl.resource.invoiceRecipients[$index]}}
    </div>
  </div>

You could easily use the "recipient" variable instead of getting it again from the array, is there a reason for doing this?

By Anonymous, 2020-10-29 16:26:16
		if (wiringPiMode == WPI_MODE_PINS)
			pin = pinToGpio[pin];
		else if (wiringPiMode == WPI_MODE_PHYS)
			pin = physToGpio[pin];
		else if (wiringPiMode != WPI_MODE_GPIO)
			return;

the 3rd condition check throws you right off the train of logic.

By Gordon Henderson, 2019-07-23 06:05:05