Entity veh = World->NewVehicle(type);
...
World->AddAnimal(veh); // insert vehicle to both landscape and world

Code for creating CAMERA object in one big AAA game engine.

By Anonymous, 2018-08-19 01:33:34
class vggNet(nn.Module):
    def __init__(self, pretrained=True):
        super(vggNet, self).__init__()
        self.net = models.vgg16(pretrained=True).features.eval()

    def forward(self, x):


        out = []
        for i in range(len(self.net)):
            #x = self.net[i](x)
            x = self.net[i](x)
            #if i in [3, 8, 15, 22, 29]:
            #if i in [15]: #提取1,1/2,1/4的特征图
            if i in [8,15,22]: #提取1,1/2,1/4,1/8,1/16
                # print(self.net[i])
                out.append(x)
        return out

Some creepy feature extraction code I found attached to a research paper.

Features:

  • the "pretrained" parameter it's not actually used.
  • Just works (not so sure about that) with a vgg16, what if I want to use any other model?
  • They provided a spare copy of line 12, in case you lose one.
  • You can select a custom combination of layers by uncommenting the right if statement. A chinese explanation follows. Sometimes.
  • Why use pytorch hooks when you can write a 20+ lines class each time you need it?
By Baichuan Huang, 2021-05-21 19:21:58
<?php

$payload = '{ "products": [';
foreach ($products as $product) {
    $payload .= $product->toJson() . ',';
}
$payload = substr($payload, 0, \strlen($payload) - 1);
$payload .= ']}';
By sijolas, 2019-03-15 14:47:06
public static int[] sleepSort(int... args) {
        final int[] sorted = new int[args.length];
        final AtomicInteger index = new AtomicInteger(0);
        List<Thread> threads = new ArrayList<Thread>(0);
        for (int i = 0; i < args.length; i++) {
            final int x = i;
            Thread sorter = new Thread(() -> {
                try {
                    Thread.sleep(args[x]);
                } catch (InterruptedException ex) { 
                    // shrug
                }
                sorted[index.getAndIncrement()] = args[x];
            });
            sorter.setDaemon(true);
            sorter.start();
            threads.add(sorter);
        }
        try {
            for (Thread t : threads) { t.join(); }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return sorted;
    }

Takes an unsorted array of integers, sorts by sleeping for the int value of each item in the array and then writing that into the resulting sorted array. Big-O analysis is... difficult.

By Sum YungGui, 2017-12-12 17:10:56
public function get($paymentType, $carrier, $gds, $clearingCompany, $allowDirectPayment)
	{
		AcqData::preload();

		$carrier = strtoupper($carrier);
		if($paymentType == 'cc') {
			$gdsVal = $this->acqData->getGdsVal($gds);

			if(!$allowDirectPayment || 
			   !$gdsVal || 
			   !isset($gdsVal['lr'], $gdsVal['direct'], $gdsVal['lr_commission_acq'], $gdsVal['direct_commission_acq'])
			  ) {
				$ccDefaultVal = $this->acqData->getPaymentTypeVal($paymentType);
				return [[$ccDefaultVal, $ccDefaultVal], false];
			}

			$commission = $gdsVal['direct_commission_acq'];
			$isDirect = $this->isDirect($carrier, $gds, $clearingCompany);
			if(!$isDirect) {
				$gdsVal['direct'] = $gdsVal['lr'];
				$commission = $gdsVal['lr'];
			}

			return [
				[$gdsVal['direct'], $commission],
				$isDirect
			];
		}

		$paymentTypeVal = $this->acqData->getPaymentTypeVal($paymentType);

		return [
			[$paymentTypeVal, $paymentTypeVal], 
			false
		];
	}

$ccDefaultVal = $this->acqData->getPaymentTypeVal($paymentType); is duplicated in two branches...

By Anonymous, 2017-12-20 12:03:01
> var x = 3;
> '5' + x - x
50
> '5' - x + x
5 // Because fuck math

JS is simply. Oh, wait...

By mademan, 2015-11-18 13:50:39
typedef signed int sint;
#define N 100
static int n = N;

inline int f(const int n, int& i, int* j, int t[2], int p=11)
{
    i*=i;
    (*j)--;
    
    if ( n<=0 )
    {
        cout << ::n << ">\n";
        return t[0];
    }
    else return f(n-1, i, j, t) + t[n];
}

int main()
{
    int n = 4;
    int x = 1U;
    sint y = 10;
    int (*fptr)(const int, int&, int*, int*, int) = f;

    int* t = new int[n];
    int& r = *(t+3);
    (*t) = 1;
    *(t+1) = 2;
    t[2] = 3;
    r = 4;

    int z = (*fptr)(5, x, &y, t, 12);    

    for(int i = 0; i < 2*n; i++)
    {
        if( i == n )
            continue;
        if( i > n )
            break;
        cout << t[i] << "\n";
    };
    cout << x << ", " << y << ", " << z << "\n";
    
    delete[] t;
}

This is what my professor gave as part of the final exam. The purpose of giving us this code was to get us used to seeing different ways the C++ syntax can be used and figure out what the output is.

By Anonymous, 2023-02-02 21:29:11
@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
if ((bool)greenButton.IsChecked)
{
    CurrentColor = Color.FromArgb(0xFF, 0x00, 0xCC, 0x00);
}
else if ((bool)greyButton.IsChecked)
{
    CurrentColor = Color.FromArgb(0xFF, 0x79, 0x79, 0x79);
}

foreach (var item in ItemsList.Items)
{
    if ((grid.Background as SolidColorBrush).Color == CurrentColor)
    {
        selectedItems.Add(item);
    }
}
By Anonymous, 2019-09-13 15:41:19
from itertools import combinations as comb
from functools import reduce
  
def all_arrangements(k):
	m=k*(k+1)/2
	m_bits_on=set([tuple(reduce(lambda x,y:x[:y]+[1]+x[y+1:],c,[0]*(2*m+1))) for c in comb(range(2*m+1),m)])
	return set([tuple(sorted(filter(lambda i:i>0,reduce(lambda x,y: x+[y] if y==0 else x[:-1]+[x[-1]+1,],p,[0])))) for p in m_bits_on])

Returns all arrangements in the Bulgarian solitaire game with k piles https://en.wikipedia.org/wiki/Bulgarian_solitaire

By Uri Goren, 2017-12-13 11:48:22
.stepper a{
}

.stepper>div>div>div>div>a{
  color: transparent !important;
}
stepper>div>div>div>div>span{
  color: transparent !important;
}

.stepper>div>div>div:nth-child(1)>div>a:after, .stepper>div>div>div:nth-child(1)>div>span:after{
  color: rgb(52, 58, 64);
  content: '4' !important;
  margin-left: -10px;
}
.stepper>div>div>div:nth-child(2)>div>a:after{
  color: rgb(52, 58, 64);
  content: '3' !important;
  margin-left: -10px;
}
.stepper>div>div>div:nth-child(3)>div>a:after{
  color: rgb(52, 58, 64);
  content: '2' !important;
  margin-left: -10px;
}
.stepper>div>div>div:nth-child(4)>div>a:after{
  color: rgb(52, 58, 64);
  content: '1' !important;
  margin-left: -10px;
}
.stepper>div>div>div:nth-child(4)>div>span:after{
  color: rgb(52, 58, 64);
  background-color: rgb(108, 117, 125);
  content: '1' !important;
  margin-left: -10px;
}
.stepper>div>div>div:nth-child(3)>div>span:after{
  color: rgb(52, 58, 64);
  background-color: rgb(108, 117, 125);
  content: '2' !important;
  margin-left: -10px;
}
.stepper>div>div>div:nth-child(2)>div>span:after{
  color: rgb(52, 58, 64);
  background-color: rgb(108, 117, 125);
  content: '3' !important;
  margin-left: -10px;
}
.stepper>div>div>div:nth-child(1)>div>span:after{
  color: rgb(52, 58, 64);
  background-color: rgb(108, 117, 125);
  content: '4' !important;
  margin-left: -10px;
}
By Anonymous, 2021-08-11 11:24:55
  $(".alarmBell").on("click", () => {

    let icon = $(".alarm-bell__icon")
    icon.attr('data', icon.attr('data') == 'images/icon/alarm-bell.svg' ? 'images/icon/alarm-bell-filled-new.svg' : 'images/icon/alarm-bell.svg');

    // $(".alarm-bell__icon").attr('data', function (index, data) {
    //   if (data == 'images/icon/alarm-bell-filled-new.svg') {
    //     return 'images/icon/alarm-bell.svg';
    //   } else if (data == 'images/icon/alarm-bell.svg') {
    //     return 'images/icon/alarm-bell-filled-new.svg';
    //   } else {
    //     return 'images/icon/alarm-bell.svg';
    //   }
    // });

  });

...after yet another icons change request

By Desperate Dev..., 2020-01-21 17:28:18
base.transform.name = this.bodyName;
		this.radius = this.diameterKm * 500.0;
		this.mass = Math.Pow(this.radius, 2.0) * this.surfaceGravity;
		this.cameraSwitchHeightM = this.cameraSwitchHeightKm * 1000.0;
		if (this.atmosphereData.shadowIntensity == 0f)
		{
			this.atmosphereData.shadowIntensity = 1.65f;
		}
		this.atmosphereData.atmosphereHeightM = this.atmosphereData.atmosphereHeightKm * 1000.0;
		if (this.terrainData.terrainMaterial != null)
		{
			this.terrainData.terrainMaterial.color = this.terrainData.terrainColor;
		}
		this.terrainData.maxTerrainHeight = this.GetMaxTerrainHeight();
		this.terrainData.unitToAngle = 360.0 / ((this.radius + this.terrainData.maxTerrainHeight) * 2.0 * 3.1415926535897931);
		for (int i = 0; i < this.terrainData.detailLevels.Length; i++)
		{
			this.terrainData.detailLevels[i].chunckSize = (double)this.terrainData.baseChunckSize / Math.Pow(2.0, (double)i);
			this.terrainData.detailLevels[i].angularSize = (float)this.terrainData.detailLevels[i].chunckSize / (float)this.terrainData.heightMaps[0].heightMap.HeightDataArray.Length * 360f;
		}
		this.terrainData.detailLevels[0].loadDistance = double.PositiveInfinity;
		if (this.type == CelestialBodyData.Type.Star)
		{
			this.parentBody = null;
			this.orbitData.SOIMultiplier = double.PositiveInfinity;
		}
		if (this.parentBody != null && (this.type == this.parentBody.type || (this.type == CelestialBodyData.Type.Planet && this.parentBody.type == CelestialBodyData.Type.Moon)))
		{
			this.parentBody = null;
		}
		if (this.parentBody != null)
		{
			this.orbitData._period = Kepler.GetPeriod(0.0, this.orbitData.orbitHeightM, this.parentBody.mass);
			this.orbitData.periodString = Ref.GetTimeString(this.orbitData._period);
			this.orbitData._meanMotion = -6.2831853071795862 / this.orbitData._period;
			this.orbitData.orbitalVelocity = this.orbitData.orbitHeightM * this.orbitData._meanMotion;
			this.orbitData.SOI = this.orbitData.orbitHeightM * Math.Pow(this.mass / this.parentBody.mass, 0.4) * this.orbitData.SOIMultiplier;
			if (!this.ParentHasThisBodyAsSatellite())
			{
				List<CelestialBodyData> list = new List<CelestialBodyData>(this.parentBody.satellites);
				list.Add(this);
				this.parentBody.satellites = list.ToArray();
				this.parentBody.ValidateSatellites();
			}
By Anonymous, 2018-02-16 21:20:56
var i = 0

for (var n in array) { 
    i+=1
    // ...
}
By PureJavascript, 2023-02-11 11:08:33
$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