Skip to content

Instantly share code, notes, and snippets.

View edsu's full-sized avatar

Ed Summers edsu

View GitHub Profile
@edsu
edsu / t.ts
Last active December 8, 2021 15:52
t.ts:3:19 - error TS2532: Object is possibly 'undefined'.
import { min } from 'lodash';
const n: number = min([1,2,3]) + min([4,2,3]);
@edsu
edsu / gif
Last active October 21, 2021 18:29
A little shell script to put in your PATH if you forget the ffmpeg options to turn a video into an animated GIF.
#!/bin/sh
# Turn a video file into an animated GIF
USAGE="usage: gif video_file [gif_file]"
video_file=$1
if [ "$video_file" = "" ]; then
echo $USAGE
@edsu
edsu / checktests.py
Last active October 1, 2021 22:35
Who tests the test testers?
#!/usr/bin/env python3
import re
import sys
import pytest
import shutil
import pathlib
name = sys.argv[1]
import os
import requests_oauthlib
e = os.environ.get
client = requests_oauthlib.OAuth1Session(
client_key=e("CONSUMER_KEY"),
client_secret=e("CONSUMER_SECRET"),
resource_owner_key=e("ACCESS_TOKEN"),
resource_owner_secret=e("ACCESS_TOKEN_SECRET")
@edsu
edsu / twitter-political-labels.csv
Created September 16, 2021 18:02
Government labels in 71,684 tweets collected with a modified version of snscrape using the query 'covid19'
label tweets
China state-affiliated media 156
Iran state-affiliated media 21
Медиј који сарађује са владом Србија 9
China government official 8
Çin devletine bağlı medya 8
Thailand government organization 7
中国官方媒体 5
Russia state-affiliated media 4
Média affilié à un État, Chine 4
@edsu
edsu / labels.csv
Last active September 16, 2021 12:36
Government labels colllected from Twitter search results for "covid" using (an adapted) snscrape.
label tweets
China state-affiliated media 127
Iran state-affiliated media 21
Thailand government organization 7
Медиј који сарађује са владом Србија 6
Çin devletine bağlı medya 6
China government official 6
中国官方媒体 4
Média affilié à un État, Chine 4
Russia state-affiliated media 3
@edsu
edsu / extract.py
Last active November 17, 2023 18:06
Convert the outbox.json in a Mastodon account export to a CSV with columns published, to, and content.
#!/usr/bin/env python3
import csv
import json
data = json.load(open("outbox.json"))
out = csv.DictWriter(open("outbox.csv", "w"), ["published", "to", "content"])
out.writeheader()
start end day_count
2021-07-27T00:00:00.000Z 2021-07-28T00:00:00.000Z 7
2021-07-28T00:00:00.000Z 2021-07-29T00:00:00.000Z 8
2021-07-29T00:00:00.000Z 2021-07-30T00:00:00.000Z 11
2021-07-30T00:00:00.000Z 2021-07-31T00:00:00.000Z 11
2021-07-31T00:00:00.000Z 2021-08-01T00:00:00.000Z 8
2021-08-01T00:00:00.000Z 2021-08-02T00:00:00.000Z 8
2021-08-02T00:00:00.000Z 2021-08-03T00:00:00.000Z 10
2021-08-03T00:00:00.000Z 2021-08-04T00:00:00.000Z 10
2021-08-04T00:00:00.000Z 2021-08-05T00:00:00.000Z 9
#!/usr/bin/env python3
import internetarchive
ia = internetarchive.get_session()
print("ids,pages")
for result in ia.search_items('collection:mediahistory creator:National Association of Educational Broadcasters'):
ia_id = result['identifier']
start end hour_count
2021-06-17T23:16:56.000Z 2021-06-18T00:00:00.000Z 232
2021-06-18T00:00:00.000Z 2021-06-18T01:00:00.000Z 267
2021-06-18T01:00:00.000Z 2021-06-18T02:00:00.000Z 353
2021-06-18T02:00:00.000Z 2021-06-18T03:00:00.000Z 260
2021-06-18T03:00:00.000Z 2021-06-18T04:00:00.000Z 286
2021-06-18T04:00:00.000Z 2021-06-18T05:00:00.000Z 278
2021-06-18T05:00:00.000Z 2021-06-18T06:00:00.000Z 185
2021-06-18T06:00:00.000Z 2021-06-18T07:00:00.000Z 225
2021-06-18T07:00:00.000Z 2021-06-18T08:00:00.000Z 241