ronantakizawa/codereview-bench huggingface dataset:
Repository: dogecoin/dogecoin
File: share/rpcuser/rpcuser.py (Python)

Code before:
import hmac

def generate_salt(size):
    """Create size byte hex salt"""
    return token_hex(size)

def generate_password():
    """Create 32 byte b64 password"""
    return token_urlsafe(32)

def password_to_hmac(salt, password):
    m = hmac.new(salt.encode('utf-8'), password.encode('utf-8'), 'SHA256')
    return m.hexdigest()

if len(sys.argv) < 2:
    sys.stderr.write('Please include username as an argument.\n')
    sys.exit(0)

username = sys.argv[1]
password = generate_password()

# Create 16 byte hex salt
salt = generate_salt(16)
password_hmac = password_to_hmac(salt, password)

print('String to be appended to bitcoin.conf:')
print(f'rpcauth={username}:{salt}${password_hmac}')
print(f'Your password:\n{password}')


Review comment (suggestion):
Can you change this to `dogecoin.conf`? I think that's the only difference we want between these files. Thanks!

Code after:
import hmac

def generate_salt(size):
    """Create size byte hex salt"""
    return token_hex(size)

def generate_password():
    """Create 32 byte b64 password"""
    return token_urlsafe(32)

def password_to_hmac(salt, password):
    m = hmac.new(salt.encode('utf-8'), password.encode('utf-8'), 'SHA256')
    return m.hexdigest()

if len(sys.argv) < 2:
    sys.stderr.write('Please include username as an argument.\n')
    sys.exit(0)

username = sys.argv[1]
password = generate_password()

# Create 16 byte hex salt
salt = generate_salt(16)
password_hmac = password_to_hmac(salt, password)

print('String to be appended to dogecoin.conf:')
print(f'rpcauth={username}:{salt}${password_hmac}')
print(f'Your password:\n{password}')
Repository: expressjs/express
File: examples/search/index.js (JavaScript)

Code before:
db.connect()
  .catch((err) => console.error('Redis connection error:', err));

var app = express();

app.use(express.static(path.join(__dirname, 'public')));

// populate search

(async () => {
  try {
    await db.sAdd('ferret', 'tobi');
    await db.sAdd('ferret', 'loki');
    await db.sAdd('ferret', 'jane');
    await db.sAdd('cat', 'manny');
    await db.sAdd('cat', 'luna');
  } catch (err) {
    console.error('Error populating Redis:', err);
  }
})();

/**
 * GET search for :query.
 */

app.get('/search/:query{0,1}', function (req, res, next) {
  var query = req.params.query || '';
  db.sMembers(query)
    .then((vals) => res.send(vals))
    .catch((err) => {
      console.error(`Redis error for query "${query}":`, err);
      next(err);
    });
});

/**
 * GET client javascript. Here we use sendFile()
 * because serving __dirname with the static() middleware
 * would also mean serving our server "index.js" and the "search.jade"
 * template.
 */

app.get('/client.js', function(req, res){
  res.sendFile(path.join(__dirname, 'client.js'));
});

/* istanbul ignore next */
if (!module.parent) {
  app.listen(3000);
  console.log('Express started on port 3000');
}

Review comment (suggestion):
This is probably better done as `/{:query}` if we intend it to be optional like the original example. 

Code after:

/**
 * Redis Initialization
 */

async function initializeRedis() {
  try {
    // connect to Redis

    await db.connect();

    // populate search

    await db.sAdd('ferret', 'tobi');
    await db.sAdd('ferret', 'loki');
    await db.sAdd('ferret', 'jane');
    await db.sAdd('cat', 'manny');
    await db.sAdd('cat', 'luna');
  } catch (err) {
    console.error('Error initializing Redis:', err);
    process.exit(1);
  }
}

/**
 * GET search for :query.
 */

app.get('/search/{:query}', function (req, res, next) {
  var query = req.params.query || '';
  db.sMembers(query)
    .then((vals) => res.send(vals))
    .catch((err) => {
      console.error(`Redis error for query "${query}":`, err);
      next(err);
    });
});

/**
 * GET client javascript. Here we use sendFile()
 * because serving __dirname with the static() middleware
 * would also mean serving our server "index.js" and the "search.jade"
 * template.
 */

app.get('/client.js', function(req, res){
  res.sendFile(path.join(__dirname, 'client.js'));
});

/**
 * Start the Server
Repository: expressjs/express
File: examples/search/index.js (JavaScript)

Code before:
var db = redis.createClient();

// npm install redis

// connect to Redis

db.connect()
  .catch((err) => console.error('Redis connection error:', err));

var app = express();

app.use(express.static(path.join(__dirname, 'public')));

// populate search

(async () => {
  try {
    await db.sAdd('ferret', 'tobi');
    await db.sAdd('ferret', 'loki');
    await db.sAdd('ferret', 'jane');
    await db.sAdd('cat', 'manny');
    await db.sAdd('cat', 'luna');
  } catch (err) {
    console.error('Error populating Redis:', err);
  }
})();

/**
 * GET search for :query.
 */

app.get('/search/:query{0,1}', function (req, res, next) {
  var query = req.params.query || '';
  db.sMembers(query)
    .then((vals) => res.send(vals))
    .catch((err) => {
      console.error(`Redis error for query "${query}":`, err);
      next(err);
    });
});

/**
 * GET client javascript. Here we use sendFile()
 * because serving __dirname with the static() middleware
 * would also mean serving our server "index.js" and the "search.jade"
 * template.
 */

app.get('/client.js', function(req, res){
  res.sendFile(path.join(__dirname, 'client.js'));
});

Review comment (suggestion):
Oh oops, I forgot to hit add on this one. I had tried to comment that this change led to some unexpected ordering issues. My original comment was likely better, but for this I think we should make sure that these being run after the server starts is not an issue (because they will be since this is not `aiwat`/`.then`'d before the server starts.

Code after:
var db = redis.createClient();
var app = express();

app.use(express.static(path.join(__dirname, 'public')));

// npm install redis

/**
 * Redis Initialization
 */

async function initializeRedis() {
  try {
    // connect to Redis

    await db.connect();

    // populate search

    await db.sAdd('ferret', 'tobi');
    await db.sAdd('ferret', 'loki');
    await db.sAdd('ferret', 'jane');
    await db.sAdd('cat', 'manny');
    await db.sAdd('cat', 'luna');
  } catch (err) {
    console.error('Error initializing Redis:', err);
    process.exit(1);
  }
}

/**
 * GET search for :query.
 */

app.get('/search/{:query}', function (req, res, next) {
  var query = req.params.query || '';
  db.sMembers(query)
    .then((vals) => res.send(vals))
    .catch((err) => {
      console.error(`Redis error for query "${query}":`, err);
      next(err);
    });
});

/**
 * GET client javascript. Here we use sendFile()
 * because serving __dirname with the static() middleware
 * would also mean serving our server "index.js" and the "search.jade"
 * template.
 */
Repository: expressjs/express
File: lib/response.js (JavaScript)

Code before:
 *
 *     res.send(Buffer.from('wahoo'));
 *     res.send({ some: 'json' });
 *     res.send('<p>some html</p>');
 *
 * @param {string|number|boolean|object|Buffer} body
 * @public
 */

res.send = function send(body) {
  var chunk = body;
  var encoding;
  var req = this.req;
  var type;

  // settings
  var app = this.app;

  switch (typeof chunk) {
    // string defaulting to html
    case 'string':
      encoding = 'utf8';
      type = this.get('Content-Type');

      // set content-type with charset in a single operation
      if (typeof type === "string") {
        this.set('Content-Type', setCharset(type, 'utf-8'));
      } else {
        this.type('html');
      }
      break;
    case 'boolean':
    case 'number':
    case 'object':
      if (chunk === null) {
        chunk = '';
      } else if (ArrayBuffer.isView(chunk)) {
        if (!this.get('Content-Type')) {
          this.type('bin');
        }
      } else {
        return this.json(chunk);
      }
      break;
  }

  // determine if ETag should be generated
  var etagFn = app.get('etag fn')
  var generateETag = !this.get('ETag') && typeof etagFn === 'function'

  // populate Content-Length

Review comment (suggestion):
```suggestion
      if (typeof type === 'string') {
```


Code after:
 *
 *     res.send(Buffer.from('wahoo'));
 *     res.send({ some: 'json' });
 *     res.send('<p>some html</p>');
 *
 * @param {string|number|boolean|object|Buffer} body
 * @public
 */

res.send = function send(body) {
  var chunk = body;
  var encoding;
  var req = this.req;

  // settings
  var app = this.app;

  switch (typeof chunk) {
    // string defaulting to html
    case 'string':
      encoding = 'utf8';
      const type = this.get('Content-Type');

      if (typeof type === 'string') {
        this.set('Content-Type', setCharset(type, 'utf-8'));
      } else {
        this.type('html');
      }
      break;
    case 'boolean':
    case 'number':
    case 'object':
      if (chunk === null) {
        chunk = '';
      } else if (ArrayBuffer.isView(chunk)) {
        if (!this.get('Content-Type')) {
          this.type('bin');
        }
      } else {
        return this.json(chunk);
      }
      break;
  }

  // determine if ETag should be generated
  var etagFn = app.get('etag fn')
  var generateETag = !this.get('ETag') && typeof etagFn === 'function'

  // populate Content-Length
  var len
  if (chunk !== undefined) {
Repository: expressjs/express
File: lib/response.js (JavaScript)

Code before:
 * Send a response.
 *
 * Examples:
 *
 *     res.send(Buffer.from('wahoo'));
 *     res.send({ some: 'json' });
 *     res.send('<p>some html</p>');
 *
 * @param {string|number|boolean|object|Buffer} body
 * @public
 */

res.send = function send(body) {
  var chunk = body;
  var encoding;
  var req = this.req;
  var type;

  // settings
  var app = this.app;

  switch (typeof chunk) {
    // string defaulting to html
    case 'string':
      encoding = 'utf8';
      type = this.get('Content-Type');

      // set content-type with charset in a single operation
      if (typeof type === "string") {
        this.set('Content-Type', setCharset(type, 'utf-8'));
      } else {
        this.type('html');
      }
      break;
    case 'boolean':
    case 'number':
    case 'object':
      if (chunk === null) {
        chunk = '';
      } else if (ArrayBuffer.isView(chunk)) {
        if (!this.get('Content-Type')) {
          this.type('bin');
        }
      } else {
        return this.json(chunk);
      }
      break;
  }

  // determine if ETag should be generated
  var etagFn = app.get('etag fn')

Review comment (suggestion):
This can be turned into a block scoped const now, it is only used in this context. 

Can remove the var type at function top scope

Code after:
 * Send a response.
 *
 * Examples:
 *
 *     res.send(Buffer.from('wahoo'));
 *     res.send({ some: 'json' });
 *     res.send('<p>some html</p>');
 *
 * @param {string|number|boolean|object|Buffer} body
 * @public
 */

res.send = function send(body) {
  var chunk = body;
  var encoding;
  var req = this.req;

  // settings
  var app = this.app;

  switch (typeof chunk) {
    // string defaulting to html
    case 'string':
      encoding = 'utf8';
      const type = this.get('Content-Type');

      if (typeof type === 'string') {
        this.set('Content-Type', setCharset(type, 'utf-8'));
      } else {
        this.type('html');
      }
      break;
    case 'boolean':
    case 'number':
    case 'object':
      if (chunk === null) {
        chunk = '';
      } else if (ArrayBuffer.isView(chunk)) {
        if (!this.get('Content-Type')) {
          this.type('bin');
        }
      } else {
        return this.json(chunk);
      }
      break;
  }

  // determine if ETag should be generated
  var etagFn = app.get('etag fn')
  var generateETag = !this.get('ETag') && typeof etagFn === 'function'
Repository: expressjs/express
File: lib/response.js (JavaScript)

Code before:
 * Examples:
 *
 *     res.send(Buffer.from('wahoo'));
 *     res.send({ some: 'json' });
 *     res.send('<p>some html</p>');
 *
 * @param {string|number|boolean|object|Buffer} body
 * @public
 */

res.send = function send(body) {
  var chunk = body;
  var encoding;
  var req = this.req;

  // settings
  var app = this.app;

  switch (typeof chunk) {
    // string defaulting to html
    case 'string':
      encoding = 'utf8';
      const type = this.get('Content-Type');

      if (typeof type === 'string') {
        this.set('Content-Type', setCharset(type, encoding));
      } else {
        this.type('html');
      }
      break;
    case 'boolean':
    case 'number':
    case 'object':
      if (chunk === null) {
        chunk = '';
      } else if (ArrayBuffer.isView(chunk)) {
        if (!this.get('Content-Type')) {
          this.type('bin');
        }
      } else {
        return this.json(chunk);
      }
      break;
  }

  // determine if ETag should be generated
  var etagFn = app.get('etag fn')
  var generateETag = !this.get('ETag') && typeof etagFn === 'function'

  // populate Content-Length
  var len

Review comment (suggestion):
```suggestion
        this.set('Content-Type', setCharset(type, 'utf-8'));
```

Code after:
 * Examples:
 *
 *     res.send(Buffer.from('wahoo'));
 *     res.send({ some: 'json' });
 *     res.send('<p>some html</p>');
 *
 * @param {string|number|boolean|object|Buffer} body
 * @public
 */

res.send = function send(body) {
  var chunk = body;
  var encoding;
  var req = this.req;

  // settings
  var app = this.app;

  switch (typeof chunk) {
    // string defaulting to html
    case 'string':
      encoding = 'utf8';
      const type = this.get('Content-Type');

      if (typeof type === 'string') {
        this.set('Content-Type', setCharset(type, 'utf-8'));
      } else {
        this.type('html');
      }
      break;
    case 'boolean':
    case 'number':
    case 'object':
      if (chunk === null) {
        chunk = '';
      } else if (ArrayBuffer.isView(chunk)) {
        if (!this.get('Content-Type')) {
          this.type('bin');
        }
      } else {
        return this.json(chunk);
      }
      break;
  }

  // determine if ETag should be generated
  var etagFn = app.get('etag fn')
  var generateETag = !this.get('ETag') && typeof etagFn === 'function'

  // populate Content-Length
  var len
Repository: expressjs/express
File: test/res.type.js (JavaScript)

Code before:
    it('should default to application/octet-stream', function(done){
      var app = express();

      app.use(function(req, res){
        res.type('rawr').end('var name = "tj";');
      });

      request(app)
      .get('/')
      .expect('Content-Type', 'application/octet-stream', done);
    })

    it('should set the Content-Type with type/subtype', function(done){
      var app = express();

      app.use(function(req, res){
        res.type('application/vnd.amazon.ebook')
          .end('var name = "tj";');
      });

      request(app)
      .get('/')
      .expect('Content-Type', 'application/vnd.amazon.ebook', done);
    })
    describe('edge cases', function(){
      it('should handle empty string gracefully', function(done){
        var app = express();

        app.use(function(req, res){
          res.type('').end('test');
        });

        request(app)
        .get('/')
        .expect('Content-Type', 'application/octet-stream')
        .end(done);
      })

      it('should handle file extension with dots', function(done){
        var app = express();

        app.use(function(req, res){
          res.type('.json').end('{"test": true}');
        });

        request(app)
        .get('/')
        .expect('Content-Type', 'application/json; charset=utf-8')
        .end(done);
      })


Review comment (bug):
```suggestion
+
+     describe('edge cases', function(){
```

Adding a new line here would be good for code flow protection, the remaining tests looks good to me.

Code after:
    it('should default to application/octet-stream', function(done){
      var app = express();

      app.use(function(req, res){
        res.type('rawr').end('var name = "tj";');
      });

      request(app)
      .get('/')
      .expect('Content-Type', 'application/octet-stream', done);
    })

    it('should set the Content-Type with type/subtype', function(done){
      var app = express();

      app.use(function(req, res){
        res.type('application/vnd.amazon.ebook')
          .end('var name = "tj";');
      });

      request(app)
      .get('/')
      .expect('Content-Type', 'application/vnd.amazon.ebook', done);
    })

    describe('edge cases', function(){
      it('should handle empty string gracefully', function(done){
        var app = express();

        app.use(function(req, res){
          res.type('').end('test');
        });

        request(app)
        .get('/')
        .expect('Content-Type', 'application/octet-stream')
        .end(done);
      })

      it('should handle file extension with dots', function(done){
        var app = express();

        app.use(function(req, res){
          res.type('.json').end('{"test": true}');
        });

        request(app)
        .get('/')
        .expect('Content-Type', 'application/json; charset=utf-8')
        .end(done);
      })
Repository: firebase/firebase-ios-sdk
File: scripts/add_copyright.sh (Shell)

Code before:
#!/bin/bash

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -u

# Check if git is available.
if ! command -v git &> /dev/null; then
    echo "git command could not be found."
    exit 1
fi

# Move to the root of the repository to ensure paths are correct.
cd "$(git rev-parse --show-toplevel)"

# Define the base branch (defaulting to main).
BASE_BRANCH=${1:-main}

# Check if BASE_BRANCH exists.
if ! git rev-parse --verify "$BASE_BRANCH" >/dev/null 2>&1; then
    # Try origin/main if main doesn't exist locally
    if git rev-parse --verify "origin/$BASE_BRANCH" >/dev/null 2>&1; then
        BASE_BRANCH="origin/$BASE_BRANCH"
    else
        echo "Base branch '$BASE_BRANCH' not found. Please provide a valid branch name as an argument."
        exit 1
    fi
fi

echo "Checking for new files against $BASE_BRANCH..."


Review comment (suggestion):
optional: add support for documenting help command

```suggestion

if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
  echo "Usage: $0 [BASE_BRANCH]"
  echo ""
  echo "Finds newly added files compared to BASE_BRANCH (defaults to 'main')"
  echo "and automatically prepends or updates the Google copyright header."
  exit 0
fi

```

Code after:
#!/bin/bash

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -u

# Check if git is available.
if ! command -v git &> /dev/null; then
    echo "git command could not be found."
    exit 1
fi

# Move to the root of the repository to ensure paths are correct.
cd "$(git rev-parse --show-toplevel)" || exit 1

# Define the base branch (defaulting to main).
BASE_BRANCH=${1:-main}

# Check if BASE_BRANCH exists.
if ! git rev-parse --verify "$BASE_BRANCH" >/dev/null 2>&1; then
    # Try origin/main if main doesn't exist locally
    if git rev-parse --verify "origin/$BASE_BRANCH" >/dev/null 2>&1; then
        BASE_BRANCH="origin/$BASE_BRANCH"
    else
        echo "Base branch '$BASE_BRANCH' not found. Please provide a valid branch name as an argument."
        exit 1
    fi
fi

echo "Checking for new files against $BASE_BRANCH..."
Repository: gchq/CyberChef
File: src/core/config/OperationConfig.js (JavaScript)

Code before:
        ]
    },
    "To Kebab case": {
        description: [
            "Converts the input string to kebab case.",
            "<br><br>",
            "Kebab case is all lower case with dashes as word boundaries.",
            "<br><br>",
            "e.g. this-is-kebab-case",
            "<br><br>",
            "'Attempt to be context aware' will make the operation attempt to nicely transform variable and function names.",
        ].join("\n"),
        run: Code.runToKebabCase,
        inputType: "string",
        outputType: "string",
        args: [
            {
                name: "Attempt to be context aware",
                type: "boolean",
                value: false,
            },
        ]
    },
    "Extract EXIF": {
        description: [
        ].join("\n"),
        run: Image.runEXIF,
        inputType: "byteArray",
        outputType: "string",
        args: [
        ],
    },
};

export default OperationConfig;


Review comment (refactor):
Add something useful here explaining what EXIF data is and which file formats might contain it. Remember that the description is checked when people use the search utility, so I usually try to include words here that people might search for when trying to find this operation.

Code after:
        ]
    },
    "To Kebab case": {
        description: [
            "Converts the input string to kebab case.",
            "<br><br>",
            "Kebab case is all lower case with dashes as word boundaries.",
            "<br><br>",
            "e.g. this-is-kebab-case",
            "<br><br>",
            "'Attempt to be context aware' will make the operation attempt to nicely transform variable and function names.",
        ].join("\n"),
        run: Code.runToKebabCase,
        inputType: "string",
        outputType: "string",
        args: [
            {
                name: "Attempt to be context aware",
                type: "boolean",
                value: false,
            },
        ]
    },
    "Extract EXIF": {
        description: [
            "Extracts EXIF data from an image.",
            "<br><br>",
            "EXIF data is metadata embedded in images (JPEG, JPG, TIFF) and audio files.",
            "<br><br>",
            "EXIF data from photos usually contains information about the image file itself as well as the device used to create it.",
        ].join("\n"),
        run: Image.runEXIF,
        inputType: "byteArray",
        outputType: "string",
        args: [
        ],
    },
};

export default OperationConfig;