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
Handlebars.registerHelper("compare", function(a, operator, b) {
    var result = false;

    try {
      switch (operator) {
        case "==":
          // eslint-disable-next-line eqeqeq
          result = a == b;
          break;
  
        case "===":
          result = a === b;
          break;
  
        case "!=":
          // eslint-disable-next-line eqeqeq
          result = a != b;
          break;
  
        case "!==":
          result = a !== b;
          break;
  
        case "<":
          result = a < b;
          break;
  
        case ">":
          result = a > b;
          break;
  
        case "<=":
          result = a <= b;
          break;
  
        case ">=":
          result = a >= b;
          break;
  
        case "typeof":
          // eslint-disable-next-line valid-typeof
          result = typeof a === b;
          break;
  
        default: {
          throw new Error(
            "helper {{compare}}: invalid operator: ' + ".concat(operator, " + '")
          );
        }
      }
    } catch (err) {
      console.error("\n********** ".concat(err, "."));
    }
  
    return result;
});
By Anonymous, 2019-04-02 15:46:35
def open(self, *filename):
	if len(filename) > 1:
		print(("Usage:\nopen() - opens with the initialized "
			"filename\nopen(filename) - opens with given filename"))
		return 1
	if len(filename) == 1:
		self.filename = filename[0]
	if self.filename is None:
		print("No filename given")
		return 1
	self.struct_p = open_struct(self.last_error, self.error_size, \
		self.filename)
	if self.struct_p is None:
		print("Cannot open file: " + self.filename)
		return 1
	self.load_data()
	return 0
By Anonymous, 2017-12-12 03:26:17

//https://gist.github.com/nim4n136/7fa38467181130f5a2270c39d495101e

function decrypt($msg_encrypted_bundle, $password){
	$password = sha1($password);

	$components = explode( ':', $msg_encrypted_bundle );
	$iv            = $components[0];
	$salt          = hash('sha256', $password.$components[1]);
	$encrypted_msg = $components[2];

	$decrypted_msg = openssl_decrypt(
	  $encrypted_msg, 'aes-256-cbc', $salt, null, $iv
	);

	if ( $decrypted_msg === false )
		return false;
	return $decrypted_msg;
}
By Anonymous, 2022-05-30 18:28:02
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
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 renderGroupSelectedSuccessors() {
    var index = 0;
    if (tempSuccessorsGroupsList != null && tempSuccessorsGroupsList.length > 0) {
        var groups = tempSuccessorsGroupsList.splice(0, PageSettings.lazyRenderItemsPerPage);
        var groupSuccessors = '';
        for (var i = 0; i < groups.length; i++) {
            if (index % 10 == 0) {
                groupSuccessors += '<div style="float: left;"><ul>';
            }
            groupSuccessors += '<li><a data-groupid="'+groups[i].GroupID+'">' + groups[i].GroupName + '</a></li>';            
            index++;
            if (index % 10 == 0 || i == groups.length - 1) {
                groupSuccessors += '</ul></div>';
            }
        }
        $('#divGroupSuccessorsList').append(groupSuccessors);
        SetCheckBoxState();
        setTimeout(renderGroupSelectedSuccessors, 50);
    }
}

Where does the data come from? Where does it go? Why isn't this an endless recursive loop? Why has this worked for three years?

By Anonymous, 2019-05-10 13:20:47
//Calculates x² of an integer up to ±1 million
var square = (function () {
	var s = "if(A==B){return C;}";
	var func = "var A=Math.abs(D|0);";
	for (var i = 0; i <= 1000000; i++) {
		func += s.replace(/B/, i).replace(/C/, i * i);
	}
	return new Function("D", func + "return Infinity;");
})();
By Anonymous, 2017-12-13 16:53:27
request.get_something = (something_id) => {
  return new Promise((resolve, reject) => {
    database.find_all('something', { where: {something_id: something_id, is_deleted:0} }).then(function(res){
      let result = {};
      res = JSON.stringify(res);
      res = JSON.parse(res);
      res.forEach(function(element){
        if(typeof element.is_deleted != "undefined"){
          delete element.is_deleted;
        }
        let key = 'something_' + element.id;
        result[key] = element;
      });
      resolve(result);
    }, reject);
  });
}

I LOVE MY JOB!

By ADyingDeveloper, 2018-04-05 17:24:33
function clean(toClean, source){
	if (typeof(toClean) !== 'string') return true;
	if (typeof(source) !== 'string') return true;
	
	return source.replace(toClean, String('CLEANED')).toString();
}

Found this in a project at work and someone clearly doesn't trust JavaScripts typeof function

By Anonymous, 2018-06-02 22:09:57
var div = '<div class="imgdiv" '+(user[5] ? 'style="display: flex; flex-direction: column; padding: 10px; justify-content: flex-end; background-image: url(\''+user[5]+'\');"' : '')+'>'
        + (usersVideos[userId] && <?= ($authuser ? 'true' : 'false') ?> ? '<i class="f7-icons icon-acc" onclick="videoShow('+user[uID]+')" style="color: white; font-size: 50px; margin-bottom: 5px; cursor: pointer; text-align: left;">play_round</i>' : '')
        + (iam && page=='home' ? '<div> <input id="video-input" onchange="uploadVideo(files)" type="file" accept="video/*" style="display: none; width: 80%; height: 100px; margin: auto; padding-top: 20px;"/> </div> <p class="action_cont" style="padding: 0; padding-top: 12;"> <a class="act_btn" onmousedown=document.getElementById("video-input").click() href="javascript:void(0)" style="text-decoration: none; margin: auto; width: calc(100% - 26px); text-align: center;"> ' + (myMods['video'] ? 'Загрузить новое видео' : 'Добавить видео-превью' ) + ' </a> </p>' : '')
+ '</div>'

JS + CSS + PHP + HTML

By Anon, 2018-08-24 18:30:12
public void sleep(long duration) {
    long start = System.currentTimeMillis();
    while(true) {
        if (System.currentTimeMillis() - start >= duration)
            break;
    }
}
By imaN NeO, 2018-10-28 09:35:15
(this.router.state['view']['data'] || {})['menuOpen'] && this.router.navigateBack();

That's how pros are javascripting

By Igor, 2017-07-06 04:00:05
function IsNumeric(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;
    for (i = 0; i < sText.length && IsNumber == true; i++) {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

So I suppose that "........" is a valid number...

By L, 2019-07-10 16:05:03
<?php 
$k =1;
for($v = 0; $v < $nt; $v++) {         
	$bgClass= 'blueBg';
		if($k > 1 && $k%2 == 0){
			$bgClass= 'whiteBg';
		}
?> 
<tr  class="row_tr <?php echo $bgClass;?>">						
			<td class="row_td td_column_0">&nbsp;</td>					
			<td class="row_td column_1"><?php echo $rows[$v]['nothing'];?></td>
			...
			<td class="row_td td_column_0">&nbsp;</td>
	</tr>

<?php       
	$k++;
	}	
?>
By Unknown, 2018-02-13 14:47:19