Skip to content

Instantly share code, notes, and snippets.

View narath's full-sized avatar

Narath Carlile narath

View GitHub Profile
@narath
narath / r_keep_only_first_row.md
Created July 29, 2019 20:42
R: keep only the first row for duplicate data

How to keep only the first instance of a row

Derived from this helpful stackoverflow answer

dup_data %>% 
  group_by(MRN) %>%
  filter(Year == min(Year)) %>%
  slice(1) %>%
 ungroup()
@narath
narath / read_all_csv_files.r
Created March 21, 2019 19:22
R code to read all the csv files into a single dataset (only works when all csv files have the same format)
read_all_csv_files <- function(dir) {
save_dir <- getwd()
setwd(dir)
files <- list.files(pattern = "csv")
for (file in files) {
if (!exists("dataset")){
dataset <- read.csv(file)
} else {
temp_dataset <- read.csv(file, stringsAsFactors = FALSE)
dataset <- rbind(dataset, temp_dataset)
@narath
narath / lib.R
Created May 11, 2018 20:43
R utility methods
# Collected R utility methods
read_all_csv_files <- function(dir) {
save_dir <- getwd()
setwd(dir)
files <- list.files(pattern = "csv")
for (file in files) {
if (!exists("dataset")){
dataset <- read.csv(file)
} else {
@narath
narath / login_helper.rb
Created October 28, 2017 22:30
LoginHelper for Basic Auth with Rspec and Rails
module LoginHelper
def login(user="test",pw="test")
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user,pw)
end
end
RSpec.configure do |config|
config.include LoginHelper, type: :controller
end
@narath
narath / faraday_post.rb
Created May 8, 2017 17:24
How to do a x-www-form-urlencoded post with Faraday
require 'faraday'
require 'uri'
data = {
:your_data => "YOUR DATA"
}
url = "some url"
response = Faraday.post(url) do |req|
<!DOCTYPE html>
<html>
<head>
<title>Simple Auth App</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<script>
// get the URL parameters received from the authorization server
var state = getUrlParameter("state"); // session key
@narath
narath / realm_words
Last active August 29, 2015 14:13 — forked from anonymous/realm_words
Menopause
Antibiotics
Exercise
Jaundice
Rectal
@narath
narath / realm_words
Last active August 29, 2015 14:13 — forked from anonymous/realm_words
Menopause
Antibiotics
Exercise
Jaundice
Rectal
@narath
narath / upgrade_phusion_passenger_to_ruby_2_1_on_ubuntu_precise.md
Created April 26, 2014 16:36
How we upgraded Phusion Passenger for Ruby 2.1 on Ubuntu Precise

After upgrading to Ruby 2.1, the rails app and apache we got the following error in our apache log:

/usr/bin/ruby: warning: RUBY_HEAP_MIN_SLOTS is obsolete. Use RUBY_GC_HEAP_INIT_SLOTS instead.
/usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- phusion_passenger (LoadError)
	from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
	from /usr/share/phusion-passenger/helper-scripts/passenger-spawn-server:76:in `<main>'
[ pid=56858 thr=140583398008576 file=ext/apache2/Hooks.cpp:884 time=2014-04-25 22:10:55.823 ]: Unexpected error in mod_passenger: Cannot spawn application '/home/web1.kmedcommunications.com/current': Could not read from the spawn server: Connection reset by peer (104)
  Backtrace:
     (empty)