Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

xuwang xuwangyin

🎯
Focusing
View GitHub Profile
View affinity_propagation_clustering.py
# coding: utf-8
from sklearn.cluster import AffinityPropagation
from sklearn import metrics
from sklearn.datasets.samples_generator import make_blobs
import scipy
import scipy.stats
import numpy as np
from collections import Counter
View kl_similarity.py
import scipy
import numpy as np
from collections import Counter
# Kullback–Leibler divergence
# https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence
# http://scipy.github.io/devdocs/generated/scipy.stats.entropy.html
def kl(p, q):
# compute common elements
@xuwangyin
xuwangyin / render_guardian_json_files.php
Created Apr 25, 2016
find my_guardian_json_file_dir -name "*.json" > guardian_json_files; php render_guardian_json_files.php guardian_json_files > guardian_articles.html; open guardian_articles.html;
View render_guardian_json_files.php
<?php
error_reporting(E_ERROR | E_PARSE);
function get_content($body) {
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
$content = "";
if ($doc->loadXML($body)) {
foreach ($doc->getElementsByTagName("body") as $t) {
foreach ($t->getElementsByTagName("paragraph") as $p) {
$content = $content . '<p>' . $p->textContent . '</p>';
@xuwangyin
xuwangyin / render_json_files.php
Created Apr 20, 2016
find my_json_file_dir -name "*.json" > json_files; php render_json_files.php json_files > articles.html; open articles.html;
View render_json_files.php
<?php
error_reporting(E_ERROR | E_PARSE);
function get_content($body) {
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
if (!$doc->loadXML($body))
return $body;
$content = "";
foreach ($doc->getElementsByTagName("body") as $t) {
foreach ($t->getElementsByTagName("paragraph") as $p) {