tools_source
Data license: All Rights Reserved · Data source: krisyotam.com · About: Kris Yotam
2 rows where tool_id = 2
This data as json, CSV (advanced)
| id ▼ | tool_id | filename | language | content |
|---|---|---|---|---|
| 13 | entropy 2 | entropy.c | c | /* entropy — calculate shannon entropy of input */ #include <math.h> #include <stdio.h> int main(int argc, char *argv[]) { FILE *fp; unsigned long freq[256] = {0}; unsigned long total = 0; int c; double entropy = 0.0; fp = (argc > 1) ? fopen(argv[1], "rb") : stdin; if (!fp) { perror(argv[1]); return 1; } while ((c = fgetc(fp)) != EOF) { freq[c]++; total++; } if (fp != stdin) fclose(fp); if (total == 0) { printf("0.000000\n"); return 0; } for (int i = 0; i < 256; i++) { if (freq[i] == 0) continue; double p = (double)freq[i] / total; entropy -= p * log2(p); } printf("%.6f\n", entropy); return 0; } |
| 14 | entropy 2 | entropy.py | py | #!/usr/bin/env python3 """entropy — calculate shannon entropy of input""" import math import sys from collections import Counter def entropy(data: bytes) -> float: if not data: return 0.0 counts = Counter(data) total = len(data) return -sum((c / total) * math.log2(c / total) for c in counts.values()) def main(): if len(sys.argv) > 1: with open(sys.argv[1], "rb") as f: data = f.read() else: data = sys.stdin.buffer.read() print(f"{entropy(data):.6f}") if __name__ == "__main__": main() |
Advanced export
JSON shape: default, array, newline-delimited, object
CREATE TABLE tools_source (id INTEGER PRIMARY KEY AUTOINCREMENT, tool_id INTEGER NOT NULL, filename TEXT NOT NULL, language TEXT NOT NULL, content TEXT NOT NULL, FOREIGN KEY (tool_id) REFERENCES tools(id) ON DELETE CASCADE, UNIQUE(tool_id, language));