Skip to content

Instantly share code, notes, and snippets.

View rringler's full-sized avatar

Ryan Ringler rringler

  • Google
  • San Francisco, CA
View GitHub Profile
@rringler
rringler / quicksort.rb
Created September 30, 2018 20:29
Quicksort (Ruby)
def quicksort(array, left = 0, right = nil)
right ||= array.size - 1 # Sort the whole array be default
# NOTE: This is subtle; we only need to perform the sorting if `left` is less
# than `right`
if left < right
index = sort(array, left, right)
quicksort(array, left, index - 1) # Sort left sub_array
quicksort(array, index + 1, right) # Sort right sub_array
require 'tsort'
class UndirectedGraph < Hash
include TSort
def initialize(size, edges)
super().tap do |hash|
(1..size).each { |i| hash[i] = [] }
edges.each do |(a, b)|
@rringler
rringler / pid.rb
Created July 21, 2018 18:25
Ruby PID Controller
class PID
attr_reader :delta_t,
:kp,
:ki,
:kd,
:output_p_prev,
:output_i_prev,
:output_min,
:output_max,
:setpoint,
@rringler
rringler / python-pid_controller
Created July 6, 2018 03:58 — forked from chaosmail/python-pid_controller
Simple PID Controller
def pid_controller(y, yc, h=1, Ti=1, Td=1, Kp=1, u0=0, e0=0)
"""Calculate System Input using a PID Controller
Arguments:
y .. Measured Output of the System
yc .. Desired Output of the System
h .. Sampling Time
Kp .. Controller Gain Constant
Ti .. Controller Integration Constant
Td .. Controller Derivation Constant
@rringler
rringler / keybase.md
Created December 6, 2017 20:23
Keybase Verification

Keybase proof

I hereby claim:

  • I am rringler on github.
  • I am rringler (https://keybase.io/rringler) on keybase.
  • I have a public key ASBqcATXxSioDtJfMXH7O-qQRe_Z-dH_wxpPg3wfSH-olAo

To claim this, I am signing this object:

path=$(dirname "$1")
basename="animated"
filename="animated.gif"
counter="0"
while [ -e "$path/$filename" ]; do
((counter++))
filename="$basename ($counter).gif"
done
@rringler
rringler / hs100.sh
Created August 27, 2017 20:12
Shell Script to control a TP-Link HS100 Smart Outlet
#!/bin/bash
##
# Controls TP-LINK HS100,HS110, HS200 wlan smart plugs
# Tested with HS100 firmware 1.0.8
#
# Credits to Thomas Baust for the query/status/emeter commands
#
# Author George Georgovassilis, https://github.com/ggeorgovassilis/linuxscripts
import Ember from 'ember';
export default Ember.Component.extend({
agentCount: null,
didInsertElement() {
const comp = this;
let values$ = Bacon.fromEvent(this, 'test');
@rringler
rringler / memoizable.rb
Created April 23, 2017 21:46
Simple module for memoizing Ruby methods
module Memoizable
# Usage:
#
# class Foo
# extend Memoizable
#
# memoize def bar
# 'bar'
# end
# end
@rringler
rringler / bottom_collapse_button.css
Last active December 13, 2016 02:26
Reddit CSS to add a collapse button to the bottom of comments
.entry { position: relative; }
.entry > p > a.expand:hover:after { background: #369; }
.entry > p > a.expand:after {
content: '[–]';
position: absolute;
bottom: 12px;
right: 10px;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 10px;
font-variant: normal;