Skip to content

Instantly share code, notes, and snippets.

View gbuesing's full-sized avatar

Geoff Buesing gbuesing

View GitHub Profile
@gbuesing
gbuesing / bounding_box.rb
Created October 27, 2015 14:00
GooglePlaces gem spots_by_bounds test
require 'google_places'
api_key = 'key'
# Actually executing stubbed-out spec "should request spots by bounds" from client_spec.rb
# Supplying a bounding box to a text search query does not seem to work, nor is this feature documented:
# https://developers.google.com/places/web-service/search#TextSearchRequests
query = 'pizza'
# Bounds is around city of Nashville TN
addParams = (path, params) ->
query = objToQuery(params)
joinChar = if /\?/.test(path) then '&' else '?'
"#{path}#{joinChar}#{query}"
objToQuery = (obj) ->
pairs = []
for own key, val of obj
if val? and val != ''
val = encodeURIComponent(val)
@gbuesing
gbuesing / pubsub.coffee
Last active October 31, 2015 21:04
PubSub via jQuery without DOM bindings
# Simple global PubSub system built around $.Callbacks
# Enables PubSub without relying on DOM element bindings
#
# Usage:
#
# PubSub.subscribe 'foo', (message) -> console.log("Received: #{message}")
# PubSub.publish 'foo', 'bar'
# # Outputs: "Received: bar"
$(document).on 'ready', () ->
window.PubSub =
@gbuesing
gbuesing / nmatrix_standardize_columns.rb
Created September 5, 2015 19:18
NMatrix standardize_columns extension
require 'nmatrix/nmatrix'
class NMatrix
def standardize_columns!
cols.times do |i|
col = self[0..-1,i]
self[0..-1,i] = (col - col.mean[0]) / col.std[0]
end
self
end
@gbuesing
gbuesing / nmatrix_ext.rb
Last active August 28, 2015 18:49
NMatrix non-contiguous row/col selection extension
require 'nmatrix/nmatrix'
NMatrix.class_eval do
def row(row_number, get_by = :copy)
if row_numbers = get_row_or_col_index_array(row_number)
out = NMatrix.new [row_numbers.length, cols], default_value, dtype: dtype, stype: stype
row_numbers.each_with_index do |rownum, i|
out[i, 0..-1] = self[rownum, 0..-1]
@gbuesing
gbuesing / linear_regressor.rb
Last active August 29, 2015 14:18
Multivariate linear regression in Ruby - adapted from example from Andrew Ng's Machine Learning Coursera class
require 'narray' # gem install narray
class LinearRegressor
attr_reader :theta, :mean, :std, :cost_history
def initialize opts = {}
@alpha = opts[:alpha] || 0.01
@iterations = opts[:iterations] || 400
end
@gbuesing
gbuesing / pca.rb
Created March 30, 2015 01:53
Principal Component Analysis in Ruby
# Ruby implementation of PCA as described in:
#
# A tutorial on Principal Components Analysis
# Lindsay I Smith February 26, 2002
# http://www.cs.otago.ac.nz/cosc453/student_tutorials/principal_components.pdf
#
# Install:
#
# brew install gsl
# brew install gnuplot --with-x11
@gbuesing
gbuesing / ml-ruby.md
Last active February 28, 2024 15:13
Resources for Machine Learning in Ruby

UPDATE a fork of this gist has been used as a starting point for a community-maintained "awesome" list: machine-learning-with-ruby Please look here for the most up-to-date info!

Resources for Machine Learning in Ruby

Gems

@gbuesing
gbuesing / temp_sensor.ino
Last active August 29, 2015 14:06
Arduino BLE temperature sensor w/ nRF8001
// BLEPeripheral: https://github.com/sandeepmistry/arduino-BLEPeripheral
// TimerOne: https://code.google.com/p/arduino-timerone/
#include <TimerOne.h>
#include <SPI.h>
#include <BLEPeripheral.h>
// Pins used for Adafruit nrf8001 breakout
// See https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout/hooking-everything-up
#define BLE_REQ 10
#define BLE_RDY 2
@gbuesing
gbuesing / btclearcache.sh
Created September 20, 2014 03:39
Clear the Bluetooth attributes cache on Mac OS X
#!/bin/sh
# Clear the Bluetooth attributes cache on Mac OS X
# From http://expertsoverflow.com/questions/23549859/clearing-corebluetooth-gatt-cache-without-removing-bond
sudo defaults write /Library/Preferences/com.apple.Bluetooth CoreBluetoothCache -dict
sudo launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist
sudo launchctl load /System/Library/LaunchDaemons/com.apple.blued.plist