Skip to content

Instantly share code, notes, and snippets.

View doron2402's full-sized avatar

Doron Segal doron2402

View GitHub Profile
@doron2402
doron2402 / tip.csv
Created October 26, 2017 18:35
Tip ~ WaiterAge, GroupSize, DinersAvergageAge, CostOfMeal, Country
WaiterAge GroupSize DinersAvgAge CostOfMeal Country Tip
19 2 25.5 120 USA 24
43 2 33 120 England 10.8
34 3 42 132 France 1.32
42 4 50 216 Israel 32.4
29 5 50 220 USA 39.6
27 6 43 606 England 12.12
32 7 63 546 England 49.14
34 8 55 712 Israel 71.2
37 3 43 336 France 10.08
@doron2402
doron2402 / top_vs_age.r
Created October 21, 2017 20:48
Tip VS Age - Linear regression model using R
# Predict how much tip will get per our clients age
# Using a simple linear regression model
dataset = read.csv('tip.csv')
library(caTools)
# choose random number for the see
set.seed(100)
# Split the dataset between test and train set
split = sample.split(dataset$Tip, SplitRatio = 2/3)
training_set = subset(dataset, split == TRUE)
@doron2402
doron2402 / linear_regression.py
Last active October 19, 2017 22:07
Simple tips prediction using linear regression
# Import python packages
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
# Load our dataset from a csv
dataset = pd.read_csv('tip.csv')
# Fetch the age column
age = dataset.iloc[:, :-1].values
@doron2402
doron2402 / preprocessing.r
Created October 17, 2017 21:51
Preprocessing data with R - filling missing values
# import the dataset
dataset = read.csv('Data.csv')
# missing values
dataset$Age = ifelse(is.na(dataset$Age),
ave(dataset$Age, FUN = function(x) mean(x, na.rm=TRUE)),
dataset$Age)
dataset$Salary = ifelse(is.na(dataset$Salary),
ave(dataset$Salary, FUN = function(x) mean(x, na.rm = TRUE)),
@doron2402
doron2402 / preprocessing.py
Last active October 17, 2017 21:41
filling missing value python
import pandas as pd
import sklearn as sk
# import the dataset
dataset = pd.read_csv(‘db.csv’)
# Load all columns into matrix but not the last ones
x = dataset.iloc[0:12,0:5].values
# Last column from the dataset
y = dataset.iloc[0:12,6].values
# Use the mean for fill missing data
imputer = sk.preprocessing.Imputer()
@doron2402
doron2402 / server_obj.js
Created August 10, 2017 16:51
hapi-plugin-pg - access plugin via server object
const Query = ‘select * from users’;
const pool = server.plugins[‘hapi - plugin - pg’].pg;
pool.query(Query, (err, res) => { 
if (err) {  //do something
 } 
pool.end(); // this is important 
 
return res;
});
@doron2402
doron2402 / index.js
Created August 10, 2017 16:48
Hapi.js with hapi-plugin-pg plugin
// index.js
use strict’;
const Hapi = require(‘hapi’);
const Joi = require(‘joi’);
const server = new Hapi.Server();
server.connection({
port: 3000,
host: ‘localhost’
@doron2402
doron2402 / sam.yaml
Created July 13, 2017 21:29
AWS Cloud Formation sam.yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
NotificationEmail:
Type: String
Resources:
CloudTrailEventProcessing:
Type: AWS::Serverless::Function
Properties:
Handler: handler
@doron2402
doron2402 / buildspec.yml
Created July 13, 2017 21:18
AWS CodeBuild buildspec.yml
version: 0.2
phases:
install:
commands:
- echo Installing Mocha...
- npm install -g mocha
pre_build:
commands:
- echo Installing source NPM dependencies...
@doron2402
doron2402 / mem_leak.js
Created July 5, 2017 17:25
Node.js Memory leark
'use strict';
const Memwatch = require('memwatch-next');
const Util = require('util');
if (Config.env === 'production') {
/**
* Check for memory leaks
*/
let hd = null;
Memwatch.on('leak', (info) => {