Skip to content

Instantly share code, notes, and snippets.

View megpay's full-sized avatar

Megan Payne megpay

  • Amsterdam, Netherlands
View GitHub Profile
i<-1
x1 <- data.frame(age=rep(tuyns$age[i], tuyns$controls[i]) ,
tobacco=rep(tuyns$tobacco[i], tuyns$controls[i]),
alcohol=rep(tuyns$alcohol[i], tuyns$controls[i]),
case.ctl=rep(0, tuyns$controls[i]))
for (i in 2:length(tuyns$id)) {
new.df <- data.frame(age=rep(tuyns$age[i], tuyns$controls[i]) ,
tobacco=rep(tuyns$tobacco[i], tuyns$controls[i]),
alcohol=rep(tuyns$alcohol[i], tuyns$controls[i]),
@megpay
megpay / DB2conn.py
Last active June 21, 2020 23:57
DB2 connection from a python jupyter notebook
# Connecting to a DB2 server using python.
import ibm_db
# Fill in credentials below.
dsn_driver = "{IBM DB2 ODBC DRIVER}"
dsn_database = "database" # e.g. "EMPLOYEES"
dsn_hostname = "hostname" # e.g.: "db2.myhost.com"
dsn_port = "port" # e.g. "50000"
dsn_protocol = "protocol" # i.e. "TCPIP"
dsn_uid = "username" # e.g. "myusername"
@megpay
megpay / DB2_create.sql
Last active June 22, 2020 10:10
DB2 Practice - Some samples
/* Create table syntax with an auto-incremented field. */
DROP TABLE NewEmployees;
/* Note the auto increment syntax. It is slightly different. */
CREATE TABLE NewEmployees (
ID INT GENERATED BY DEFAULT AS IDENTITY
(START WITH 100 INCREMENT BY 10),
first_name VARCHAR(50),
last_name VARCHAR(50),
salary INT,
@megpay
megpay / readfile.sh
Created June 22, 2020 23:40
sed reading file parts
#!/bin/sh
# Read from the file file.txt and output the tenth line to stdout.
sed -n 10p file.txt
@megpay
megpay / topsal.sql
Last active June 23, 2020 07:28
Top Employee Salary by Department
/*
Given 2 tables in a MySQL database, Employee and Department, find the employees (including ties) with the highest
salaries for each department.
Employee table:
Id (auto incremented integer)
Name (Varchar, employee name)
DepartmentId (integer and key to Department table)
Salary (Integer)
@megpay
megpay / avg_salary.py
Created June 29, 2020 01:04
Returning the mean of a list of salaries without the max or min salaries.
# From this problem on leetcode.
# https://leetcode.com/problems/average-salary-excluding-the-minimum-and-maximum-salary/
# Given an array of unique integers salary where salary[i] is the salary of the employee i.
# Return the average salary of employees excluding the minimum and maximum salary.
# Example:
# Input: salary = [4000,3000,1000,2000]
@megpay
megpay / SF_crime_map.ipynb
Last active June 10, 2024 19:46
Visualizing the crime rate in San Francisco using python and folium
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@megpay
megpay / sed_commands.sh
Last active September 24, 2020 16:58
Useful sed commands
#!/bin/sh
# Where I am storing useful sed commands for later use.
# Removing characters from a csv or text file. This removes a double-quote.
sed 's/"//g' filename.csv
sed 's/"//g' filename.csv > filename_new.csv
# Not sed, but using cut to remove columns of a csv file.
# This takes a pipe-delimited file and removes columns 2, 3, and 4.
@megpay
megpay / useful_psql_commands.sql
Last active September 29, 2020 08:30
Useful postgresql commands
/* Basic viewing the structure commands */
\c database_name --connect to a database.
\dt --view the tables. this filters out non-table relations.
\d --view the tables. Includes non-table relations.
\d tablename --view the columns of the table.
/* Create a table and import from a csv into that table. */
CREATE TABLE employees (
id SERIAL,
@megpay
megpay / manual_gc.py
Created February 22, 2021 22:30
Manual garbage collection when RAM is limited
# Manual garbage collection due to limited RAM - useful in Kaggle competitions
import sys
for i in dir():
if sys.getsizeof(eval(i)) > 10000:
print("the size of {} is:".format(i), sys.getsizeof(eval(i))/1e+9)
import gc
del train # delete a data frame
gc.collect() # manual garbage collection