Skip to content

Instantly share code, notes, and snippets.

View Nurou's full-sized avatar
🐼
Focusing

Joel Hassan Nurou

🐼
Focusing
View GitHub Profile
@Nurou
Nurou / npm-download-counts-for-pkg.js
Last active December 25, 2023 19:51
npm download counts for a package using npm stats. Hardcoded for 2023
const fs = require("fs");
async function getDownloadsPerDay(pkgName) {
// for the past year
const from = "2022-12-01";
const until = "2023-11-30";
try {
const res = await fetch(
`https://npm-stat.com/api/download-counts?package=${pkgName}&from=${from}&until=${until}`,
);
@Nurou
Nurou / npm-view-categorised-releases-for-pgk.js
Last active December 25, 2023 13:45
Fetches, categories and CSV formats release data for npm packages. Skips < v1 and pre-releases (e.g. chores and betas).
const { promisify } = require("util");
const execAsync = promisify(require("child_process").exec);
const fs = require("fs");
async function getReleaseData(pkgName) {
const command = `npm view ${pkgName} time --json`;
try {
const { stdout } = await execAsync(command);
const data = JSON.parse(stdout);
@Nurou
Nurou / contributor-breakdown.sh
Last active January 1, 2024 16:02
Script to get the distribution of commits between top contributors in a Git repository.
#!/bin/bash
# Run git shortlog to get the contributors and their commit counts
git shortlog -s -n > contributors.txt
# Calculate total commits and average commits per contributor
total_commits=$(awk '{s+=$1} END {print s}' contributors.txt)
num_contributors=$(wc -l < contributors.txt)
average_commits_per_contributor=$((total_commits / num_contributors))
@Nurou
Nurou / useReducerWithLocalStorage.ts
Created February 28, 2022 17:44
useReducerWithLocalStorage
// this is a TS & modified version of: https://gist.github.com/mattiaerre/8dbd2d8efca3f242c7085a9ce82ecbde
import * as React from 'react';
// from: https://usehooks.com/useLocalStorage
import { useLocalStorage } from './useLocalStorage';
export const useReducerWithLocalStorage = <S, A>(reducer: React.Reducer<S, A>, initializerArg: S, key: string) => {
const [localStorageState, setLocalStorageState] = useLocalStorage(key, initializerArg);
return React.useReducer(