Skip to content

Instantly share code, notes, and snippets.

View abegong's full-sized avatar

Abe Gong abegong

View GitHub Profile
@abegong
abegong / get_liked_posts.py
Created April 30, 2023 17:21
Download all posts that an actor has liked using the psychonaut implementation of the ATProtocol
"""
Example code to download all posts that an actor has Liked from BlueSky
Uses the psychonaut implementation of ATProtocol.
"""
import json
from typing import List
from psychonaut.client import get_simple_client_session
from psychonaut.client.cursors import collect_cursored
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import random
import names
# http://treyhunner.com/2013/02/random-name-generator/
import pandas as pd
k = 10
gender = [random.choice(['male', 'female']) for i in range(k)]
users = pd.DataFrame({
"""
watcher.py
A nifty little script for responsive coding ala Brackets, but in python
It watches a directory for file changes, then executes an aribtrary python script.
Imports and large data loads can be cached at setup so that the remaining code can execute very fast.
See more about intended use case here:
http://stackoverflow.com/questions/32997698/auto-run-a-python-script-without-reloading-dependencies
@abegong
abegong / traffic_scraper.py
Created March 28, 2014 21:11
Fetch current traffic conditions from http://traffic.calit2.net/bayarea/ and save them to a timestamped file.
"""
Fetch current traffic conditions from http://traffic.calit2.net/bayarea/ and save them to a timestamped file.
"""
import re
import json
import codecs
import datetime
import requests
from lxml import html
@abegong
abegong / gist:7608465
Last active July 25, 2018 00:44
Example of regex-based tornado handler. (Doesn't actually work, but you get the idea.) NB: the database here is mongo, not SQL
class OpenTemplateHandler(tornado.web.RequestHandler):
def get_current_user(self):
return json.loads(self.get_secure_cookie("myapp-user"))
def get(self, path):
self.render(path+'.html')
class ApiHandler(BaseHandler):
@tornado.gen.coroutine
def get(self, path):
@abegong
abegong / gist:7381803
Created November 9, 2013 04:48
Parse chrome history and extract recent google searches
import sqlite3
import pandas
import re
#cp ~/Library/Application\ Support/Google/Chrome/Default/History ./History
sql = sqlite3.connect("History")
c = sql.cursor()
#List table creation commands to introspect schemas
@abegong
abegong / up_data_skyline_viz.py
Created September 24, 2013 03:31
Generate graphs from the last week of UP data.
import json
import pandas
import pylab as plt
#Load data
M = [json.loads(l) for l in file("data/snapshots.jl", 'r').readlines()]
#Day step graph
D = pandas.DataFrame(M[2]["data"])
@abegong
abegong / get_up_data.py
Created September 24, 2013 03:25
Retrieve the last 10 days of UP data from the jawbone nudge API
import requests
import json
import pandas
import pylab as plt
import auth
# Get auth token
r = requests.post("https://jawbone.com/user/signin/login", {