Skip to content

Instantly share code, notes, and snippets.

View primaryobjects's full-sized avatar

Kory Becker primaryobjects

View GitHub Profile
@primaryobjects
primaryobjects / interpolation.js
Created October 23, 2017 19:44
JavaScript string interpolation (strings with variables and transformation functions). See https://jsfiddle.net/eg278r0s/
function upper(strings, ...values) {
let result = '';
strings.forEach((string, i) => {
result += string + (values[i] ? values[i].toUpperCase() : '');
});
return result;
}
@primaryobjects
primaryobjects / learning-curve.R
Last active October 13, 2017 13:09
Plotting a learning curve from image recognition data.
library(caret)
library(reshape2)
dataTrain <- data.frame(x = trainData$x[1:30000,], y = trainData$y[1:30000])
dataTest <- data.frame(x = testData$x, y = testData$y)
# Train.
trainctrl <- trainControl(verboseIter = TRUE, number=5, repeats=1, method='repeatedcv')
results <- data.frame()
@primaryobjects
primaryobjects / perceptron.js
Last active October 5, 2022 00:37
Perceptron in JavaScript, a simple example. Neural network. See https://jsfiddle.net/qu960cc2/1/
function Perceptron(opts) {
if (!opts) opts = {}
var debug = 'debug' in opts ? opts.debug : false;
var weights = 'weights' in opts
? opts.weights.slice()
: []
var threshold = 'threshold' in opts
@primaryobjects
primaryobjects / which.js
Last active September 23, 2017 18:20
Which conditional would you write in JavaScript and why?
// A
if (isActive)
doIt();
// B
if (isActive) {
doIt();
}
// C
@primaryobjects
primaryobjects / mouse.gif
Last active June 27, 2022 18:24
View the mouse pointer position in Selenium Nightwatch. Execute this code when the page loads or in the javascript console. See https://stackoverflow.com/a/35867777
mouse.gif
@primaryobjects
primaryobjects / image-grayscale.png
Last active September 13, 2017 02:02
Read a PNG as a grayscale single-channel image. Converts from RGB to G (single channel color array of bytes 0-255).
image-grayscale.png
@primaryobjects
primaryobjects / circles.R
Last active September 11, 2017 17:47
# [2017-09-04] Challenge #330 [Easy] Surround the circles: Calculating the bounding rectangle for a group of circles, plotted on a graph in R. https://www.reddit.com/r/dailyprogrammer/comments/6y19v2/20170904_challenge_330_easy_surround_the_circles/
#
# [2017-09-04] Challenge #330 [Easy] Surround the circles
# https://www.reddit.com/r/dailyprogrammer/comments/6y19v2/20170904_challenge_330_easy_surround_the_circles/
#
# Demo at http://www.r-fiddle.org/#/fiddle?id=xNcJwO6x&version=2
#
# In this challenge, you will be given a set of circles, defined by their centers and radii. Your goal is to find the bounding rectangle which will contain all of the circles completely.
# Write a program that determines the vertices of the bounding rectangle with sides parallel to the axes.
#
# by Kory Becker
@primaryobjects
primaryobjects / heroku.md
Created August 27, 2017 23:22
Enabling/Disabling a Heroku App from the command-line.

Enabling/Disabling a Heroku App

Disabling a Heroku App

heroku ps:scale web=0 --app myAwesomeApp

Enabling a Heroku App

@primaryobjects
primaryobjects / 1-word2vec.R
Last active May 4, 2024 22:33
word2vec example in R. Natural language processing, NLP, word to vector, wordVector
###
### Example of using word2vec.
### Kory Becker, August 16, 2017
###
library(devtools)
library(httr)
library(tm)
set_config(
@primaryobjects
primaryobjects / github.R
Last active August 15, 2017 18:54
Installing a github package in RStudio while behind a proxy.
library(devtools)
library(httr)
# Set proxy.
set_config(
use_proxy(url="proxy.company.com", port=80),
)
# Disable SSL verify check.
set_config( config( ssl_verifypeer = 0L ) )