Skip to content

Instantly share code, notes, and snippets.

const ml = require('ml-regression');
const csv = require('csvtojson');
const SLR = ml.SLR; // Simple Linear Regression
const csvFilePath = 'advertising.csv'; // Data
let csvData = [], // parsed Data
X = [], // Input
y = []; // Output
let regressionModel;
@Morganjackson
Morganjackson / script.py
Created June 21, 2018 23:07
Machine learning script
import csv
import functools
import os.path
import numpy
from sqlalchemy import create_engine
import pandas
from sklearn_pandas import DataFrameMapper
import sklearn.preprocessing
from sklearn.pipeline import Pipeline
describe Simulator do
let(:table) { Table.new(5, 5) }
let(:simulator) { described_class.new(table) }
it "places the robot onto a valid position" do
simulator.place(0, 0, "NORTH")
expect(simulator.robot).to be_a(Robot)
end
it "places the robot onto a invalid position" do
const createAdSet = async (fbCampaignId, campaign) => {
try {
const data = {
[AdSet.Fields.campaign_id]: fbCampaignId,
[AdSet.Fields.name]: `${campaign.name} Ad Set`,
[AdSet.Fields.optimization_goal]: 'BRAND_AWARENESS',
[AdSet.Fields.billing_event]: 'IMPRESSIONS',
[AdSet.Fields.is_autobid]: true,
// [AdSet.Fields.bid_amount]: 2, // TODO: Write a conversion method to calculate budget based on end date of campaign.
@Morganjackson
Morganjackson / actionTypeBuilder.js
Created May 17, 2017 09:39 — forked from smeijer/actionTypeBuilder.js
React Redux Meteor middlewares
export function actionTypeBuilder(prefix) {
return {
type: actionType => `${prefix}/${actionType}`,
loading: actionType => `${actionType}/loading`,
ready: actionType => `${actionType}/ready`,
stopped: actionType => `${actionType}/stopped`,
changed: actionType => `${actionType}/changed`,
error: actionType => `${actionType}/error`,
success: actionType => `${actionType}/success`
};
@Morganjackson
Morganjackson / actionTypeBuilder.js
Created May 17, 2017 09:39 — forked from dbismut/actionTypeBuilder.js
React Redux Meteor middlewares
export function actionTypeBuilder(prefix) {
return {
type: actionType => `${prefix}/${actionType}`,
loading: actionType => `${actionType}/loading`,
ready: actionType => `${actionType}/ready`,
stopped: actionType => `${actionType}/stopped`,
changed: actionType => `${actionType}/changed`,
error: actionType => `${actionType}/error`,
success: actionType => `${actionType}/success`
};
// meteor algorithm to check if this is a meteor serving http request or not
function IsAppUrl(req) {
var url = req.url;
if(url === '/favicon.ico' || url === '/robots.txt') {
return false;
}
// NOTE: app.manifest is not a web standard like favicon.ico and
// robots.txt. It is a file name we have chosen to use for HTML5
// appcache URLs. It is included here to prevent using an appcache
export function setTextColor(color) {
const rgb = convertHexToRgb(color)
const gamma = 2.2
const luminosity =
0.2126 * Math.pow(splitRgb(rgb).r, gamma) +
0.7152 * Math.pow(splitRgb(rgb).g, gamma) +
0.0722 * Math.pow(splitRgb(rgb).b, gamma)
if (luminosity < 0.6) return '#FFFFFF'
return '#282828'
}
@Morganjackson
Morganjackson / App.js
Created March 29, 2017 21:20 — forked from Sivli-Embir/App.js
A drop in solution to getting dynamic import React components in Meteor 1.5
import React from 'react';
import AsyncComponent from './AsyncComponent'
// call this.getAsyncComponent(path) to get a default export.
// call this.getAsyncComponent(path, specifier) to get a non-default export.
class App extends AsyncComponent {
render() {
let view;
export function convertHexToRgba(originalHex, opacity) {
const hex = originalHex.replace('#', '')
const r = parseInt(hex.substring(0, 2), 16)
const g = parseInt(hex.substring(2, 4), 16)
const b = parseInt(hex.substring(4, 6), 16)
const rgba = `rgba(${r}, ${g}, ${b}, ${opacity})`
return rgba
}
export function convertHexToRgb(originalHex) {