String zeroPad(int number) {
  return number < 10 ? "0" + number : String.valueOf(number);
}

You could just have done String.format("%02d", number);

By Anonymous, 2022-04-30 10:50:20
const newReply = (reply !== null) ? reply : null;
By foxy, 2018-06-04 21:19:27
private HashMap<String, Tuple6<float[], String[], String[], String[], String[], String>> memberNameChangedToProtectTheInnocent = null;
By Anonymous, 2017-12-12 12:13:22
<ng-container *ngIf="!errors">
    <div *ngIf="errors" class="no-content-wrapper">
        <esel-components-error [error]="errors"></esel-components-error>
    </div>
</ng-container>

Make your code error prone with effective error handling!

By Anonymous, 2019-10-11 12:49: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
    public static String arrayToString(List list) {
        if (list == null) {
            throw new IllegalArgumentException("list is null");
        }
        return list.toString()
                .replace("[", "")  //remove the right bracket
                .replace("]", "")  //remove the left bracket
                .trim();
    }
By Anonymous, 2023-07-30 00:29:07
export const LandingReducer=createSlice({
    name:'MAIN_SLICE',
    initialState:initialStates,
    reducers: {
        changeStateValue:(state,action) => {
            state[action.payload.name] = action.payload.value
            const check = action.payload.name.includes('.')
            if (!check) {
                state[action.payload.name] = action.payload.value
            }else{
                const groups=action.payload.name.split('.')
                console.log(groups);
                if(groups.length===2){
                    state[groups[0]][groups[1]]=action.payload.value;
                }else if(groups.length===3){
                    state[groups[0]][groups[1]][groups[2]]=action.payload.value;
                }else if(groups.length===4){
                    state[groups[0]][groups[1]][groups[2]][groups[3]]=action.payload.value;
                }
            }
        }
    }
});
By shitmaker, 2023-08-08 16:33:56
reduc_ind = list(xrange(1, len(x.get_shape())))
By Anonymous, 2017-08-14 18:37:29
def even?(number)
  if number > 0
    result = number
  else
    result = -number
  end

  while result > 2 or result == 2
    result = result - 2
  end

  if result == 0
    true
  else
    false
  end
end

Best solution to find out if a number is even.

By Anonymous, 2023-11-12 14:59:07
function generateArrayFrom1To10()
{
    let a = 0;
    let b = 1;
    let c = 3;
    let d = 4;
    let e = 5;
    let f = 6;
    let g = 7;
    let h = 8;
    let i = 9;
    
    let array = [a,b,c,d,e,f,g,h,i];
    
    return array;
    
}
By Melon Tasters, 2019-07-11 18:06:38
public class MandateData {

    public final UUID coreId;
    public final UUID accountId;
    public final String accountRef;
    public final String creditorId;
    public final String creditorName;
    public final String debtorFirstName;
    public final String debtorLastName;
    public final String branchCode;
    public final String accountNumber;
    public final LocalDate signingDate;
    public final Address debtorAddress;

    private MandateData(UUID coreId, UUID accountId, String accountRef, String creditorId, String creditorName, String branchCode, String accountNumber, String debtorFirstName, String debtorLastName,
                        LocalDate signingDate, Address debtorAddress) {
        this.coreId = coreId;
        this.accountId = accountId;
        this.accountRef = accountRef;
        this.creditorId = creditorId;
        this.creditorName = creditorName;
        this.debtorFirstName = debtorFirstName;
        this.debtorLastName = debtorLastName;
        this.branchCode = branchCode;
        this.accountNumber = accountNumber;
        this.signingDate = signingDate;
        this.debtorAddress = debtorAddress;
    }

    public static MandateData creationMandateData(UUID coreId, UUID accountId, String accountRef, String creditorId, String creditorName, String branchCode, String accountNumber, String debtorFirstName, String debtorLastName,
                                                  LocalDate signingDate, Address debtorAddress) {
        return new MandateData(coreId, accountId, accountRef, creditorId, creditorName, branchCode, accountNumber, debtorFirstName, debtorLastName, signingDate, debtorAddress);
    }
}

There is an ancient and mysterious legend about public static constructor, called createShit. If anyone want's just to create an instance of Shit be aware of it! This is too obvious! just Implement static method with the exactly the same fields, and make constructor private. Don't write a shit!

By Anonymous, 2018-06-07 13:03:44
<style type="text/css">
    <?php echo file_get_contents(
            \realpath(ROOT_PATH . '/public/').$this->assetPath('css/styles.css', true)
            ); ?>
</style>

Including style file (about 100kb) directly to HTML page. Thanks for developer, it's in .

By Ed, 2023-07-28 10:51:07
fn add_unsafe(a: i32, b: i32) -> i32 {
  a + b
}

fn add_safer(a: i32, b: i32) -> std::io::Result<i32> {
  Ok(add_unsafe(a, b))
}

fn add_option(a: i32, b:i32) -> Option<std::io::Result<i32>> {
  Some(add_safer(a, b))
}

fn main() {
  println!("{:?}", add_option("4".parse::<i32>().unwrap(), "5".parse::<i32>().unwrap()).unwrap().unwrap());
}

it unwraps

By onrirr mqhirr, 2023-08-10 11:21:24
 private void EnableGPSAutoMatically() {
        GoogleApiClient googleApiClient = null;
        if (googleApiClient == null) {
            oogleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(LocationServices.API).addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this).build();
            /* about 50 lines of code were here ... 
             * all depends on this if statement ... !
             * Actually the whole method depends on this if statement ! */
                    }
                }
            });
        }
}

what if that mysterious power change it to be not null !! It gonna be a holly object and You should not "new" it anymore ?! damn ... :)))

By Anonymous, 2018-03-28 11:31:15
const int ONLY_ONE_ITEM = 1;

if (myList.Count > ONLY_ONE_ITEM)
{
    DoSomething();
}
else
{
    DoSomethingElse();
}
By Anonymous, 2018-05-15 17:04:22