Skip to content

Instantly share code, notes, and snippets.

#!/bin/python
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlencode, parse_qs
def get_endpoints(url):
r = requests.get(url)
soup = BeautifulSoup(r.text)
@kylewm
kylewm / tld-regex.txt
Created January 28, 2016 22:00
Regex matching all TLDs
(?:a(?:a(?:a|rp)|b(?:b(?:ott)?|ogado)|c(?:ademy|c(?:enture|ountant(?:s)?)|o|t(?:ive|or))?|d(?:ac|s|ult)?|e(?:g|ro)?|f(?:l)?|g(?:ency)?|i(?:g|r(?:force|tel))?|l(?:i(?:baba|pay)|lfinanz|sace)?|m(?:ica|sterdam)?|n(?:alytics|droid)|o|p(?:artments|p(?:le)?)|q(?:uarelle)?|r(?:amco|chi|my|pa|te)?|s(?:ia|sociates)?|t(?:torney)?|u(?:ction|di(?:o)?|t(?:hor|o(?:s)?))?|w|x(?:a)?|z(?:ure)?)|b(?:a(?:idu|n(?:d|k)|r(?:c(?:elona|lay(?:card|s))|gains)?|uhaus|yern)?|b(?:c|va)?|cn|d|e(?:ats|er|ntley|rlin|st|t)?|f|g|h(?:arti)?|i(?:ble|d|ke|ng(?:o)?|o|z)?|j|l(?:ack(?:friday)?|oomberg|ue)|m(?:s|w)?|n(?:l|pparibas)?|o(?:ats|ehringer|m|nd|o(?:k|ts)?|s(?:ch|tik)|t|utique)?|r(?:adesco|idgestone|o(?:adway|ker|ther)|ussels)?|s|t|u(?:dapest|gatti|ild(?:ers)?|siness|y|zz)|v|w|y|z(?:h)?)|c(?:a(?:b|fe|l(?:l)?|m(?:era|p)|n(?:cerresearch|on)|p(?:etown|ital)|r(?:avan|ds|e(?:er(?:s)?)?|s|tier)?|s(?:a|h|ino)|t(?:ering)?)?|b(?:a|n)|c|d|e(?:b|nter|o|rn)|f(?:a|d)?|g|h(?:a(?:n(?:el|nel)|t)|eap|loe|r(?:istmas|ome)|urch)?|i(?:priani|rcle|sco|t(?:ic|y(?
>>> from bs4 import BeautifulSoup
>>> import requests
>>> soup = BeautifulSoup(requests.get('https://snarfed.org/2015-04-18_kyle-mahan-checked-in-to-nourse-theatre').text)
>>> soup.body.div.find_all()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/srv/www/kylewm.com/redwind/venv/lib/python3.4/site-packages/bs4/element.py", line 1180, in find_all
return self._find_all(name, attrs, text, limit, generator, **kwargs)
File "/srv/www/kylewm.com/redwind/venv/lib/python3.4/site-packages/bs4/element.py", line 491, in _find_all
return ResultSet(strainer, result)
@kylewm
kylewm / reply.js
Created April 9, 2015 21:48
Tweet-aware reply bookmarklet
javascript:
(function(){
var url=window.location;
if(url.hostname=='twitter.com'&&url.pathname=='/'){
var openedTweet=document.querySelector('.opened-tweet');
if(openedTweet&&openedTweet.dataset.permalinkPath){
url='https://twitter.com'+openedTweet.dataset.permalinkPath;
}
}
window.open('https://kylewm.com/new/reply?url='+url,'_blank')
@kylewm
kylewm / gist:451c59261e3a749b0536
Last active August 29, 2015 14:17
Nginx configuration for Websockets
location /_updates {
proxy_pass http://localhost:8077;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400s;
}
@kylewm
kylewm / bridgy-so-draft.md
Last active August 29, 2015 14:14
bridgy stackoverflow question

Facebook Graph API: Find graph object from post URL

Given the URL of a public Facebook post, how can one find the post object in the FB Graph API?

We would like to be able to comment on or like a post via the v2.x Graph API, given the post's URL. Doing so requires the post's object ID, which we can make some educated guesses about, but accessing the actual object through the API has proven unreliable (works for some posts but not others).

@kylewm
kylewm / nginx-configuration
Created December 20, 2014 18:46
redwind-pilbox-setup
proxy_cache_path /srv/www/kylewm.com/cache keys_zone=one:10m max_size=500m;
...
server {
listen 443 ssl;
server_name kylewm.com;
...
@kylewm
kylewm / known-nginx-config
Last active April 19, 2017 09:19
my Known configuration for nginx
server {
listen 80;
root /home/vagrant/idno;
index index.php;
server_name vagrant.dev;
location ~ (\.ini|known.php)$ {
deny all;
}
@kylewm
kylewm / indie-config.js
Last active August 29, 2015 14:07
Loads indie-config and if available, apply handlers to <indie-action> tags
// Lazy-create and return an indie-config load promise
// The promise will be resolved with a config once the indie-config has been loaded
var loadIndieConfig = function () {
// Create the Promise to return
var loadPromise = new Promise(function (resolve) {
// Parse the incoming messages
var parseIndieConfig = function (message) {

Keybase proof

I hereby claim:

  • I am kylewm on github.
  • I am kylewm (https://keybase.io/kylewm) on keybase.
  • I have a public key whose fingerprint is D718 74E3 40FB 85B1 21BE 04E6 03AA A9DA C3F7 73CB

To claim this, I am signing this object: