Skip to content

Instantly share code, notes, and snippets.

View cornhundred's full-sized avatar

Nicolas Fernandez cornhundred

View GitHub Profile
@urschrei
urschrei / horror.py
Created September 8, 2019 14:36 — forked from sbma44/horror.py
Lovecraft word pairs by rarity of vocab
# sample invocation:
# pdftotext -f 5 /tmp/The_Complete_Works_of_H.P._Lovecraft.pdf - | python3 horror.py | uniq > lovecraft_word_pairs_sorted.txt
import re
import sys
import nltk
import wordfreq
re_word = re.compile(r'[^\-\w]')
@cornhundred
cornhundred / custom.css
Last active August 29, 2015 14:24
d3 clustergram with zooming and searching
/* prevents horizontal scrolling */
html {
/*min-width: 1040px;*/
max-width: 100%;
overflow-x: hidden;
}
h1 {
font-size: 45px;
@urschrei
urschrei / hexgrid.py
Last active May 4, 2022 11:57
Python Hexgrid
import math
def calculate_polygons(startx, starty, endx, endy, radius):
"""
Calculate a grid of hexagon coordinates of the given radius
given lower-left and upper-right coordinates
Returns a list of lists containing 6 tuples of x, y point coordinates
These can be used to construct valid regular hexagonal polygons
@erogol
erogol / cluster.py
Created December 13, 2013 15:46
clustering with theano
import numpy as np
import numpy
import theano
import theano.tensor as T
from theano import function, config, shared, sandbox
from theano import ProfileMode
from sklearn import cluster, datasets
import matplotlib.pyplot as plt
def rsom(data, cluster_num, alpha, epochs = -1, batch = 1, verbose = False):
@mdml
mdml / README.md
Last active March 30, 2023 16:30
Dendrograms: Convert from Scipy to D3

A dendrogram is a common way to represent hierarchical data. For Python users, Scipy has a hierarchical clustering module that performs hierarchical clustering and outputs the results as dendrogram plots via matplotlib. When it's time to make a prettier, more customized, or web-version of the dendogram, however, it can be tricky to use Scipy's dendrogram to create a suitable visualization. My preferred method of visualizing data -- especially on the web -- is D3. This example includes a script to convert a Scipy dendrogram into JSON format used by D3's cluster method.

In the example, I cluster six genes by their expression values from two experiments. You can easily replace that data with your own, larger data set, to harness the power of both Scipy and D3 for analyzing hierarchical data. The D3 code I used to generate this example is straigh

@andrewgiessel
andrewgiessel / gist:5684769
Created May 31, 2013 12:52
fit a sigmoid curve, python, scipy
# good discussion here: http://stackoverflow.com/questions/4308168/sigmoidal-regression-with-scipy-numpy-python-etc
# curve_fit() example from here: http://permalink.gmane.org/gmane.comp.python.scientific.user/26238
# other sigmoid functions here: http://en.wikipedia.org/wiki/Sigmoid_function
import numpy as np
import pylab
from scipy.optimize import curve_fit
def sigmoid(x, x0, k):
y = 1 / (1 + np.exp(-k*(x-x0)))
@cpbotha
cpbotha / README.md
Last active January 10, 2017 00:49
d3.js breathing drop shadows

Look ma, those drop shadows are breathing!

Your eyes want you to believe that the blocks are hovering up and down, when in fact only the drop shadow is being translated out and in again.

Follow me on https://twitter.com/cpbotha for even more fun, or see my other d3 blocks: http://bl.ocks.org/cpbotha

@jjdelc
jjdelc / crayola.json
Created February 20, 2012 06:32
Crayola colors in JSON format
[
{
"hex": "#EFDECD",
"name": "Almond",
"rgb": "(239, 222, 205)"
},
{
"hex": "#CD9575",
"name": "Antique Brass",
"rgb": "(205, 149, 117)"