I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!
\
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') |
-- Functions to create and draw histograms with PostgreSQL. | |
-- | |
-- psql# WITH email_lengths AS ( | |
-- -# SELECT length(email) AS length | |
-- -# FROM auth_user | |
-- -# LIMIT 100 | |
-- -# ) | |
-- -# SELECT * FROM show_histogram((SELECT histogram(length, 0, 32, 6) FROM email_lengths)) | |
-- bucket | range | count | bar | cumbar | cumsum | cumpct | |
-- --------+-------------------------------------+-------+--------------------------------+--------------------------------+--------+------------------------ |
#!/bin/bash | |
aws cloudformation create-stack --stack-name test-vpc --template-body file://vpc.json |
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,
#!/bin/sh | |
# linux firewall/forwarding | |
modprobe iptable_nat | |
echo 1 | tee /proc/sys/net/ipv4/ip_forward | |
iptables -t nat -A POSTROUTING -s 10.10.10.1/2 -o eth0 -j MASQUERADE | |
# install openvpn | |
apt-get update && apt-get install -y openvpn | |
cd /etc/openvpn/ | |
INSTANCE=$(curl http://169.254.169.254/latest/meta-data/public-hostname) | |
openvpn --genkey --secret ${INSTANCE}.key |
--- | |
rvm: | |
- 2.0.0 | |
before_install: | |
- "echo 'gem: --no-document' > ~/.gemrc" | |
- "echo '--colour' > ~/.rspec" | |
- gem install fog | |
- "./script/travis/bundle_install.sh" | |
- export DISPLAY=:99.0 |
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.
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 |
Here are some things I have learned along the way.
Last Updated: 2013-02-08
Original Audience: Hack Reactor