Skip to content

Instantly share code, notes, and snippets.

View IronistM's full-sized avatar
🏗️
Under construction

Manos Parzakonis IronistM

🏗️
Under construction
View GitHub Profile
N <- 10
id <- 1:10
x <- 1 + rnorm(N) - 1*id
date <- seq(as.Date("2013-07-01"), by = "year", along = x)
df <- data.frame(x = x, date = date)
plot(df$date, df$x)
summary(lm(x ~ date, data = df))
ANOVA<-function(fit1,fit2){
temp <- anova(fit2,fit1 )
fin.aov <- anova(fit1)
reg <- temp[2,2:6]
rownames(reg) <- "Regression"
reg[1,1:2] <- reg[1,2:3]
reg[1,3] <- reg[1,2]/reg[1,1]
colnames(reg) <- colnames(fin.aov)
res <- fin.aov[tail(nrow(fin.aov),1),]
tot <- cbind(reg[1,1:2]+res[1,1:2],NA,NA,NA)
suppressMessages(library(forecast))
data<-read.csv( file('stdin') )
anomaly_detection<-function(data){
seasonality<-48
data_series<-ts(data$count,frequency=seasonality)
train_start<-1 ## train on 1 month of data
# Library Loading
library("RPostgreSQL");
library("car");
# Connect to Database
pgDrv <- dbDriver("PostgreSQL")
dbh <- dbConnect(pgDrv, host="localhost", dbname="dnsmonitor", user="dnsmon", password="tooEasy")
# Retrieve Statistics from DB
stats <- dbGetQuery(dbh, "select client.id, client.ip, sum(queries) as queries, sum(nx) as nx, sum(answers) as answers, sum(errors) as errors, count(distinct day) as days_active
####################
# Create relogit predicted probabilities using Zelig and ggplot2
# Two Sword Lengths: Losers' Consent and Violence in National Legislatures (Working Paper 2012)
# Christopher Gandrud
# Updated 26 April 2012
###################
## Load required packages
library(RCurl)
library(Zelig)
@IronistM
IronistM / dynamically_changing_SQL_statement.qvs
Created November 11, 2013 10:42
This code sets variables to define a time period (previous calendar month) dynamically changing the SQL statement sent to source
let vLastMonth = Year(AddMonths(now(),-1)) & '-' & num(month(addmonths(now(),-1)),'00') & '-01';
// This gets the first of the previous month
let vThisMonth = Year(now()) & '-' & num(month(now()),'00') & '-01';
// This gets the first of the current month
ODBC CONNECT TO MyDSN; // Change to your database
LOAD *;
SQL SELECT
#########################################
## GLOBAL REQUIREMENTS AND DEFINITIONS ##
#########################################
require(RCurl)
require(XML)
loginURL <- "https://accounts.google.com/ServiceLogin"
authenticateURL <- "https://accounts.google.com/accounts/ServiceLoginAuth"
@IronistM
IronistM / exportjson.js
Created November 11, 2013 15:11 — forked from pamelafox/exportjson.js
functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
/**
* Copyright 2010, Boy van Amstel
* All rights reserved.
*/
var NAME = 'TTResponds';
var CONFIGSHEET = 'TTRespondsConfig';
var _activeApp = SpreadsheetApp.getActive();
var _formSheet = _activeApp.getSheets()[0];
set RecCount = 500000000; // Number of records to generate
Data:
load
chr(round(25 * rand() + 65)) & chr(round(25 * rand() + 65)) & chr(round(25 * rand() + 65)) as Customer, // Customer name between AAA and ZZZ
chr(round(25 * rand() + 65)) as Product, // Product name between A and Z
round(3 * Rand() + 2008) as Year, // Year between 2008 and 2011
round(1000000 * Rand()) as Actual, // Actual Revenue between 0 and 1,000,000
round(1000000 * Rand()) as Target // Target Revenue between 0 and 1,000,000
autogenerate(RecCount);