Skip to content

Instantly share code, notes, and snippets.

View normalhuman's full-sized avatar

Normal Human normalhuman

View GitHub Profile
@normalhuman
normalhuman / svdtrunc.m
Created December 4, 2015 02:27
An example of using truncated SVD for latent semantic indexing
A = [0 1 1 0 1 1; 2 1 1 0 3 0; 0 0 0 4 0 2; 3 2 1 0 1 0; 0 0 1 1 0 3]
[U,D,V] = svd(A)
D2 = D.*(D>=5)
A2 = U*D2*V'
for j=1:6 disp(A2(1,j)/norm(A2(:,j))); end
import scipy.optimize as optimization
def u(x, a):
return numerical_integral(lambda t: x*a+t, 0, 1)[0]
print optimization.curve_fit(u, [1,2,3], [1,3,2], [1])
@normalhuman
normalhuman / spelling.js
Created September 24, 2016 23:23
spelling.js
b=document.querySelector('.wmd-input.processed');
if (b) {
a=b.value;
a=a.replace(/\bi(?=\s|\')/g,'I');
a=a.replace(/\b[Ii]m\b/g,'I\'m');
a=a.replace(/\b[Ii]ve\b/g,'I\'ve');
a=a.replace(/\b(ca|did|do|does|has|is|was|were|wo)nt\b/gi,'$1n\'t');
a=a.replace(/\b(w|t)hats\b/gi,'$1hat\'s');
a=a.replace(/\b(c|w|sh)ouldnt\b/gi,'$1ouldn\'t');
a=a.replace(/\b(t)heres\b/gi,'$1here\'s');
@normalhuman
normalhuman / flags.py
Created January 10, 2017 04:55
Scraping a user's helpful flag counts network-wide. Python 3
import re
import urllib.request
from bs4 import BeautifulSoup
from operator import itemgetter
from time import sleep
account_id = 'YOUR ACCOUNT ID HERE'
network_profile = 'http://stackexchange.com/users/' + account_id + '?tab=accounts'
with urllib.request.urlopen(network_profile) as response:
@normalhuman
normalhuman / notifications.js
Created April 3, 2018 19:36
The number of unread notifications for a user with given network id
w = new WebSocket("wss://qa.sockets.stackexchange.com/");
w.onmessage = function(e) {
d = JSON.parse(e.data).data;
console.log(d);
if (d == "hb") {
w.send("hb");
}
};
w.onopen = function() {
w.send("4606062-topbar");
@normalhuman
normalhuman / site_connections.js
Created April 22, 2018 20:41
Sites that share a moderator
// https://stackexchange.com/about/moderators?by=users
JSON.stringify(Array.from(document.querySelectorAll('.mods-summary-list')).filter(e=>e.children.length>1).map(e=>Array.from(e.children).map(x=>x.hostname.split('.')[0])))