Skip to content

Instantly share code, notes, and snippets.

View bclavie's full-sized avatar

Benjamin Clavié bclavie

View GitHub Profile
# Fetch some text content in two different categories
from wikipediaapi import Wikipedia
wiki = Wikipedia('RAGBot/0.0', 'en')
docs = [{"text": x,
"category": "person"}
for x in wiki.page('Hayao_Miyazaki').text.split('\n\n')]
docs += [{"text": x,
"category": "film"}
for x in wiki.page('Spirited_Away').text.split('\n\n')]
@bclavie
bclavie / day3.py
Last active December 3, 2021 15:45
AoC 2021 Day3
from collections import Counter
# Part 1
inputs = [x.strip() for x in open('inputs.txt', 'r').readlines()]
gamma_str = ''
epsilon_str = ''
for i in range(len(inputs[0])):
col_count = Counter([x[i] for x in inputs])
if col_count['1'] > col_count['0']:
# Please use the following encoding: utf-8, thanks!
import networkx as nx
''' Part 1'''
graph = nx.read_edgelist('./data/day6_input.txt', delimiter=')', create_using=nx.DiGraph)
orbit_count = sum(len(nx.ancestors(G=graph, source=node)) for node in graph.nodes)
print(orbit_count)
''' Part 2 '''
undir_graph = nx.read_edgelist('./data/day6_input.txt', delimiter=')', create_using=nx.Graph)
shortest = len(nx.shortest_path(undir_graph, source="YOU", target="SAN")) - 3
@bclavie
bclavie / Wipetweets.py
Last active April 17, 2016 21:25
Python 3.x script to wipe all tweets from a twitter account. Requires tweepy.
import tweepy
"""Consumer key&secret key from http://dev.twitter.com"""
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
def login(consumer_key, consumer_secret):
logon = tweepy.OAuthHandler(consumer_key, consumer_secret)
logonurl = logon.get_authorization_url()
"""Authenticate tweet deleter"""