void printNumber(int Number){
    while(Number>0){
        int i=Number%10;
        switch(i) {
            case 1 : cout << '1'; // prints "1",
            case 2 : cout << '2'; // then prints "2"
            case 3 : cout << '3'; // then prints "3"
            case 4 : cout << '4'; // then prints "4"
            case 5 : cout << '5'; // then prints "5"
            case 6 : cout << '6'; // then prints "6"
            case 7 : cout << '7'; // then prints "7"
            case 8 : cout << '8'; // then prints "8"
            case 9 : cout << '9'; // then prints "9"
            case 0 : cout << '0'; // then prints "0"
            default : cout<<'5'; // :|
        }
        Number=Number/10;
    }
}
By Amir Havangi, 2017-12-15 18:03:04

def divide(a, b):
    try:
        return a / b
    except:
        x = 17

My smart exception handling before meeting "pass" :))

By mophix, 2017-12-15 18:13:07
 SELECT CAST(CASE a8900.AllowCloserChanges
             WHEN 0
             THEN 0
             ELSE 1 END AS BIT) AllowCloserChanges
 FROM Vision.sub8900.tApplication8900 a8900 
 WHERE a8900.ApplicationNum = @ApplicationNum

Inheriting others' code in the fun world of corporate development.

By The snitch, 2017-12-15 21:21:56
function prepareKeyword($keyword) {
    $keyword  = html_entity_decode($keyword);
    $keyword  = html_entity_decode($keyword);
    $keyword  = html_entity_decode($keyword);
    $keyword  = iconv("ISO-8859-1", "UTF-8", $keyword);
    $keyword  = cleanString($keyword);
    $keyword  = html_entity_decode($keyword);
    if ($keyword != "") {
        $keyword = mb_strtolower($keyword, "UTF-8");
        $keyword = htmlentities($keyword, ENT_HTML5);
    }
    return $keyword;
}
By Anonymous, 2017-12-15 22:05:55
if (logger.isDebugEnabled()) {
			logger.debug("process (FollettPojo) - start");	
		}
String dnum = StringUtil.toCapitalizedString(pojo.getDnum().toString()); 
pojo.setDnum(new String(dnum));
	    
if (logger.isDebugEnabled()) {
    logger.debug("process (FollettPojo) - middle ");
}

String rawI = StringUtil.toCapitalizedString(pojo.getRawInput().trim().toString()); 
pojo.setRawInput(new String(rawI));

if (logger.isDebugEnabled()) {
	logger.debug("process (FollettPojo) - end ");
}
		
		
/* And you may ask what is this toCapitalizedString? Well here you go a separate class to boot */
	public static String toCapitalizedString(String string){
		StringBuilder strb = new StringBuilder();
		if(string != null && string.trim().length() > 0
				&& Character.isLetter(string.charAt(0))
				&& Character.isLowerCase(string.charAt(0))){

			strb.append(string.substring(0,1).toUpperCase()).append(string.substring(1));
			return strb.toString();
		}
		return string;

	}

SpringBatch this is the processor for each record...dnum example D00000000

By Albert, 2017-12-15 23:53:41
maybeSomething match {
  case Some(x) => true
  case None => false
}

maybeSomething.getOrElse(false) Short code and readable

By Majid Hosseini, 2017-12-16 07:03:07
                    //read country intformation and assign to variables
                    cName = InpList.get(0).replace(",", ".");
                    cCode = InpList.get(1).replace(",", ".");
                    cAlpha2 = InpList.get(2).replace(",", ".");
                    cAbreviation = InpList.get(3).replace(",", ".");
                    dYear = InpList.get(4).replace(",", ".");
                    dPoliticalCompatibility = InpList.get(5).replace(",", ".");
                    dRankPoliticalCompatibility = InpList.get(6).replace(",", ".");
                    dEconomicCompatibility = InpList.get(7).replace(",", ".");
                    dRankEconomicCompatibility = InpList.get(8).replace(",", ".");
                    dMilitaryCompatibility = InpList.get(9).replace(",", ".");
                    dRankMilitaryCompatibility = InpList.get(10).replace(",", ".");
                    dDemoScore = InpList.get(11).replace(",", ".");
                    dRankDemoScore = InpList.get(12).replace(",", ".");
                    dEnvironmentalCompatibility = InpList.get(13).replace(",", ".");
                    dRankEnvironmentalCompatibility = InpList.get(14).replace(",", ".");
                    dSumCompatibility = InpList.get(15).replace(",", ".");
                    dRankCompatibility = InpList.get(16).replace(",", ".");
                    dPoliticalUtility = InpList.get(17).replace(",", ".");
                    dRankPoliticalUtility = InpList.get(18).replace(",", ".");
                    dEconomicUtility = InpList.get(19).replace(",", ".");
                    dRankEconomicUtility = InpList.get(20).replace(",", ".");
                    dMilitaryUtility = InpList.get(21).replace(",", ".");
                    dRankMilitaryUtility = InpList.get(22).replace(",", ".");
                    dEnvironmentalUtility = InpList.get(23).replace(",", ".");
                    dRankEnvironmentalUtility = InpList.get(24).replace(",", ".");
                    dSumUtility = InpList.get(25).replace(",", ".");
                    dRankUtility = InpList.get(26).replace(",", ".");
                    dPoliticalScore = InpList.get(27).replace(",", ".");
                    dRankPoliticalScore = InpList.get(28).replace(",", ".");
                    dEconomicScore = InpList.get(29).replace(",", ".");
                    dRankEconomicScore = InpList.get(30).replace(",", ".");
                    dMilitaryScore = InpList.get(31).replace(",", ".");
                    dRankMilitaryScore = InpList.get(32).replace(",", ".");
                    dEnvironmentalScore = InpList.get(33).replace(",", ".");
                    dRankEnvironmentalScore = InpList.get(34).replace(",", ".");
                    dAggregate = InpList.get(35).replace(",", ".");
                    dRankAggregate = InpList.get(36).replace(",", ".");
By Anonymous, 2017-12-17 21:45:26
public IsTrueWithNewTokenResponse isVoice(String token){
    IsTrueWithNewTokenResponse isTrue = isWhatever(token, 0)
    resultStatus.success = isTrue.generalResultResponse.success;
    resultStatus.statusCode = isTrue.generalResultResponse.statusCode;
    resultStatus.statusDescription  = isTrue.generalResultResponse.statusDescription;
    if(isTrue != null && isTrue.generalResultResponse != null && isTrue.generalResultResponse.success){
        isTrue.isTrue = !isTrue.isTrue
        return isTrue
    } else {
        return isTrue
    }
}
By Anonymous, 2017-12-18 09:11:43
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
if ( x == true)
{
    // do something
}

Fucking amateurs :| lol

By Manoochehr Mojgani, 2017-12-19 10:03:29
zipped_file.extractall(f'{file_path}')
zipped_file.close()
By Anonymous, 2017-12-19 10:29:52
//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
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
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
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