String.prototype.capitalize=function(){return this.charAt(0).toUpperCase()+this.slice(1);};
String.prototype.followCase=function(b){
	if(b==b.toUpperCase()){return this.toUpperCase();}
	if(b==b.toLowerCase()){return this.toLowerCase();}
	if(b==b.capitalize()){return this.capitalize();}
	return this;
};
String.prototype.atRemoveAdd=function(index,n,string){
	return this.substring(0,index)+string+this.substring(index+n,this.length);
};
String.prototype.matchIndex=function(re){
	var a=[];
	while((match=re.exec(this))!==null){
		a.push({chars:match[0].length,index:match.index});
	}
	return a;
};
String.prototype.caseReplace=function(o,n){
	for(var s=this,a=this.matchIndex(o),shift=0,i=0;i<a.length;i++){
		var c=n.followCase(this.substring(a[i].index,a[i].index+a[i].chars));
		s=s.atRemoveAdd(a[i].index+shift,a[i].chars,c);
		shift+=c.length-a[i].chars;
	}
	return s;
};

My code from 2016 for the hall of shame where I realized today that caseReplace could just return this.replace(o,m=>n.followCase(m)) instead.

By Anonymous, 2017-12-19 03:55:58
  $guard = ($vars->a_payment) + (0) * $price;
  if ($bless >= $guard) {
    $amount = $bless;
  }

Why not to write just 1 line?! $amount = max($bless, $vars->a_payment);

By Anonymous, 2018-02-05 17:27:25
    if (preg_match("/^N/",$postcode)) {
        if (preg_match("/^NW/", $postcode)) {
            if (!preg_match("/^NW1/", $postcode)) {
                // NORTH WEST (NW2, NW3, NW4, NW5, NW6, NW7, NW8, NW9, NW10)
                $property['Prop_area'] = 'NW';
            } else {
                // NW1 which is Central
                $property['Prop_area'] = 'SW';
            }
        } else {
            // NORTH  (N1, N2, N3, N4, N5 etc)
            $property['Prop_area'] = 'N';
        }
    } else if (preg_match("/^W/",$postcode)) {
        if (
            !preg_match("/^W1 /",$postcode)
            && !preg_match("/^W2 /",$postcode)
            && !preg_match("/^W8/",$postcode)
            && !preg_match("/^W11/",$postcode)
        ) {
            // WEST includes (W3, W4, W5, W6, W7, W9, W10, W12, W13, W14)
            $property['Prop_area'] = 'W';
        } else {
            //W1 and W2, W8, W11 which are Central
            $property['Prop_area'] = 'SW';
        }
    } else {
        if (
            preg_match("/^SW/",$postcode)
            || preg_match("/^EC/",$postcode)
            || preg_match("/^WC/",$postcode)
        ) {
            // CENTRAL includes (W1, W2, EC, WC, NW1, SW1, SW3, SW5, SW7, W8, W11)
            $property['Prop_area'] = 'SW';
        } else {
            // OTHER includes South and East and everything else
            return 'SE';
        }
    }
By ichikawayukko, 2018-11-06 12:30:21
if yearOfBirth > 2002 {
    fmt.Errorf("year of birth not allowed %d", yob)
    return
}
By V, 2021-06-15 14:53:58
ngOnInit() {
    this._FunctionService.getSicksList().then(res => {
        let resf:any = res;
        if (resf.err) {
        } else {
            this.diagnosticAll = resf.data
        }
    }, err => { })
}
/*
ngOnInit() {
    this._FunctionService.getSicksList().then(res => {
        this.diagnosticAll = res.data
    }, err => { })
}
*/
By ElkinDev, 2019-06-27 15:18:41
const handleBoolean = value => {
        switch (value) {
            case "true":
                return true;
            case true:
                return "true";
            case "false":
                return false;
            case false:
                return "false"
            default:
                return null;
        }
    }
By Ifncn, 2022-01-27 07:49:16

function atoi(charstring)
{
  if(charstring=="a") return 0x61;if(charstring=="b") return 0x62;
  if(charstring=="c") return 0x63;if(charstring=="d") return 0x64;
  if(charstring=="e") return 0x65;if(charstring=="f") return 0x66;
  if(charstring=="g") return 0x67;if(charstring=="h") return 0x68;
  if(charstring=="i") return 0x69;if(charstring=="j") return 0x6a;
  if(charstring=="k") return 0x6b;if(charstring=="l") return 0x6c;
  if(charstring=="m") return 0x6d;if(charstring=="n") return 0x6e;
  if(charstring=="o") return 0x6f;if(charstring=="p") return 0x70;
  if(charstring=="q") return 0x71;if(charstring=="r") return 0x72;
  if(charstring=="s") return 0x73;if(charstring=="t") return 0x74;
  if(charstring=="u") return 0x75;if(charstring=="v") return 0x76;
  if(charstring=="w") return 0x77;if(charstring=="x") return 0x78;
  if(charstring=="y") return 0x79;if(charstring=="z") return 0x7a;
  if(charstring=="0") return 0x30;if(charstring=="1") return 0x31;
  if(charstring=="2") return 0x32;if(charstring=="3") return 0x33;
  if(charstring=="4") return 0x34;if(charstring=="5") return 0x35;
  if(charstring=="6") return 0x36;if(charstring=="7") return 0x37;
  if(charstring=="8") return 0x38;if(charstring=="9") return 0x39;
  if(charstring==".") return 0x2e;
  return 0x20;
}

found in a proxy script

By Anonymous, 2020-08-10 03:17:52
typedef NS_ENUM(NSUInteger, MyEnum1) {
    PackagesNo1 = 1,
    PackagesNo2 = 2,
    PackagesNo4 = 4,
    PackagesNo8 = 8
};

typedef NS_ENUM(NSUInteger, MyEnum2) {
    LEVEL0 = 0,
    LEVEL1 = 1,
    LEVEL2 = 2,
    LEVEL3 = 3
};

- (int)packagesNeededForLevel:(int)level {
    switch (level) {
        case LEVEL0:
            return PackagesNo8;
        case LEVEL1:
            return PackagesNo4;
        case LEVEL2:
            return PackagesNo2;
        case LEVEL3:
            return PackagesNo1;
    }
}

well done mr junior

By Anonymous, 2021-04-12 09:37:34
if (isset($data['phone_id']) && !empty($data['phone_id'])) {
    $userPhone = $this->getDoctrine()->getRepository('STODBBundle:Phones')->find($data['phone_id']);
    if ($userPhone->getPhoneNumber() != $data['phone'] || $userPhone->getMobileProviderCode()->getId() != $data['phone_code']) {
        if ($data['smsCode'] ?? false) {
            if ($sessionSmsCode !== $data['smsCode']) {
                $aData['smsCodeShow'] = false;
                $aData['isWrongCode'] = true;
            } else {
                $aData['isWrongCode'] = false;
                $checkCode = $data['smsCode'];
            }
        } else {
            $aData['smsCodeShow'] = true;
            $aData['isWrongCode'] = true;
        }
    } elseif (!$userPhone->getCodeCheck()) {
        if ($data['smsCode'] ?? false) {
            if ($sessionSmsCode !== $data['smsCode']) {
                $aData['smsCodeShow'] = false;
                $aData['isWrongCode'] = true;
            } else {
                $aData['isWrongCode'] = false;
                $checkCode = $data['smsCode'];
            }
        } else {
            $aData['smsCodeShow'] = true;
        }
    } else {
        $aData['isWrongCode'] = false;
    }
} else {
    if ($data['smsCode'] ?? false) {
        if ($sessionSmsCode !== $data['smsCode']) {
            $aData['smsCodeShow'] = false;
            $aData['isWrongCode'] = true;
        } else {
            $aData['isWrongCode'] = false;
            $checkCode = $data['smsCode'];
        }
    } else {
        $aData['smsCodeShow'] = true;
    }
}

shit ... this junior

By sergma33, 2020-12-23 15:30:45
    if (model.env.Trim().ToUpper() == "Release")
    {
        retVal = false;
        if (!string.IsNullOrEmpty(model.Server_Core))
        {
            // Perform a trim in case user specified just whitespace...
            string tmpStr = model.Server_Core.Trim();
            if (!string.IsNullOrEmpty(tmpStr))
            {
                retVal = true;
            }
        }
    }
By Anonymous, 2019-02-25 17:12:31

var move=0;
var kier=0;
var pic=0;
var rol=0;

var rol2=171;
var rol3=343;
var rol4=514;
var rol2_cel=171;
var rol3_cel=343;
var rol4_cel=514;

function onpic(p) {
  pic=p;
}

function offpic(p) {
  if( pic==p ) pic=0;
}

 function next() { if(move<40) move = 40; kier=0; }
 function prev() { if(move<40) move = 60; kier=1; }
 function set() {
  document.getElementById('ba1').style.left=0;
  document.getElementById('ba2').style.left=rol2;
  document.getElementById('ba3').style.left=rol3;
  document.getElementById('ba4').style.left=rol4;
}


function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}


var randtim=new Array(110,103,130,125,108,118,112,122,101,100);
var showtimer=0;
var showpic=1;

 
 function Animuj() {
   if( pic==0 ) {
     rol2_cel=171;
     rol3_cel=343;
     rol4_cel=514;
   } else if( pic==1 ) {
     rol2_cel=342;
     rol3_cel=457;
     rol4_cel=571;
   } else if( pic==2 ) {
     rol2_cel=115;
     rol3_cel=457;
     rol4_cel=571;
   } else if( pic==3 ) {
     rol2_cel=114;
     rol3_cel=229;
     rol4_cel=571;
   } else if( pic==4 ) {
     rol2_cel=114;
     rol3_cel=228;
     rol4_cel=344;
   }
   var a = (rol2-rol2_cel)/10; if(( a< -0.1 )&&( a> -1 )) a = -1; if(( a>0.1 )&&( a<1 )) a = 1;
   if( rol2!=rol2_cel ) rol2-= a;
   var a = (rol3-rol3_cel)/10; if(( a< -0.1 )&&( a> -1 )) a = -1; if(( a>0.1 )&&( a<1 )) a = 1;
   if( rol3!=rol3_cel ) rol3-= a;
   var a = (rol4-rol4_cel)/10; if(( a< -0.1 )&&( a> -1 )) a = -1; if(( a>0.1 )&&( a<1 )) a = 1;
   if( rol4!=rol4_cel ) rol4-= a;
   set();
    document.getElementById('ba2').style.left=rol2;



 showtimer+=1;
 if(showtimer>100) {
  for( st=0; st<9; ++st ) {
   if(showtimer==randtim[st]) { SetOpacity(document.getElementById("ps"+st), 0); document.getElementById("ps"+st).style.backgroundImage="url('cs/log"+showpic+".jpg')"; }
   if(showtimer==(randtim[st]+1)) SetOpacity(document.getElementById("ps"+st),20); 
   if(showtimer==(randtim[st]+2)) SetOpacity(document.getElementById("ps"+st),40); 
   if(showtimer==(randtim[st]+3)) SetOpacity(document.getElementById("ps"+st),60); 
   if(showtimer==(randtim[st]+4)) SetOpacity(document.getElementById("ps"+st),80); 
   if(showtimer==(randtim[st]+5)) { document.getElementById("pn"+st).style.backgroundImage="url('cs/log"+showpic+".jpg')"; SetOpacity(document.getElementById("ps"+st),0); }
  }
  if(showtimer>150) {
   showtimer=0;
   for( st=0; st<9; ++st ) randtim[st]=Math.floor(Math.random()*26)+100;
   showpic+=1; if(showpic>2) showpic=0;
  }
 }


 }

 window.setInterval("Animuj()", 50);

This is how public money is spent in poland

By Anonymous, 2019-05-29 18:35:09
public partial class Form1 : Form
   {
      public Form1()
      {
         InitializeComponent();
      }

      protected override void OnLoad(EventArgs e)
      {
         base.OnLoad(e);
         var token = new CancellationTokenSource().Token;
         Task.Factory.StartNew (() => {
            while (!token.IsCancellationRequested) {
               try {
                  if (/*Condition*/)
                     this.Invoke(new Action(() => label.Text = " =)"));
                  else
                     this.Invoke(new Action(() => label.Text = " =("));
                  Thread.Sleep(10);
               }
               catch (Exception) {
                  throw;
               }
               finally {
                  throw new Exception();
               }
            }
         }) ;
      }
   }

My collegue's way of using multithreading features (and exceptions handling) :)

By Loganjii, 2019-10-09 15:00: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
function add(input1,input2) {
	var number1 = input1.toString();
	var number2 = input2.toString();
	var numbers1 = new Array();
	var numbers2 = new Array();
	var size1 = 0;
	var size2 = 0;
	while(size1 < number1.length) {
		var SizeAndNumberToAddToNumbers1Array = 0;
		var Number1FromFunctionAddLength = number1.length-size1-1;
		SizeAndNumberToAddToNumbers1Array = number1.charAt(size1);
		while(Number1FromFunctionAddLength > 0){
			SizeAndNumberToAddToNumbers1Array = SizeAndNumberToAddToNumbers1Array + "0";
			Number1FromFunctionAddLength = Number1FromFunctionAddLength-1;
		}
		numbers1.push(SizeAndNumberToAddToNumbers1Array);
		size1 = size1 + 1;
	}
	while(size2 < number2.length) {
		var SizeAndNumberToAddToNumbers1Array2 = 0;
		var Number1FromFunctionAddLength2 = number2.length-size2-1;
		SizeAndNumberToAddToNumbers1Array2 = number2.charAt(size2);
		while(Number1FromFunctionAddLength2 > 0){
			SizeAndNumberToAddToNumbers1Array2 = SizeAndNumberToAddToNumbers1Array2 + "0";
			Number1FromFunctionAddLength2 = Number1FromFunctionAddLength2-1;
		}
		numbers2.push(SizeAndNumberToAddToNumbers1Array2);
		size2 = size2 + 1;
	}
	var result1 = 0;
	var saize1 = 0;
	while(saize1 < numbers1.length){
		var topush1 = numbers1[saize1];
		result1=result1+parseInt(topush1);
		saize1 = saize1 + 1;
	}
	var result2 = 0;
	var saize2 = 0;
	while(saize2 < numbers2.length){
		var topush2 = numbers2[saize2];
		result2=result2+parseInt(topush2);
		saize2 = saize2 + 1;
	}
	return result1+result2;
}

advanced and optimized add function better than a + b

By Rzaba Kiddo, 2021-11-27 21:25:24
bool calculateLeapYear(uint8_t year) {
    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
        return true;
    } else {
        return false;
    }
}

uint8_t and a useless if.

By eha, 2023-06-19 23:01:57