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
// this.collectPairs() returns data from the UI form 
// this.alert.alarmReasons contains empty array or alarmReason-Category pair objects

let newAlarmReasonsToAdd = []

this.collectPairs().forEach(categoryAndAlarmReasonPair => {
  !!!this.searchAmidExisting(categoryAndAlarmReasonPair, this.alert.alarmReasons) ? newAlarmReasonsToAdd.push(categoryAndAlarmReasonPair) : null
})

searchAmidExisting(alarmReasonToAdd, existingAlarmReasons){
    let res = existingAlarmReasons.find(existing => {
    if(alarmReasonToAdd.categoryDictEntryKey === existing.category && alarmReasonToAdd.reasonDictEntryKey === existing.reason){
      return true
    } else return false
  })
    return res
  }
By mallioppilas, 2023-11-03 14:13:41
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
    string sum_numbers(string a, string b) {
        char ca, cb, ci, out, co = '0';
        string result = "";
        while (a.size() > 0 || b.size() > 0 || co != '0') {
            ci = co; ca = '0'; cb = '0';
            if (a.size() > 0) {ca = a.back(); a.pop_back();}
            if (b.size() > 0) {cb = b.back(); b.pop_back();}
            result = ((((ca != cb) ? '1' : '0') != ci) ? '1' : '0') + result;
            co = ((((ca == '1' && cb == '1') ? '1' : '0') == '1' || 
                 ((((ca != cb) ? '1' : '0') == '1' && ci == '1') ? '1' : '0') == '1') ? '1' : '0');
        }
        return result;
    }

Scary stuff

By Anonymous, 2023-12-01 22:20:27
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iterator>

constexpr int N = 10;

int main() {
    std::vector<int> even;
    std::vector<int> odd;
    
    even.resize(N);
    
    // Fill up the 'even' vector with integers starting from from 1 through 'N'
    std::iota(even.begin(), even.end(), 1);

    // Segregate the odd and even integers from each other
    
    for (auto it = even.begin(); it != even.end(); ++it)
        if (*it % 2 != 0) {
            // If the number is odd, put it in the 'odd' vector
            odd.push_back(*it);
            // Remove the number from the even vector
            even.erase(it);
        }

    // Print the result
    
    std::cout << "Even numbers: ";
    std::copy(even.begin(), even.end(), std::ostream_iterator<int>(std::cout, " "));

    std::cout << "\nOdd numbers: ";
    std::copy(odd.begin(), odd.end(), std::ostream_iterator<int>(std::cout, " "));

    std::cout << '\n';
}

Seems fine to me... C++ couldn't possibly be THAT evil to introduce another nuanced and verbose complexity in there, right?

By cufbox, 2023-12-15 09:38:58
/*
 *                                                      _____________________________________________________ 
 *                                           ___________↓___↓____________________________________________   |  
 *                                          _↓_________↓|___|________________________________________   |   |
 *                                    ______↓|_________||___|↓___________________________________   |   |   |
 *                               _____↓__↓__||_________||___||_______________________________   |   |   |   |
 *                              _↓__↓_|__|__||_________||___||___________________________   |   |   |   |   |
 *                     _________↓|__|_|__|↓_||_________||___||_______________________   |   |   |   |   |   |
 *                     ↓   ↓    ||  | |  || ||         ||   ||                      |   |   |   |   |   |   |      */
opcId = child.replace(/([.])?(?:((.+)=(.+))|(([a-zA-Z]+)(\d*)))/g, function (match, m1, m2, m3, m4, m5, m6, m7) {
By Michal, 2024-01-18 13:18:02
const [glossaries, prompts] = [await getGlossaries(), await getPromps()];

// instead of
// const [glossaries, prompts] = await Promise.all([getGlossaries(), getPrompts()]);

When I was writing the code, I thought for a moment that getGlossaries() and getPrompts() will be executed in parallel

By igor, 2024-01-22 17:24:54
export const getUniqueIds = (ids: string[]) => {
  const uniqueIds = new Set<string>();
  return ids.filter((id) => {
    if (!uniqueIds.has(id)) {
      uniqueIds.add(id);
      return true;
    }
    return false;
  });
};
By Anonymous, 2024-01-27 11:22:30
//class tworzenie.FaceOknoDodatki
var b = 2;
   var wlosyT = [tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,7,4,4,7,8,9,10,6,8,6,5,5,7,8,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b];
   var brwiT = [tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b];
   var oczyT = [tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,5,6,6,7,8,8,8,9,9,9,10,10,10,10,10,10];
   var nosT = [tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b];
   var brodaT = [tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,5,6,7,7,8,9];
   var ustaT = [tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,10,10];
   var czachyT = [tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,10];
   var tatuazT = [tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,3,7,7,7,7,8,8,8,9,9,9,10,10,0,0,0,0,0,0,0,0,0,0,0,0,0];
   var opaskaT = [tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,8,9,10,7,8,9,8,9,10,10,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
   var kolczykiT = [tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,3,3,4,4,5,6,5,6,7,8,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
   var kolczyki2T = [tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,3,3,6,5,8,9,4,7,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
   var bliznaT = [tworzenie.FaceOknoDodatki.prototype.b,tworzenie.FaceOknoDodatki.prototype.b,5,7,8,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];

code from some shitty polish game, character face creator

By whitemoon, 2024-03-08 19:58:38
int main() {
    int error_code = some_function();
    if (error_code == 1) {
        // In case of error, crash the program by eating up memory
        while (true) new int;
    }
}
By Anonymous, 2024-04-30 08:31:39