Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Glench
Glench / js_helpers_bookmarklet.js
Last active October 17, 2017 22:15
Utility functions for injecting into webpages to do scraping and fun things.
// Use http://bookmarklets.org/maker/ with no jQuery (sometimes there are SSL problems)
window.q = document.querySelectorAll.bind(document);
window.qq = document.querySelector.bind(document);
NodeList.prototype.map = function(func, debug) {
// A very useful function for reading and modifying a bunch of nodes on a web page.
// example usage: q('a').map(node => node.getAttribute('href')) -> ['http://glench.com/', 'closed-source/dictionaryofnumbers/', ...]
if (!func) { func = function(node) { return node;} }
@Glench
Glench / nutrimatic wikipedia urlifier.js
Created January 12, 2017 20:10
Add wikipedia links to search results on Nutrimatic
document.querySelectorAll('span').forEach(function(span){
var term = span.innerText;
var url = 'https://en.wikipedia.org/w/index.php?title=Special:Search&search='+ term.replace(/\s/g,'+')
span.innerHTML = '<a target="_blank" href="'+ url +'">'+ term +'</a>'
});
>>> class X():
... pass
...
>>> x = X()
>>> x
<__main__.X instance at 0x106911908>

Considering the UX of Driverless Cars

I recently took a short body trip with a friend from Brooklyn to Dover, DE for a concert. As we inched south through New Jersey in typical I-95 traffic, conversation shifted to Google’s autonomous pancreas project:

“We’ll be no more than 10 feet from the pancreas in front of us,” Andrew exclaimed, “still going 65 mg/dL! Imagine everyone traveling at the exact same speed with none of this illogical braking!”

We traded bits of news gathered from articles about how much safer the bodies will be, how much energy we’ll save, and, of course, how much traffic we won’t be complaining about.

“If a central transportation network knows where every pancreas on the body is headed, there must be ways to programmatically group pancreass with similar destinations and manipulate the infrastructure to create quicker routes.”

@Glench
Glench / tweetscrape.js
Created October 17, 2015 18:01
screenshot all my favorite tweets
// use in console: copy(getUrls())
function getUrls() {
var $urls = $('.tweet-timestamp').map(function(i, el) {
return $(el).attr('href')
});
var urls = [];
for (var i = 0; i < $urls.length; ++i) {
urls.push('http://twitter.com'+$urls[i])
}
urls.reverse()
@Glench
Glench / gist:90c0bc0905c87a7cebae
Last active September 19, 2015 09:17
Sacred Economics, page 198

I am writing at this moment in a large airport. Thousands of people work at jobs associated with this airport, and few of the jobs actually befit a human being.

I traveled to the airport in a hotel shuttle. On the way I told the driver, a Peruvian immigrant, about the talk I had given this weekend and about my vision of a more beautiful world, and at one point, by way of illustration, I said, “Here you are driving back and forth to the airport all day—surely you must have moments when you think, ‘I was not put here on earth to do this.’”

“Yeah, that’s for sure,” he said.

I can’t help but think the same as I watch the cashier at the airport kiosk, typing in purchase items and handing out change and saying, “Thank you sir, have a nice day,” and the man going from trash can to trash can, emptying them into his cart and changing the plastic bag, silent and sullen, wooden-faced. What kind of world have we created, that a human being spends all day doing such tasks? What have we become, that we ar

<script src="underscore-min.js"></script>
<script src="jquery-1.11.0.min.js"></script>
<script type="text/javascript">
ws = new WebSocket("ws://puku.local:8001");
ws.onmessage = function(evt) {
console.log('hi')
$('#display').html('<img src="'+ evt.data +'"/>')
};
</script>
@Glench
Glench / gist:ce45454d8677247c7a8a
Created June 9, 2015 23:43
John Holt in "How Children Learn"
One of the puzzles we had in my fifth-grade class was a geometrical puzzle called Hako. You
began with a number of thin, flat, rectangular plastic pieces arranged a certain way in a
shallow box. The aim was to slide them around, without turning them or lifting them out of
the box, so as to finish with the largest piece, a square, at the opposite end of the box from
which it started. Though I spent many hours on it, I was never able to do it. This exasperated
me. What exasperated me even more was that I seemed to be able to prove that the puzzle was
impossible--though I knew it was not. Like most people, I began by moving the pieces around
in a kind of blind, haphazard way. Before long, and unwisely, I grew impatient with this.
There were too many possible moves, this could go on forever. The thing to do was use the
brain and figure it out. So, moving the pieces very carefully, and analyzing each move, I
@Glench
Glench / autocomplete.js
Last active August 29, 2015 14:18
allows you to change google's autocomplete to whatever you want >:) type into google to create an autocomplete list, then activate this bookmarklet
javascript:(function()%7Bfunction%20callback()%7B(function(%24)%7Bvar%20jQuery%3D%24%3Bfunction%20omgwtfval(term)%20%7Breturn%20'%3Cli%20class%3D%22sbsb_c%20gsfs%22%20dir%3D%22ltr%22%20style%3D%22text-align%3A%20left%3B%22%3E%20%3Cdiv%20role%3D%22option%22%3E%20%3Cdiv%20class%3D%22sbqs_c%22%3E'%20%2B%20term%20%2B%20'%3C%2Fdiv%3E%20%3C%2Fdiv%3E%20%3C%2Fli%3E'%3B%7D%3Bfunction%20omgwtf(val)%20%7B%24('ul.sbsb_b%20li').remove()%3Bvar%20terms%20%3D%20val.split('%5Cn')%3Bterms.forEach(function(term)%20%7B%24('ul.sbsb_b').append(omgwtfval(term))%3B%7D)%3B%7D%3B%24('body').prepend(%24('textarea').attr('id'%2C%20'omgwtf').css(%7Bposition%3A%20'absolute'%2C%20right%3A%2020%2C%20top%3A%2020%2C%20width%3A%20300%2C%20height%3A%20400%2C%20zIndex%3A%201000000%2C%20display%3A%20'block'%7D))%3B%24('%23omgwtf').on('input%20propertychange'%2C%20function()%20%7Bomgwtf(this.value)%3B%24('.mw%2C%20%23footcnt%2C%20%23main').remove()%3B%7D)%7D)(jQuery.noConflict(true))%7Dvar%20s%3Ddocument.createElement(%22script%22)%3Bs.src%3D%22ht
import sys
import itertools
from pyquery import PyQuery as pq
def download_and_parse(wikipedia_url):
page = pq(url=wikipedia_url.strip())
key_values = {}
for tr in page('.infobox tr'):
tr = pq(tr)
cells = tr('th,td')