Skip to content

Instantly share code, notes, and snippets.

View ginixsan's full-sized avatar

Ginés Sanz Sanchis ginixsan

View GitHub Profile
import os
import re
import gzip
import hashlib
from tqdm import tqdm
from bs4 import BeautifulSoup, SoupStrainer
fnames = []
for fname in os.listdir('PubMed'):
if fname.endswith('.xml'):
@ginixsan
ginixsan / ImpactHunter.py
Created June 3, 2023 15:57 — forked from SemiQuant/ImpactHunter.py
Summarize the publication of a researcher, and calculate their IFs for first and last authorships in a data range
#!/bin/python
from Bio import Entrez
import subprocess
import ast
import statistics
def search_publications(author_name, start_year, end_year):
# Search PubMed for publications by the author within the specified date range
query = f'({author_name}[Author]) AND (Journal Article[Publication Type]) NOT (Clinical Trial[Publication Type]) NOT preprint[pt] NOT review[pt] AND ({start_year}:{end_year}[PDAT])'
handle = Entrez.esearch(db='pubmed', term=query)
record = Entrez.read(handle)
@ginixsan
ginixsan / search_biopython.py
Created June 3, 2023 15:57 — forked from bonzanini/search_biopython.py
Searching PubMed with Biopython
# This code uses Biopython to retrieve lists of articles from pubmed
# you need to install Biopython first.
# If you use Anaconda:
# conda install biopython
# If you use pip/venv:
# pip install biopython
# Full discussion:
@ginixsan
ginixsan / pubmed-publications.html
Created June 3, 2023 15:55 — forked from slowkow/pubmed-publications.html
Get an HTML list of PubMed publications
<!DOCTYPE html>
<body>
<!-- Copied directly from http://www.ephys.org/ by Damian J Williams -->
<input placeholder="Kamil Slowikowski" name="name"/>
<p id="demo"></p>
<script>
@ginixsan
ginixsan / arduino_byte_array_to_string.cpp
Created February 3, 2023 18:29 — forked from mischazip/arduino_byte_array_to_string.cpp
arduino convert string to/from byte array
void setup(void)
{
}
void loop(void)
{
byte byteArray[5];
strcpy((char *)byteArray,"0123"); //init byte array, index 5 = \0
String myString = String((char *)byteArray);
}
@ginixsan
ginixsan / nodejs_java_encrypt_decrypt_128.js
Created January 17, 2023 07:49 — forked from luizwbr/nodejs_java_encrypt_decrypt_128.js
Encrypt and Decrypt using 128 for Nodejs or Javascript that actually works
// None of the tutorals could help me, so I adapted a few codes.
// What I really want is make a full duplex way between NodeJS and Java, using encrypt/decrypt with AES 128 bit
// 1 - you must have to generate the key
openssl enc -aes-128-cbc -k secret -P -md sha1
// key examples:
// DCDD74627CD60252E35DFBA91A4556AA
// 2CB24CFDB3F2520A5809EB4851168162
// 468CA14CA44C82B8264F61D42E0E9FA1
@ginixsan
ginixsan / client.html
Created December 7, 2022 08:37 — forked from agrueneberg/client.html
HMAC-SHA256 example for verifying both the data integrity and the authentication of a request in Node.js and web browsers.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HMAC-SHA256 Example</title>
</head>
<body>
<script src="http://crypto.stanford.edu/sjcl/sjcl.js"></script>
<script>
var sharedSecret, query, signature, hmac, xhr;
@ginixsan
ginixsan / iBeaconCalculateDistance.js
Created October 26, 2022 17:39 — forked from JoostKiens/iBeaconCalculateDistance.js
iBeacon calculate distance in meters
// Based on http://stackoverflow.com/a/20434019
function calculateAccuracy(txPower, rssi) {
if (rssi === 0) {
return -1; // if we cannot determine accuracy, return -1.
}
var ratio = rssi * 1 / txPower;
if (ratio < 1.0) {
return Math.pow(ratio, 10);
@ginixsan
ginixsan / express.js
Created August 18, 2022 18:26 — forked from gabrielstuff/express.js
express + passport + session / req.session
/**
* Module dependencies.
*/
var express = require('express'),
mongoStore = require('connect-mongo')(express),
flash = require('connect-flash'),
viewHelpers = require('./middlewares/view'),
fs = require('fs'),
upload = require('jquery-file-upload-middleware');

Do not use forEach with async-await

TLDR: Use for...of instead of forEach in asynchronous code.

The problem

Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)

For example, the following forEach loop might not do what it appears to do: