Skip to content

Instantly share code, notes, and snippets.

import axios from 'axios'
const baseUrl = SOME_URL
const fetchAllData = async () => {
let allData = []
let apiResponse = await axios.get(baseUrl)
allData.push(apiResponse.data_you_care_about)
while (apiResponse.next_cursor) {
apiResponse = await axios.get(baseUrl + `next_cursor=${apiResponse.next_cursor}`)
@rweald
rweald / install-postgres-driver.sh
Created January 14, 2013 23:02
Installing postgres driver for apache sqoop
cd /tmp
wget "http://jdbc.postgresql.org/download/postgresql-9.2-1002.jdbc4.jar"
cp postgresql-9.2-1002.jdbc4.jar /usr/share/java/
ln -s /usr/share/java/postgresql-9.2-1002.jdbc4.jar /usr/lib/sqoop/lib/postgresql-9.2-1002.jdbc4.jar
@rweald
rweald / build.sbt
Created March 24, 2012 18:22 — forked from mumoshu/build.sbt
DES and AES encryption in Scala
name := "DES and AES encryption in Scala"
version := "1.0"
scalaVersion := "2.9.1"
libraryDependencies += "commons-codec" % "commons-codec" % "1.6"
@rweald
rweald / simple-linear-regression.rb
Created August 29, 2012 19:13
Simple Linear Regression in Ruby
class SimpleLinearRegression
def initialize(xs, ys)
@xs, @ys = xs, ys
if @xs.length != @ys.length
raise "Unbalanced data. xs need to be same length as ys"
end
end
def y_intercept
mean(@ys) - (slope * mean(@xs))
@rweald
rweald / clock_time.rb
Created November 17, 2017 05:42
Hacky little ruby scripts to generate race pace charts
paces = (13..18).to_a
aid_station_miles = [0.0,3.5,6.5,11.8,17.7,20.5,23.5,26.4,32.4]
start_time = 420
puts (['Miles'] + paces.map { |m| "#{m} min/mi" }).join(',')
aid_station_miles.each do |milage|
elapsed_time = paces.reduce([]) do |times, pace|
total_mins = (milage * pace).round(2)
/Users/Ryan/code/lantern/xealth-partner-sample-code/partner-api/gulper.js:78
function runCommand(cmd, args, verbosity = 0) {
^
SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:54:16)
at Module._compile (module.js:375:25)
at loader (/Users/Ryan/code/lantern/xealth-partner-sample-code/partner-api/node_modules/babel-register/lib/node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (/Users/Ryan/code/lantern/xealth-partner-sample-code/partner-api/node_modules/babel-register/lib/node.js:154:7)
at Module.load (module.js:345:32)
@rweald
rweald / install-rserver-ubuntu.sh
Created December 17, 2012 19:13
Installing R Server on Ubuntu
#!/usr/bin/env bash
echo "Installing R"
apt-get update
apt-get install r-base-core
apt-get install r-base-dev
echo "Installing R Server dependencies"
apt-get install gdebi-core libapparmor1
@rweald
rweald / denominator-snippet.rb
Created August 29, 2012 17:50
Code Snippets for Simple Linear Regression Using Ruby Blog Post
denominator = @xs.reduce(0) do |sum, x|
sum + ((x - x_mean) ** 2)
end
@rweald
rweald / running-scalatra-on-heroku.md
Created December 14, 2012 02:34
Running Scalatra on Heroku

Instructions

###You will need to add the sbt-start-script plugin.

This plugin gives you a stage action which generates a script called target/start that can be used to run your application without pulling SBT into memory.

This can be accomplished by first adding the following line to project/plugins.sbt

@rweald
rweald / convert-lat-long-to-state.R
Created February 6, 2013 06:40
Convert (long,lat) pairs into state names
#Code taken from SO
#http://stackoverflow.com/questions/8751497/latitude-longitude-coordinates-to-state-code-in-r/8751965#8751965
library(sp)
library(maps)
library(maptools)
# The single argument to this function, pointsDF, is a data.frame in which:
# - column 1 contains the longitude in degrees (negative in the US)
# - column 2 contains the latitude in degrees