Skip to content

Instantly share code, notes, and snippets.

class Ticket < ActiveRecord::Base
belongs_to :grouper
belongs_to :user
validate :user_cant_be_blacklisted, on: :confirmation
validate :user_cant_double_book, on: :confirmation
validate :grouper_cant_be_full, on: :confirmation
validate :grouper_cant_have_occurred, on: :confirmation
@scy
scy / opening-and-closing-an-ssh-tunnel-in-a-shell-script-the-smart-way.md
Last active March 15, 2024 11:26
Opening and closing an SSH tunnel in a shell script the smart way

Opening and closing an SSH tunnel in a shell script the smart way

I recently had the following problem:

  • From an unattended shell script (called by Jenkins), run a command-line tool that accesses the MySQL database on another host.
  • That tool doesn't know that the database is on another host, plus the MySQL port on that host is firewalled and not accessible from other machines.

We didn't want to open the MySQL port to the network, but it's possible to SSH from the Jenkins machine to the MySQL machine. So, basically you would do something like

ssh -L 3306:localhost:3306 remotehost

defmodule ApplicationRouter do
use Dynamo.Router
prepare do
# Pick which parts of the request you want to fetch
# You can comment the line below if you don't need
# any of them or move them to a forwarded router
conn.fetch([:cookies, :params])
end
@jstorimer
jstorimer / tclient.rb
Created June 25, 2013 21:09
These scripts were the result of the "Faster Rails test runs...with Unix!" screencast at https://www.youtube.com/watch?v=RSehcT4MnRM.
#!/usr/bin/env ruby
require 'socket'
test_file = ARGV[0]
socket = UNIXSocket.new('testing.sock')
socket.write(test_file)
socket.close_write
@willurd
willurd / web-servers.md
Last active May 6, 2024 13:43
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@ericbmerritt
ericbmerritt / Makefile
Last active August 11, 2023 09:35
Universal drop in Makefile for Erlang projects that use rebar
# Copyright 2012 Erlware, LLC. All Rights Reserved.
#
# This file is provided to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@rubiii
rubiii / tldr.md
Last active December 17, 2015 22:59
Savon 3.0 TL;DR

Savon 3.0 TL;DR

  • It requires Ruby 1.9 or higher.
  • It is based on the all-new Wasabi 4.0 which is the driving factor behind this version. This means, that we now require a WSDL! There's a TL;DR for Wasabi 4.0 as well and you should read it.
  • HTTP caused a lot of problems and questions which this project should not have to deal with at all, so I'm replacing HTTPI with a simple adapter you can overwrite for authentication, cookies, etc. Added benefit: you can also easily swap it out in your tests.
  • Thanks to the new parser, Savon can now create example requests and show you the types to use.
#!/bin/sh
for q in $(echo 'SMEMBERS "resque:queues"' | redis-cli | awk '{print $1}')
do
echo $q $(echo "LLEN \"resque:queue:$q\"" | redis-cli)
done
# in a single line;
# for q in $(echo "SMEMBERS \"resque:queues\"" | redis-cli | awk '{print $1}'); do echo $(echo "LLEN \"resque:queue:$q\"" | redis-cli); done | awk '{s+=$1} END {print s}'
@ryandotsmith
ryandotsmith / timer.rb
Last active December 15, 2015 00:19
Time rack requests and print heroku request id
class RackTimer
def initialize(app)
@app = app
end
def call(env)
start_request = Time.now
status, headers, body = @app.call(env)
elapsed = (Time.now - start_request) * 1000
$stdout.puts("request-id=#{env['HTTP_HEROKU_REQUEST_ID']} measure.rack-request=#{elapsed.round}ms")