Skip to content

Instantly share code, notes, and snippets.

@illbzo1
illbzo1 / aan.rb
Created November 15, 2011 02:42
Random Phrase Generator, Refactored
require 'yaml'
words = YAML::load(File.open('words.yml'))
loop do
puts "Generate new phrase? (y / n)"
input = gets.chomp()
unless input == "n"
new_phrase = %w[adj2 noun].map { |type| words[type].sample }
addition = rand(7)
@illbzo1
illbzo1 / madlib.rb
Created November 8, 2011 03:15
Madlibs Generator, Objectified
@counter = 0
files = Dir.glob("*.madlib")
if files.size > 1
puts "CHOOSE YOUR FILE:"
x = 0
files.each do |file|
x += 1
puts "#{x}. #{file}"
@illbzo1
illbzo1 / madlibs
Created October 30, 2011 23:08
Madlibs Generator, Second Refactoring
def generate_mad_lib
puts "Bear with me. I'm going to need 16 singular nouns."
@nouns = []
16.times { @nouns << gets.chomp }
@nouns = @nouns.reverse
puts "Awesome, now I'm going to need 6 plural nouns."
@plural_nouns = []
6.times { @plural_nouns << gets.chomp }
@plural_nouns = @plural_nouns.reverse
@illbzo1
illbzo1 / madlibs
Created October 30, 2011 17:30
Refactored Madlibs generator
def generate_mad_lib
puts "Bear with me. I'm going to need 16 singular nouns."
@nouns = []
16.times { @nouns << gets.chomp }
puts "Awesome, now I'm going to need 6 plural nouns."
@plural_nouns = []
6.times { @plural_nouns << gets.chomp }
puts "Ok, now let's collect some singular verbs. I'm looking for 7 of them."
@illbzo1
illbzo1 / madlib
Created October 29, 2011 00:32
Simple MadLibs generator
def prompt
print "> "
end
def generate_mad_lib
puts "Bear with me. I'm going to need 18 singular @nouns."
prompt;
@noun1 = gets.chomp()
@noun2 = gets.chomp()
@noun3 = gets.chomp()
@illbzo1
illbzo1 / Gothon_Game
Created October 27, 2011 00:13
Another text-based dungeon game
class Game
def initialize(start)
@quips = [
"You died. You kind of suck at this.",
"Nice job! You died again!",
"What a loser!",
"I have a small puppy that's better at this."
]
@start = start
@illbzo1
illbzo1 / node_request_example.js
Last active August 29, 2015 14:22
An example for making POST requests to DocRaptor in Node.js, using request instead of restler
var request = require('request');
var fs = require('fs');
var content = "<html><body>TEST!</body></html>";
config = {
url: 'https://docraptor.com/docs',
encoding: null, //IMPORTANT! This produces a binary body response instead of text
headers: {
'Content-Type': 'application/json'
},
@illbzo1
illbzo1 / doc_raptor_async_example.sh
Last active August 29, 2015 14:18
Asynchronous Curl example for DocRaptor
#This example will create a sample asynchronous pdf document with the authentication information as part of the POST data
curl -H "Content-Type:application/json" -d'{"user_credentials":"YOUR_API_KEY_HERE", "doc":{"name":"async_example.pdf", "document_type":"pdf", "async":"true", "test":"true", "document_url":"https://docraptor.com"}}' http://docraptor.com/docs > async_example.pdf
#Making an asynchronous request will return some JSON with a status_id key like '{"status_id":"123454321"}'
cat async_example.pdf
#You can then use the status_id key to check the status of your asynchronous job
curl http://docraptor.com/status/123454321 -H "Content-Type:application/json" -d '{"user_credentials":"YOUR_API_KEY_HERE"}'
#Once your job has completed, you will recieve a response that contains the download_url for your document
@illbzo1
illbzo1 / random.pdf.erb
Created April 24, 2014 16:00
A step by step Ruby on Rails implementation for DocRaptor
<style type="text/css">
/* setup the page */
@page {
size: US-Letter;
margin: 0 0 35mm 0;
background: #ffffff;
}
/* setup the footer */
@page {
@illbzo1
illbzo1 / random.pdf.erb
Created April 23, 2014 19:09
A sample template for creating PDFs with DocRaptor.
<style type="text/css">
/* setup the page */
@page {
size: US-Letter;
margin: 0 0 35mm 0;
background: #ffffff;
}
/* setup the footer */
@page {