Skip to content

Instantly share code, notes, and snippets.

View danemacaulay's full-sized avatar

Dane Macaulay danemacaulay

View GitHub Profile
@danemacaulay
danemacaulay / nltk_preprocessor.py
Created November 6, 2017 20:52
sci kit learn nltk preprocessor
import string
from numpy import array
from nltk.corpus import stopwords as sw
from nltk.corpus import wordnet as wn
from nltk import wordpunct_tokenize
from nltk import WordNetLemmatizer
from nltk import sent_tokenize
from nltk import pos_tag
from sklearn.feature_extraction.text import CountVectorizer
import numpy as np
import pandas as pd
import scipy as sp
posts = pd.read_csv('posts.csv')
# Create vectorizer for function to use
vectorizer = CountVectorizer(binary=False)
y = posts["score"].values.astype(np.float32)
@danemacaulay
danemacaulay / less-plugin.js
Last active February 24, 2017 17:15
custom less plugin. instead of compiling each less file and concatenating, first concatenate and then compile. much faster.
'use stric';
var fs = require('fs');
var less = require('less');
var path = require('path');
var async = require('async');
var _ = require('lodash');
function readLessFilesIntoString(lessFiles, callback) {
var initialText = '';
@danemacaulay
danemacaulay / element-selector.js
Last active March 15, 2020 10:33
get unique css selector by element
'use strict';
function attributeIterator(node, extractorFunction) {
var selector = '';
var attributes = node.attributes;
for (var i = 0; i < attributes.length; i++) {
var attr = attributes[i];
var attrSelector = extractorFunction(attr);
if (attrSelector) {
selector += attrSelector;
@danemacaulay
danemacaulay / unique-selector.js
Last active January 3, 2017 19:44
UniqueSelector
'use strict';
function attributeIterator(node, extractorFunction) {
var selector = '';
var attributes = node.attributes;
for (var i = 0; i < attributes.length; i++) {
var attr = attributes[i];
var attrSelector = extractorFunction(attr);
if (attrSelector) {
selector += attrSelector;
@danemacaulay
danemacaulay / shrink.js
Last active October 6, 2016 17:01
dirty hack to reduce element sizing
'use strict';
var _ = require('lodash');
function stripPx(val) {
return val.replace('px', '');
}
function addPx(val) {
return val + 'px';
(function() {
'use strict';
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
@danemacaulay
danemacaulay / README.md
Created October 15, 2015 01:15 — forked from mbostock/.block
Bar Chart
@danemacaulay
danemacaulay / d3.chart.js
Created October 12, 2015 15:23
d3.chart layer example
// define a new chart type: a circle chart
d3.chart("CircleChart", {
initialize: function() {
// create a layer of circles that will go into
// a new group element on the base of the chart
this.layer("circles", this.base.append("g"), {
// select the elements we wish to bind to and
// bind the data to them.
@failure-color: @chart-1;
@delinquency-color: @chart-2;
@paydex-color: @chart-3;
@industry-color: @chart-4;
@industry-lower-color: #45a6aa;
@industry-median-color: #99cc01;
@industry-upper-color: #ff8800;