Skip to content

Instantly share code, notes, and snippets.

View davybrion's full-sized avatar

Davy Brion davybrion

  • That Extra Mile
  • Belgium
View GitHub Profile
module AutoRollbackBehavior
def run(runner)
test_result = nil
DB.transaction do
test_result = super
raise Sequel::Rollback
end
test_result
end
end
@davybrion
davybrion / gist:8576995
Created January 23, 2014 11:21
easy way to create query classes that create prepared statements through the 'sequel' library... performance impact of this is really low (query string is only stored in memory once and query execution always goes through prepared statement)
class Query
def self.query_name
:return_valid_query_name_in_subclass_or_you_will_get_really_weird_results
end
def self.create_prepared_statement(sql, placeholders_array)
sql = sql.super_strip unless Environment.log_sql?
DB[sql, *placeholders_array].prepare(:select, query_name)
end
@davybrion
davybrion / s1.js
Created September 15, 2012 17:12
code snippets for "Stop Storing Passwords Already!" post
var mongoose = require('mongoose'),
crypto = require('crypto'),
uuid = require('node-uuid'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
var userSchema = new Schema({
name: { type: String, required: true, unique: true },
email: { type: String, required: true },
salt: { type: String, required: true, default: uuid.v1 },
@davybrion
davybrion / s1.xml
Created September 15, 2012 17:08
code snippet for "Hosting a Node.js site through Apache" post
<VirtualHost 109.74.199.47:80>
ServerAdmin [email protected]
ServerName thatextramile.be
ServerAlias www.thatextramile.be
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
@davybrion
davybrion / s1.js
Created September 15, 2012 17:04
code snippets for "Displaying Feed Items On A Web Page: My Solution" post
var express = require('express'),
app = module.exports = express.createServer(),
NodePie = require('nodepie'),
request = require('request'),
recentFeedItems = null;
app.dynamicHelpers({
getRecentFeedItems: function() {
return recentFeedItems;
}
@davybrion
davybrion / s1.js
Created September 15, 2012 16:58
code snippets for "Using Mongoose’s Setters To Get Calculated Properties" post
var invoiceSchema = new Schema({
companyId: { type: ObjectId, required: true },
customerId: { type: ObjectId, required: true },
invoiceNumber: { type: String, required: true, unique: true },
date: { type: Date, required: true },
dueDate: { type: Date, required: true },
paid: { type: Boolean, required: true, default: false },
activityId: { type: ObjectId, required: true },
totalHours: { type: Number, required: true },
hourlyRate: { type: Number, required: true },
@davybrion
davybrion / s1.js
Created September 15, 2012 16:55
code snippets for "Take Advantage Of Your BDD Framework" post
describe('given an existing customer', function() {
describe('when it is retrieved from the database', function() {
it('should contain the same values that have been inserted', function() {
var customer = new CustomerBuilder()
.withIncludeContactOnInvoice()
.build();
customer.save(function(err) {
@davybrion
davybrion / s1.js
Created September 15, 2012 16:52
code snippet for "Solving A Problem By Avoiding It" post
var exec = require('child_process').exec;
function getJsFilesRecursively(startPath, callback) {
exec('find ' + startPath, function(err, stdout) {
var jsFiles = [];
stdout.split('\n').forEach(function(f) {
if (!/node_modules\//.test(f) && /.js$/.test(f)) {
jsFiles.push(f);
};
});
@davybrion
davybrion / s1.js
Created September 15, 2012 16:49
code snippets for "First Steps With MongoDB, Mongoose and Jasmine-Node On Node.JS" post
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
var customerSchema = new Schema({
name: { type: String, required: true },
address: {
street: { type: String, required: true },
postalCode: { type: String, required: true },
city: { type: String, required: true },
@davybrion
davybrion / s1.cs
Created September 15, 2012 16:46
code snippets for "Customizing ASP.NET MVC’s Required Property Validation Messages" post
public class ConventionsBasedRequiredAttributeAdapter : RequiredAttributeAdapter
{
public ConventionsBasedRequiredAttributeAdapter(ModelMetadata metadata, ControllerContext context, RequiredAttribute attribute)
: base(metadata, context, attribute) {}
public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
{
string errorMessage;
var className = Metadata.ContainerType.Name;