This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Read from the file file.txt and output the tenth line to stdout. | |
sed -n 10p file.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
OlderNewer