Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
aws cloudformation create-stack --stack-name test-vpc --template-body file://vpc.json
@brianjlandau
brianjlandau / gist:aa33f69932a4089a4de9
Created June 17, 2014 18:07
More strict web URL regex for validations. (better then URI.regexp)
require 'uri'
hostname = "(?:(?:[\\w\\-]+\\.)+[[:alpha:]]{2,})"
host = "(?:#{hostname}|#{URI::DEFAULT_PARSER.pattern[:IPV4ADDR]}|#{URI::DEFAULT_PARSER.pattern[:IPV6ADDR]})"
server = "//(?:#{URI::DEFAULT_PARSER.pattern[:USERINFO]}@)?#{host}(?::\\d*)?"
absolute_path = "(?:#{URI::DEFAULT_PARSER.pattern[:ABS_PATH]})?"
query = URI::DEFAULT_PARSER.pattern[:QUERY]
http_uri_regex = Regexp.new("\\A(?:http|https):(?:#{server}#{absolute_path})(?:\\?(?:#{query}))?\\z", Regexp::EXTENDED, 'N')
@JoshCheek
JoshCheek / quiz.md
Last active August 29, 2015 14:17
HTTP quiz!

Quiz time!

  • What does the dot mean in in StringIO.new, what does the hash mean in StringIO#puts?
  • How do you make a String literal?
  • How do you make a String without using a literal?

This is an HTTP request, it is a String that is sent across a Socket, which your program can read from as if it were a file or $stdin.

01 POST /users/5?omg=wtf&bbq=lol HTTP/1.1\r\n
@croaky
croaky / bid_offered_job.rb
Created July 27, 2012 06:28
Delayed::Job example
class BidOfferedJob < Struct.new(:bid_id)
PRIORITY = 1
def self.enqueue(bid)
Delayed::Job.enqueue new(bid.id), priority: PRIORITY
end
def perform
Mailer.bid_offered(owner, bid).deliver
Activity.create activity_type: 'bid_offered', subject: bid, user: aide
require 'rack'
require 'uri'
module UrlHelper
def self.merge_url_with_params(url, params = {})
uri = URI.parse(url)
query = Rack::Utils.parse_query(uri.query || '')
params.each do |key, value|
query[key.to_s] = value
end
@mjallday
mjallday / EXAMPLE.mkd
Created November 21, 2013 21:07
Failed debit creates transaction

curl https://api.balancedpayments.com/debits -XPOST -u ak-test-2yK59ihwoOOk0S6wsg77iMGzLGnGxiohB: -d "source[number]=4444444444444448" -d "source[expiration_month]=12" -d "source[expiration_year]=2016" -d amount=100

{
  "errors": [
    {
      "status": "Payment Required",
      "category_code": "card-declined",
      "additional": "Account Frozen",
      "status_code": 402,
@iain
iain / game_of_life.rb
Created April 30, 2010 00:06
Conway's Game of Life, in one line of Ruby
# Copyright 2010, Iain Hecker. All Rights Reserved
# Conway's Game of Life, in one line of Ruby.
# http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
# Tested and found working on Ruby 1.8.7 and 1.9.2
# The grid is spherical or "wrap around", so the left is connected to the right and top to bottom.
#
# Generate a random grid, 30 cells wide and 10 cells high
#
# grid = "30x10".to_grid
#
@sax
sax / load_data.sh
Last active February 16, 2017 11:18
Dump and reload data into PostgreSQL with massive concurrency
# interpolated load tables step
find . -type f -print0 | xargs -0 -n1 -P50 bash -c "psql -U <postgres_user> <mydatabase> < \$0"
@solarce
solarce / getting_more_familiar_with_go_resources.md
Last active June 19, 2017 13:54
A list of resources for getting more familiar with Go

Getting more familiar with Go

@glv
glv / trouble-free-bundler.md
Last active March 16, 2018 14:50
This is a thing I wrote over a year ago for the internal LivingSocial wiki. There's nothing LS-specific about it, and it seems generally useful, so …

Trouble-Free Bundler

Every couple of weeks, I hear someone complaining about some difficulties with Bundler. Yesterday, it happened twice. But somehow I just never have those difficulties. I'm not saying Bundler is perfect; certainly in its early days it wasn't even close. But for the past two years it's been incredibly solid and trouble-free for me, and I think a large part of the reason is the way I use it. Bundler arguably does too much, and just as with Git, a big part of it is knowing what not to do, and configuring things to avoid the trouble spots.