Skip to content

Instantly share code, notes, and snippets.

View rye's full-sized avatar
🦀
wranglin' Cow<T>'s

Kris Rye rye

🦀
wranglin' Cow<T>'s
View GitHub Profile
@rye
rye / print-request-body.patch
Created July 22, 2014 17:22
This patch to FReCon prints out the request body.
diff --git a/lib/frecon/server.rb b/lib/frecon/server.rb
index 5a524de..06b6435 100644
--- a/lib/frecon/server.rb
+++ b/lib/frecon/server.rb
@@ -13,6 +13,8 @@ module FReCon
before do
content_type "application/json"
+
+ p request.body.read.to_s
@rye
rye / streaming_server.rb
Created December 16, 2014 16:14
Messing around with HTTP Streaming responses.
require "date"
require "json"
require "sinatra"
require "time"
module StreamMessageFormatter
def self.format(object)
return JSON.generate(object) << "\r\n"
end
end
@rye
rye / ruby-xflux.rb
Last active August 29, 2015 14:14
A simple startup script for XFlux, written in Ruby, of course.
#!/usr/bin/env ruby
require "net/http"
require "json"
require "pry"
# Uncomment this line and put in your default location if
# you want to have a default location (in case of network
# errors).
# $default_latlon = [90.0, 90.0]
@rye
rye / example_command.md
Created February 12, 2015 02:48
An example command to grab images from a webcam.

Example Command

This is the example command that will take pictures periodically:

$ ffmpeg -f v4l2 -i {{device, e.g. /dev/video1}} -ss 0:0:2 -s 120x90 -vsync 2 -r 4 -updatefirst 1 stream.png
  • -f v4l2 uses the standard linux /dev/video decoder thing.
require "net/http"
require "pry"
# Parameters for episode looping.
#
# Note that 404 seems to be reserved for whining.
MIN_EPISODE_NUMBER = 001
MAX_EPISODE_NUMBER = 417
FORMAT = ".ogv"
@rye
rye / bezier.rb
Created May 7, 2015 17:45
A Ruby script to calculate Bézier curves.
require "matrix"
require "pry"
class Integer
# Method to compute binomial coefficient nCk (where n is this object,
# and k is some other integer.
def choose(k)
# n! / (n-k)!
top = (((self-k)+1)..(self)).inject(1, &:*)
@rye
rye / defunct.sh
Created June 15, 2015 16:18
Print out a list of PID's that are defunct
#!/bin/sh
ruby -e "\"`ps -ef|grep \<defunct\>`\".split(/$/).each{|l|puts(l.match(/^(?<user>\w+)\W+(?<pid>\d+)\W+(?<ppid>\d+)/)[:pid])}"
@rye
rye / monoid-firehose.rb
Last active November 26, 2015 20:45
Drink from the Monoid firehose! (Downloads the latest Monoid release)
require 'uri'
require 'net/http'
module Monoid
class Site
attr_accessor :base_uri
def initialize(base_uri = URI.parse('https://larsenwork.com'))
@base_uri = base_uri
end
@rye
rye / output.txt
Created December 8, 2016 18:26
Output from Make when I compile @shyouhei's ruby version
CC = clang
LD = ld
LDSHARED = clang -dynamic -bundle
CFLAGS = -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Werror=implicit-int -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=shorten-64-to-32 -Werror=implicit-function-declaration -Werror=division-by-zero -Werror=deprecated-declarations -Werror=extra-tokens -pipe
XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -fPIE
CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -I. -I.ext/include/x86_64-darwin16 -I./include -I. -I./enc/unicode/data/8.0.0
DLDFLAGS = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -fstack-protector -Wl,-u,_objc_msgSend -Wl,-pie -framework CoreFoundation
SOLIBS = -lgmp
Apple LLVM version 8.0.0
@rye
rye / check_machine_status.sh
Created June 12, 2017 20:28
Checks the status of a list of machines using SSH blank firing.
#!/bin/bash
function check_user_and_host {
_ssh_result=$(ssh -o ConnectTimeout=5 -o BatchMode=yes -o StrictHostKeyChecking=no $1@$2 "echo \"\`who | grep -c . \`\"; true" 2>/dev/null)
}
function check_and_output_host {
check_user_and_host $1 $2 && echo "$2: up, $_ssh_result users logged in" || echo "$2: down"
}