Skip to content

Instantly share code, notes, and snippets.

View JackySu's full-sized avatar
🦄
dream

iulx0 JackySu

🦄
dream
View GitHub Profile
@codsane
codsane / commitCount.py
Last active February 6, 2023 12:11 — forked from 0penBrain/commitCount.sh
The simplest way to get commit count of a GitHub repository through the API
import requests
import re
def commitCount(u, r):
return re.search('\d+$', requests.get('https://api.github.com/repos/{}/{}/commits?per_page=1'.format(u, r)).links['last']['url']).group()
def latestCommitInfo(u, r):
""" Get info about the latest commit of a GitHub repo """
response = requests.get('https://api.github.com/repos/{}/{}/commits?per_page=1'.format(u, r))
commit = response.json()[0]; commit['number'] = re.search('\d+$', response.links['last']['url']).group()
@abel0b
abel0b / install-linux-perf-on-wsl2.sh
Last active July 7, 2024 17:24
Install perf on WSL 2
apt install flex bison
git clone https://github.com/microsoft/WSL2-Linux-Kernel --depth 1
cd WSL2-Linux-Kernel/tools/perf
make -j8
sudo cp perf /usr/local/bin
@0penBrain
0penBrain / commitCount.sh
Last active July 6, 2024 13:46
The simplest way to get commit count of a GitHub repository through the API
curl -I -k "https://api.github.com/repos/:owner/:repo/commits?per_page=1" | sed -n '/^[Ll]ink:/ s/.*"next".*page=\([0-9]*\).*"last".*/\1/p'
### And that's all !
# I saw many fighting with finding first commit SHA or similar fancy thing.
# Here we just rely on the GH API, asking commits at 1 per page and parsing the last page number in the header of the reply (whose body only holds the last commit !)
# So this is robust and bandwidth efficient. :)
# If one want the commit count of a specific SHA, just use :
curl -I -k "https://api.github.com/repos/:owner/:repo/commits?per_page=1&sha=:sha" | sed -n '/^[Ll]ink:/ s/.*"next".*page=\([0-9]*\).*"last".*/\1/p'
@yershalom
yershalom / get_commit_count.py
Created December 17, 2017 13:19
Easy way to calculate commits count from the github api
import requests
base_url = 'https://api.github.com'
def get_all_commits_count(owner, repo, sha):
first_commit = get_first_commit(owner, repo)
compare_url = '{}/repos/{}/{}/compare/{}...{}'.format(base_url, owner, repo, first_commit, sha)
commit_req = requests.get(compare_url)