Skip to content

Instantly share code, notes, and snippets.

@GUI
GUI / typhoeus_put_easy.rb
Created March 9, 2011 20:22
Multiple Typhoeus::Request PUT requests hang. Multiple Typhoeus::Easy PUT requests work.
require "typhoeus"
2.times do |i|
puts "\n==== RUN #{i} ===="
e = Typhoeus::Easy.new
e.url = "http://example.com/"
e.method = :put
e.verbose = true
e.perform
end
@GUI
GUI / server_thin.rb
Created March 10, 2011 04:11
Multiple Typhoeus::Request PUT requests hanging when connecting to WEBrick server
require "rubygems"
require "sinatra"
set :server, "thin"
set :port, "4568"
put "/" do
"Hi"
end
@GUI
GUI / install_vagrant_sudoers.sh
Created June 3, 2012 19:13 — forked from beddari/install_vagrant_sudoers.sh
Allow Vagrant sudo-access without password for NFS-setup (for OS X)
#!/bin/bash
# Script for placing sudoers.d files with syntax-checking
# Making a temporary file to contain the sudoers-changes to be pre-checked
TMP=$(mktemp -t vagrant_sudoers)
cat /etc/sudoers > $TMP
cat >> $TMP <<EOF
# Allow passwordless startup of Vagrant when using NFS.
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/su root -c echo '*' >> /etc/exports
@GUI
GUI / apis.json
Created September 26, 2012 05:20
API Metadata Schema Examples
{
"apis": [
{
"title": "Alternative Fuel Stations - List All",
"description": "Get all alternative fuel stations that match your query",
"keywords": ["alternative fuel", "transportation"],
"agency": "Department of Energy",
"dataDictionary": "http://developer.nrel.gov/doc/api/alt-fuel-stations/v1",
"accessURL": {
"absoluteURI": "http://developer.nrel.gov/doc/api/alt-fuel-stations/v1.{format}",
{
"apiVersion":"1.0.0",
"swaggerVersion":"1.2",
"basePath":"http://petstore.swagger.wordnik.com/api",
"resourcePath":"/pet",
"produces":[
"application/json",
"application/xml",
"text/plain",
"text/html"
def foo
if("moo" =~ /(\w+)/)
puts " inside foo: #{$1.inspect} #{Regexp.last_match.inspect}"
end
end
def replace
"something".gsub(/(foo)/, "bar")
end
def fast_string_to_time(string)
matches = string.match(Format::ISO_DATETIME)
if matches
microsec = (matches[7].to_r * 1_000_000).to_i
new_time matches[1].to_i, matches[2].to_i, matches[3].to_i, matches[4].to_i, matches[5].to_i, matches[6].to_i, microsec
end
end
@GUI
GUI / Vagrantfile
Created April 26, 2014 14:45
NREL Vagrant Base Box Puppet Test
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "CentOS-6.5-x86_64-v20140311"
config.vm.box_url = "http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.5-x86_64-v20140311.box"
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "site.pp"
end
end
@GUI
GUI / hash_to_seed_fu.sh
Created December 31, 2014 00:04
Big ugly regex to convert Ruby hash object-ish text into Seed-Fu seed syntax (used to translate some custom db/seeds.rb into seed-fu compatible files)
perl -p -i -e 's/^ *:/ s./g;s/s\._id/s.id/g;s/ => / = /g;s/, *$//g;s/^ *} *$/end\n/g;s/^ *{ *$/ModelName.seed do |s|/g' seed_file.rb
@GUI
GUI / test_rate.md
Created January 8, 2015 19:46
SAM API Rate Limits

Test Script

require "rest_client"

10.times do
  puts Time.now
  RestClient.get("https://api.data.gov/sam/v1/registrations/1459697830000?api_key=#{ENV["API_KEY"]}") do |response|
    puts "Response: #{response.code}"
 end