Skip to content

Instantly share code, notes, and snippets.

Ryan Walker rwalk

Block or report user

Report or block rwalk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View quadprog_ospq_comp_1.R
library(quadprog)
library(osqp)
# This gist compares the quadprog solver against OSPQ on a very simple problem.
##
## The following example comes directly from `?? quadprog` documentation`
##
## Assume we want to minimize: -(0 5 0) %*% b + 1/2 b^T b
## under the constraints: A^T b >= b0
@rwalk
rwalk / chis2015demo.R
Last active Dec 27, 2016
CHIS 2015: Insurance coverage type vs fast food consumption
View chis2015demo.R
library(foreign)
library(car)
library(ggplot2)
library(scales)
# load the CHIS data
file <- "~/projects/CHIS/chis15_adult_stata/Data/ADULT.dta" # your file
CHIS <- read.dta(file, convert.factors = TRUE)
# Recode insurance type
@rwalk
rwalk / ScalatraChunkedEncoding.scala
Last active Oct 25, 2016
Scalatra: chunked transfer Encoding HTTP endpoint example
View ScalatraChunkedEncoding.scala
import org.json4s.{DefaultFormats, Formats}
import scala.language.postfixOps
import scalate.ScalateSupport
import org.scalatra._
import java.io.PrintWriter
class Chunks extends ScalatraServlet with ScalateSupport {
/*
Simple example of chunked transfer encoding in Scalatra (scala web framework)
*/
@rwalk
rwalk / image_segmentation_demo.R
Created Jan 3, 2016
Segment an image by color using Kmeans
View image_segmentation_demo.R
# image segmentation demo
# author: rwalker (ryan@ryanwalker.us)
# license: MIT
library("jpeg")
library("png")
library("graphics")
library("ggplot2")
library("gridExtra")
#######################################################################################
View tweet_sampler.py
#!/usr/bin/python3
'''
Sample from the twitter API and post results to a file or to Kafka.
To use, set credientials as enviornment variables, e.g.
export TWITTER_ACCESS_TOKEN=...
or source myfile
where myfile exports the authorization variables
'''
import twython, json, re, argparse, subprocess, os, sys, time
from socket import timeout
View kafka_stream_producer.py
#!/usr/bin/python3
'''
Put documents from the stream into Kafka
'''
import argparse
from kafka import SimpleProducer, KafkaClient
from time import sleep
def chunk_iterable(A,n):
'''An iterable that contains the iterates of A divided into lists of size n.
@rwalk
rwalk / elasticsearch_quickstart.py
Created Sep 17, 2015
Quickstart elasticsearch with Python
View elasticsearch_quickstart.py
#!/usr/bin/python3
# This script is a simple introduction to the python elasticsearch API.
#
# This script will populate an elasticsearch index from a file and then give a simple command line query interface.
# Each line of the input file will be mapped into a JSON document of the form { "text": "my file line..." } and added
# to the index.
#
# You can use Docker to spin up a local elasticsearch instance to play around with, e.g.
# docker run --name elasticsearch -d -p 9200:9200 elasticsearch:latest
#
@rwalk
rwalk / autocompleter
Last active Aug 29, 2015
Autocompleter running in Docker
View autocompleter
#
# Docker demo: container for a simple autocomplete program
# Autocomplete script is python3 and consumes a dictionary
# file packaged in the ubuntu operating system.
#
# start with the base ubuntu image
FROM ubuntu
# Tell apt-get that we are going to be NONINTERACTIVE
@rwalk
rwalk / autocomplete.py
Last active Aug 29, 2015
Autocomplete with a trie
View autocomplete.py
#!/usr/bin/python3
'''
Autocompletion using a trie and a user supplied language file.
HINT: Linux/Unix users can look in "/usr/share/dict" for language files.
Author: rwalker
Email: r_walker@zoho.com
License: MIT
'''
import argparse, os, sys
@rwalk
rwalk / quadprog_ipoptr_translate.R
Created Mar 8, 2015
Quadratic programming: Use matrix inputs to solve a QP with ipoptr
View quadprog_ipoptr_translate.R
ipoptr_qp <- function(Dmat, dvec, Amat, bvec, ub=100){
# Solve the quadratic program
#
# min -d^T x + 1/2 x^T D x
# s.t. A%*%x>= b
#
# with ipoptr.
n <- length(bvec)
# Jacobian structural components
You can’t perform that action at this time.