Skip to content

Instantly share code, notes, and snippets.

@ssajous
ssajous / backward.R
Last active June 4, 2019 01:46
Multiple Linear Regression in R - Automatic Backward Elimination
backwardElimination <- function(x, sl) {
numVars = length(x)
for (i in c(1:numVars)){
regressor = lm(formula = Profit ~ ., data = x)
maxVar = max(coef(summary(regressor))[c(2:numVars), "Pr(>|t|)"])
if (maxVar > sl){
j = which(coef(summary(regressor))[c(2:numVars), "Pr(>|t|)"] == maxVar)
x = x[, -j]
}
numVars = numVars - 1
@ssajous
ssajous / backward-p.py
Created June 4, 2019 01:12
Backward Elimination
import statsmodels.formula.api as sm
def backwardElimination(x, sl):
numVars = len(x[0])
for i in range(0, numVars):
regressor_OLS = sm.OLS(y, x).fit()
maxVar = max(regressor_OLS.pvalues).astype(float)
if maxVar > sl:
for j in range(0, numVars - i):
if (regressor_OLS.pvalues[j].astype(float) == maxVar):
x = np.delete(x, j, 1)
@ssajous
ssajous / konami-code.js
Last active December 16, 2017 06:11
ES6 module to handle the Konami code input in a browser.
const _code = "38384040373937396665";
export default class CheatCode {
code = '';
delay = 1500;
callbacks = [];
timeout = null;
constructor() {
@ssajous
ssajous / gist:470cfdbd30efcc17e229f54fb6a47470
Created February 14, 2017 21:20 — forked from yetanotherchris/gist:4746671
Unique identifiers: Base62
public static string Base62Random()
{
int random = _random.Next();
return Base62ToString(random);
}
private static string Base62ToString(long value)
{
// Divides the number by 64, so how many 64s are in
// 'value'. This number is stored in Y.
@ssajous
ssajous / TimeProvider.cs
Last active January 7, 2016 15:58
Time Provider Ambient Context for mockable date times
public abstract class TimeProvider
{
private static TimeProvider current;
static TimeProvider()
{
TimeProvider.current =
new DefaultTimeProvider();
}
public static TimeProvider Current

Abstraction Suggestions

Summary: use good/established messaging patterns like Enterprise Integration Patterns. Don't make up your own. Don't expose transport implementation details to your application.

Broker

As much as possible, I prefer to hide Rabbit's implementation details from my application. In .Net we have a Broker abstraction that can communicate through a lot of different transports (rabbit just happens to be our preferred one). The broker allows us to expose a very simple API which is basically:

  • publish
  • request
  • start/stop subscription
function requireHTTPS(req, res, next) {
if (!req.secure) {
//FYI this should work for local development as well
var domain = "https://" + req.get("host");
if (process.env["SSL_PORT"]) {
domain = domain.replace(/:\d+$/, "");
domain += ":" + process.env["SSL_PORT"];
}
return res.redirect(domain + req.url);
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Hooking up the middleware with the express app
// In app.js
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
var forceSSL = require('../middleware/ssl').force(config.hostname);
if ('production' == app.get('env')) {
app.use(forceSSL);
}
@ssajous
ssajous / md5.rb
Created December 6, 2014 20:59
Calculate the MD5 hash of a file
#!/usr/bin/ruby
require 'digest/md5'
if ARGV[0] && File.exists?(ARGV[0])
STORAGE_PATH = ARGV[0]
else
puts 'Fatal error: path not existent or not given.'
exit
end
@ssajous
ssajous / .gitconfig
Last active August 29, 2015 14:09 — forked from jvandyke/.gitconfig
# ~/.gitconfig
# Add this to your global git configuration file
# Change phpstorm to webstorm, if you use that.
# Diff and merge tool changes
# Run `git difftool <directory/file>...` or `git mergetool <directory/file>...`
[merge]
tool = phpstorm
[diff]
tool = phpstorm