Skip to content

Instantly share code, notes, and snippets.

View rpgraham84's full-sized avatar

Robert Graham rpgraham84

View GitHub Profile
var Search = function (window) {
var data = {};
function getSearchResults (p) {
var params = {
// If no tokens are passed in, use the value of the search input.
tokens: document.querySelector('#id_q').value.split(' '),
// Facets are currently not tacked anywhere on the page.
selectedFacets: []
@rpgraham84
rpgraham84 / fb-friends-scraper.js
Created March 9, 2017 20:00
Facebook friends scraper
// Works as of 03/08/2017 - selectors may change on Facebook's end
// Useful for grabbing a list of friends and associated lists of their friends from a single fb user's "friends" page.
// I would have used FB's Graph API, but it doesn't provide any means of getting the same data.
// Must have a plugin in the browser to ignore X-Frame-Options header in order for pages to work within iframes.
// I'm using (https://chrome.google.com/webstore/detail/ignore-x-frame-headers/gleekbfjekiniecknbkamfmkohkpodhe) for Chrome.
// Saves output to json files which can later be assembled into a big json file or entered directly into a database.
// To run the script, get the aforementioned plugin, go to a fb user's page, click friends, then paste this in dev tools.
// There's a runaway memory problem somewhere, but rather than diagnose and fix it, I just restart the script when it crashes.
@rpgraham84
rpgraham84 / hnsort.es6
Last active March 21, 2018 00:27
Hacker News sort by best
'use strict';
// This let statement selects elements from the HTML document using a CSS selector.
// Specifically, we're making an Array of all table rows (each news listing is
// a table row in an html table). The css selector here says, find the 'tr' elements
// that are nested at any depth below a tbody which is nested at any depth below any
// element bearing the class 'itemlist' -- the dot in front of itemlist indicates
// we're talking about a CSS class, not an element.
// Look up css selectors and the document.querySelectorAll
// function for more about that.
#!/usr/bin/env python3.6
import os
import sys
import time
import string
import random
import requests
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
@rpgraham84
rpgraham84 / roman_numerals.py
Created August 11, 2018 18:15
Convert integers to roman and vice-versa
import re
numerals = {"M": 1000, "CM": 900, "D": 500, "CD": 400, "C": 100,
"XC": 90, "L": 50, "XL": 40, "X": 10, "IX": 9, "V": 5,
"IV": 4, "I": 1}
r = re.compile('|'.join(sorted(numerals.keys(), key=len, reverse=True)))
def to_roman(n, s=''):
@rpgraham84
rpgraham84 / best_trade.py
Last active August 28, 2018 19:13
Find best trade example
from random import randint
def best_trade(closes):
size = len(closes)
if size < 2:
return 'Input must contain at least 2 prices.'
best = (-1, 0, 0)
right = closes[-1]
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import division, print_function
from operator import add, sub
from itertools import cycle
from functools import reduce
"""
Fun little script for approximating pi. Inspired my Matt Parker's
#1 @ 55,885: 22x10
#2 @ 102,14: 23x14
#3 @ 539,327: 21x22
#4 @ 429,353: 14x25
#5 @ 232,934: 29x11
#6 @ 796,785: 17x18
#7 @ 508,96: 11x18
#8 @ 83,289: 28x23
#9 @ 291,46: 21x17
#10 @ 505,954: 23x15
#!/usr/bin/env bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the active virtualenv
# * the branch/status of the current git repository
# * the return value of the previous command
# * the fact you just came from Windows and are used to having newlines in
# your prompts.

Keybase proof

I hereby claim:

  • I am rpgraham84 on github.
  • I am robertpgraham (https://keybase.io/robertpgraham) on keybase.
  • I have a public key whose fingerprint is AB77 D012 8661 E1AE 02A7 5EE7 D78C 3C3A 4941 5609

To claim this, I am signing this object: