Skip to content

Instantly share code, notes, and snippets.

View thigm85's full-sized avatar

Thiago G. Martins thigm85

View GitHub Profile
@thigm85
thigm85 / YahooFinance_odb_table.R
Last active December 17, 2015 12:09
This is the first step to establish a simple and free database to hold stock quotes downloaded from Yahoo Finance!
require(ODB)
database_path = "~/example_path/my_database.odb"
# Create a database
odb.create(database_path)
# Connect to the database
ODB <- odb.open(database_path)
@thigm85
thigm85 / simple_neural_network_diagram
Created May 26, 2013 15:10
Graphviz script to draw a simple neural network diagram. Copy this to a `file.txt` file and then run `dot -Tpng -O file.txt` from command-line to get a .png figure with the diagram.
digraph G {
rankdir=LR
splines=line
node [fixedsize=true, label=""];
subgraph cluster_0 {
color=white;
node [style=solid,color=blue4, shape=circle];
@thigm85
thigm85 / multi_class_neural_netwrok_diagram
Created June 11, 2013 20:04
Graphviz script to draw a multi-class neural network diagram. Copy this to a `file.txt` file and then run `dot -Tpng -O file.txt` from command-line to get a .png figure with the diagram.
digraph G {
rankdir=LR
splines=line
nodesep=.05;
node [label=""];
subgraph cluster_0 {
color=white;
require(ggplot2)
require(gridExtra)
require(reshape2)
set.seed(1)
predictors = data.frame(x1 = rnorm(1000, mean = 5, sd = 2),
x2 = rexp(1000, rate=10))
p1 = ggplot(predictors) + geom_point(aes(x = x1, y = x2))
@thigm85
thigm85 / loading_plot.R
Created November 28, 2013 09:45
Sample code to plot PCs coefficients associated with variables in the dataset. See http://tgmstat.wordpress.com/2013/11/28/computing-and-visualizing-pca-in-r/ for more info.
require(ggplot2)
theta <- seq(0,2*pi,length.out = 100)
circle <- data.frame(x = cos(theta), y = sin(theta))
p <- ggplot(circle,aes(x,y)) + geom_path()
loadings <- data.frame(ir.pca$rotation,
.names = row.names(ir.pca$rotation))
p + geom_text(data=loadings,
mapping=aes(x = PC1, y = PC2, label = .names, colour = .names)) +
@thigm85
thigm85 / lda_vs_pca.R
Last active March 16, 2021 11:31
Visualize the difference between PCA and LDA on the iris dataset.
require(MASS)
require(ggplot2)
require(scales)
require(gridExtra)
pca <- prcomp(iris[,-5],
center = TRUE,
scale. = TRUE)
prop.pca = pca$sdev^2/sum(pca$sdev^2)
require(ggplot2)
# Figure 1
ggplot(GermanCredit, aes(x = Class)) +
geom_bar(aes(y = (..count..)/sum(..count..))) +
labs(y = "prob.")
@thigm85
thigm85 / node_js_first_application.js
Created January 20, 2016 14:23
A minimal node.js application
var http = require("http");
http.createServer(function (request, response) {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response body as "Hello World"
<html>
<head>
<title>File Uploading Form</title>
</head>
<body>
<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="http://127.0.0.1:8081/file_upload" method="POST"
enctype="multipart/form-data">
<input type="file" name="file" size="50" />
@thigm85
thigm85 / pre_post_clean_pom.xml
Created February 17, 2016 21:25
POM file where a goal is executed in the pre-clean, clean and post-clean phases of the clean lifecycle. Reference: http://www.tutorialspoint.com/maven/maven_build_life_cycle.htm
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.companyname.projectgroup</groupId>
<artifactId>project</artifactId>
<version>1.0</version>
<build>
<plugins>