try{
    //...
    getMyDataFromServer();
    //...
}catch(Excepion e){
    // :D
}

HMM FIXED BUG!

By H20, 2017-12-23 11:12:50
val weekEnd = DateTime.now.withDayOfWeek(5).plusDays(2)
By Anonymous, 2017-12-22 13:55:37
@Override
public void afterTextChanged(Editable s) {
    switch (paymentType) {
        case 0:
            if (s.length() == 9) etPaymentAmount.requestFocus();
            break;
        case 1:
            if (s.length() == 9) etPaymentAmount.requestFocus();
            break;
    }
}
By Anonymous, 2017-12-22 12:41:02
guard let reachability = Reachability(), reachability.isReachable == true else {
    // No network connection available. Do stuff.
    ...
}

While this works, it's not immediately readable and creates confusion. Mis-using Swift's control flow. Did not pass code review.

By Anonymous, 2017-12-22 10:04:01
try {
    User.ClaimToken();
} 
catch {
    User.ClaimToken();
}
By Anonymous, 2017-12-22 08:44:59
/// <summary>
/// Method that checks if an object is not null
/// </summary>
/// <param name="obj">extend type of <see cref="Object"/></param>
/// <returns>true if object is not null</returns>
public static bool NotNull(this Object obj)
{
    return obj != null;
}


[TestMethod]
public void Test_Something()
{
    // test
    var result = DoSomething();
    
    // assert
    Assert.IsTrue(result.NotNull());
}
By Anonymous, 2017-12-21 15:42:20
// 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
public void Handle(SomethingCreatedEvent e)
{
    if (e.ActCode == "SOME_VALUE")
    {
        return;
    }
    else
    {
        // insert real function body here
    }
}
By Anonymous, 2017-12-20 15:40:49
Public Shared Function CompeleteDateStr(DateStr As String) As String
    'MBS 96-09-25: High Caliber DataEntry
    Dim DateVal = CType(DateStr, Integer)
    If DateVal < 1 Then Return ""
    If DateVal < maxDay Then 'DayOnly
        Return MakeJalaliDate(curYear, curMonth, DateVal, _4DigitYear)
    ElseIf DateVal > maxDay Then
        Dim YearPiece? As Short = Nothing, MonthPiece? As Byte = Nothing, DayPiece As Byte
        Select Case DateVal
            Case Is < 100
                MonthPiece = (DateVal \ 10) Mod 10
                DayPiece = DateVal Mod 10
                If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
            Case Is < 1000
                MonthPiece = DateVal \ 10
                DayPiece = DateVal Mod 10
                If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
                MonthPiece = (DateVal \ 100) Mod 10
                DayPiece = DateVal Mod 100
                If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
                DayPiece = DateVal \ 10
                MonthPiece = DateVal Mod 10
                If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
                DayPiece = (DateVal \ 100) Mod 10
                MonthPiece = DateVal Mod 100
                If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
            Case Is < 10000
                MonthPiece = DateVal \ 100
                DayPiece = DateVal Mod 100
                If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
                MonthPiece = DateVal Mod 100
                DayPiece = DateVal \ 100
                If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
                DayPiece = DateVal \ 100
                MonthPiece = DateVal Mod 100
                If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
                DayPiece = DateVal Mod 100
                MonthPiece = DateVal \ 100
                If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, curYear) Then Return MakeJalaliDate(curYear, MonthPiece, DayPiece, _4DigitYear)
                MonthPiece = (DateVal \ 10) Mod 10
                YearPiece = DateVal \ 100
                If IsValidMonth(MonthPiece) Then
                    DayPiece = DateVal Mod 10
                    If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
                Else
                    MonthPiece = (DateVal \ 100) Mod 10
                    YearPiece = DateVal Mod 100
                    DayPiece = DateVal \ 1000
                    If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
                End If
            Case Is < 100000
                Dim DaySize As Byte = 2
                MonthPiece = (DateVal Mod 1000) \ 10
                If Not IsValidMonth(MonthPiece) Then
                    MonthPiece = (DateVal \ 100) Mod 10
                    DaySize = 1
                    If Not IsValidMonth(MonthPiece) Then Return ""
                End If
                YearPiece = DateVal \ 1000
                DayPiece = DateVal Mod 10 ^ DaySize
                If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece)
                YearPiece = DateVal Mod 100
                DayPiece = DateVal \ (10000 \ (10 ^ DaySize))
                If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece)
            Case Is < 1000000
                MonthPiece = (DateVal Mod 10000) \ 100
                If IsValidMonth(MonthPiece) Then
                    YearPiece = DateVal \ 10000
                    DayPiece = DateVal Mod 100
                    If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
                    YearPiece = DateVal Mod 100
                    DayPiece = DateVal \ 10000
                    If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
                End If
                YearPiece = DateVal \ 100
                If YearPiece > 1300 AndAlso YearPiece < 1500 Then
                    MonthPiece = (DateVal \ 10) Mod 10
                    DayPiece = DateVal Mod 10
                    If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
                End If
                YearPiece = DateVal Mod 10000
                If YearPiece > 1300 AndAlso YearPiece < 1400 Then
                    DayPiece = DateVal \ 100000
                    MonthPiece = (DateVal \ 10000) Mod 10
                    If IsValidMonth(MonthPiece) AndAlso IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece + If(_4DigitYear, 0, -1300), MonthPiece, DayPiece, _4DigitYear)
                End If
            Case Is < 10000000
                Dim DaySize As Byte = 2
                MonthPiece = (DateVal Mod 1000) \ 10
                If Not IsValidMonth(MonthPiece) Then
                    MonthPiece = (DateVal \ 100) Mod 10
                    DaySize = 2
                    If Not IsValidMonth(MonthPiece) Then Return ""
                End If
                YearPiece = DateVal \ 1000
                DayPiece = DateVal Mod 10 ^ DaySize
                If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece)
                YearPiece = DateVal Mod 10000
                DayPiece = DateVal \ (100000 * (10 ^ DaySize))
                If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece)
            Case Is < 100000000
                MonthPiece = (DateVal Mod 10000) \ 100 '13961229
                If IsValidMonth(MonthPiece) Then
                    YearPiece = DateVal \ 10000
                    DayPiece = DateVal Mod 100
                    If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
                    YearPiece = DateVal Mod 10000
                    DayPiece = DateVal \ 1000000
                    If IsValidDay(DayPiece, MonthPiece, YearPiece) Then Return MakeJalaliDate(YearPiece, MonthPiece, DayPiece, _4DigitYear)
                End If
        End Select
        Return ""
    End If
End Function

this code is so wrong in so many different levels

By NoobProger, 2017-12-20 12:37:08
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
private static final double RESULT_OF_DIVISION_BY_0 = 9.99;

public static double getPercentageDifference(long currentResult, long previousResult) {
    if (previousResult == 0 && currentResult == 0) {
        return 0;
    } else if (previousResult == 0) {
        return RESULT_OF_DIVISION_BY_0;
    } else {
        return (currentResult - previousResult) * 1.0 / previousResult;
    }
}
By Anonymous, 2017-12-20 10:56:50
//count to 10
#include <iostream>
#include <string>

int main()
{
  int i = 0;
  
  beginning:
  if (i < 10) {
      std::cout << ++i << std::endl;
      goto beginning;
  }
  else goto end;

  end:
  return 0;
}
By Yoges, 2017-12-19 14:43:26
zipped_file.extractall(f'{file_path}')
zipped_file.close()
By Anonymous, 2017-12-19 10:29:52
if ( x == true)
{
    // do something
}

Fucking amateurs :| lol

By Manoochehr Mojgani, 2017-12-19 10:03:29
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