Skip to content

Instantly share code, notes, and snippets.

View abmathewks's full-sized avatar

Abraham Mathew abmathewks

View GitHub Profile
@zachmayer
zachmayer / Recessions.R
Created August 9, 2011 16:33
Forecasting Recessions
#Code to re-create John Hussman's Recession warning index
#http://www.hussmanfunds.com/wmc/wmc110801.htm
#R code by Zach Mayer
rm(list = ls(all = TRUE)) #CLEAR WORKSPACE
library(quantmod)
#################################################
# 1. Credit spreads
#################################################
@syntacticsugar
syntacticsugar / crapload_of_data.sql
Created October 8, 2012 21:31
Learn SQL Hard Way - snippets
INSERT INTO pet (id, name, breed, age, dead)
VALUES (5, "shimmer", "unicorn", 500, 1);
INSERT INTO pet (id, name, breed, age, dead)
VALUES (6, "water bottle", "faun", 4, 1);
INSERT INTO pet (id, name, breed, age, dead)
VALUES (7, "luis", "elephant", 282, 1);
INSERT INTO pet (id, name, breed, age, dead)
@bdewilde
bdewilde / knnRemoveZeroVarCols_kaggleDigitRecognizer
Created October 27, 2012 16:31
how to remove features with near zero variance, not useful for discriminating classes
# helpful functions for classification/regression training
# http://cran.r-project.org/web/packages/caret/index.html
library(caret)
# get indices of data.frame columns (pixels) with low variance
badCols <- nearZeroVar(train)
print(paste("Fraction of nearZeroVar columns:", round(length(badCols)/length(train),4)))
# remove those "bad" columns from the training and cross-validation sets
train <- train[, -badCols]
@mrdwab
mrdwab / LinearizeNestedList.R
Created December 4, 2012 16:00
Un-nest a nested list in R
LinearizeNestedList <- function(NList, LinearizeDataFrames=FALSE,
NameSep="/", ForceNames=FALSE) {
# LinearizeNestedList:
#
# https://sites.google.com/site/akhilsbehl/geekspace/
# articles/r/linearize_nested_lists_in_r
#
# Akhil S Bhel
#
# Implements a recursive algorithm to linearize nested lists upto any
@adrienne
adrienne / Useful SQL snippets
Last active August 30, 2023 22:17
Useful SQL snippets
Various handy bits and bobs relating to SQL (and the mySQL RDBMS in particular).
# Dump all databases from CLI:
$ mysqldump -h [server] -u root --password=password --default-character-set=utf8 --set-charset --all-databases > all_dbs.sql
# Restore all databases from CLI:
$ mysql -u root --password=password --default-character-set=utf8 --set-charset < all_dbs.sql
@martincr
martincr / gist:8463613
Created January 16, 2014 21:17
PostgreSQL Cheat Sheet
PostgreSQL Cheat Sheet
======================
CREATE DATABASE
CREATE DATABASE dbName;
CREATE TABLE (with auto numbering integer id)
CREATE TABLE tableName (
id serial PRIMARY KEY,
name varchar(50) UNIQUE NOT NULL,
@bsweger
bsweger / useful_pandas_snippets.md
Last active April 19, 2024 18:04
Useful Pandas Snippets

Useful Pandas Snippets

A personal diary of DataFrame munging over the years.

Data Types and Conversion

Convert Series datatype to numeric (will error if column has non-numeric values)
(h/t @makmanalp)

## Load libraries
library(XML)
library(dplyr)
library(RCurl)
## Get the results for a specific term
scrape_term = function(search_term,npages){
base_url = "http://scholar.google.com/scholar?"
search_string = paste0("q=",paste0(strsplit(search_term," ")[[1]],collapse="+"))
dat = data.frame(NA,nrow=10*npages,ncol=3)
@markglenfletcher
markglenfletcher / cheat.txt
Created September 30, 2015 20:02
SQL cheat sheet
SQL
Statements always end with a semi-colon ;
Statement breakdown:
CREATE TABLE table_name (
column_1 data_type,
column_1 data_type
);