Skip to content

Instantly share code, notes, and snippets.

View stravid's full-sized avatar

David Strauß stravid

View GitHub Profile
@clemens
clemens / invoice.rb
Created July 24, 2014 19:49
invoice number generation per year
class Invoice < ActiveRecord::Base
before_validation :generate_number, on: :create
private
def generate_number
prefix = "R#{Date.today.strftime('%y')}-"
last_order_number_this_year = self.class.where("number LIKE ?", "#{prefix}%").order("number DESC").limit(1).pluck(:number).first
number = last_order_number_this_year ? last_order_number_this_year.match(/\A#{prefix}(\d+)\z/)[1].to_i : 0
@thbar
thbar / private_buckets_test.rb
Last active August 29, 2015 14:17
Production sanity test to verify that S3 buckets remain private over time
def buckets
[
'myapp-production-backups',
'myapp-staging-backups',
'myapp-s3-logs'
]
end
def test_buckets_subdomain_private
buckets.each do |bucket_name|
@tvandervossen
tvandervossen / testing.txt
Created April 13, 2011 20:13
A small part from a code review report for an iOS app
Testing
Automated testing (even though still not widely used by Objective-C developers) would make
refactoring much easier, faster and safer. Good test coverage would also allow maintenance
to be done and new features to be added without first having to fully investigate the
function of all parts of the codebase and the way these parts fit together. This especially
applies when work is contracted out to developers other than those who originally created
the application.
The lack of a comprehensive automated test suite is a real disadvantage. Adding one is
@sirupsen
sirupsen / explain.rb
Created December 6, 2011 06:35
.ircrb entry to run explain on a query.
if defined? ActiveRecord
def explain(query)
query = query.to_sql if query.is_a?(ActiveRecord::Relation)
ActiveRecord::Base.connection
.execute("EXPLAIN ANALYZE #{query}")
.to_a
.each { |hash| puts hash["QUERY PLAN"] }
nil
@tvandervossen
tvandervossen / gist:1478543
Created December 14, 2011 21:09
Initial client lead questions
Can you please answer the following questions so we can assess the project,
and judge if we would be a good match?
1. Is this a new project, or is this for an existing website or application?
- This is a project for a completely new site or application
- This is a project to update an existing site or application
2. Which of the following areas do you need help with?
@mbleigh
mbleigh / Gemfile
Created March 21, 2012 03:14
Non-Rails Rackup with Sprockets, Compass, Handlebars, Coffeescript, and Twitter Bootstrap
source "https://rubygems.org"
gem 'sprockets'
gem 'sprockets-sass'
gem 'sass'
gem 'compass'
gem 'bootstrap-sass'
gem 'handlebars_assets'
gem 'coffee-script'
@voodootikigod
voodootikigod / migrate.js
Created January 3, 2012 22:45
Schema (SQL) and Data (JS) Migrations for node.js (specifically PostgreSQL, but could be MySQL)
#!/usr/bin/env node
// this file is stored in a directory of APP_ROOT/script for me, all things are relative to that
var APP_ROOT = __dirname+"/../";
// this assumes there is a file stored in APP_ROOT called "config.js" with the following structure:
//
// module.exports = {
// "development: {
// "postgresql": "tcp://postgres@localhost/dev-db"
@r00k
r00k / gist:5885955
Created June 28, 2013 16:19
Notes for my talk at Engineers4Engineers at Constant Contact on 6/28/13.
My name is Ben Orenstein and I work at thoughtbot in Boston.
Notes will be published.
I'd like to tell you a story. (5:42)
I've never talked about this publicly.
Umass.
Second job.
Version control.
Successful since then.
@hoffmanc
hoffmanc / en.yml
Last active December 20, 2015 15:09
Hand rolled ICS support
# locales/en.yml
en:
time:
formats:
ical: "%Y%m%dT%H%M%SZ"
@maxhoffmann
maxhoffmann / gist:7373563
Last active December 27, 2015 18:59
run local php server and open browser
# local PHP Server
server() {
url="localhost:${2:-8000}"
if [ -z "$1" ]; then
php -S $url & # run server in background
else
php -S $url -t $1 &
fi
sleep 0.3s # wait for server to start