Skip to content

Instantly share code, notes, and snippets.

View snusnu's full-sized avatar

Martin Gamsjaeger snusnu

View GitHub Profile
@dkubb
dkubb / strip_whitespace.rb
Last active December 21, 2015 20:52
Strips trailing whitespace from source files
#!/usr/bin/env ruby
require 'pathname'
# files and extensions to process
FILES = %w[ capfile Capfile Dockerfile Gemfile Gemfile.devtools Gemfile.lock Guardfile CHANGELOG LICENSE Manifest README README.rdoc README_FOR_APP RUNNING_UNIT_TESTS Rakefile RUBY-STYLE SPECS TODO USAGE Vagrantfile .autotest .gitattributes .gitignore .htaccess .rspec .rcov .rvmrc .travis.yml .vimrc ].freeze
EXTENSIONS = %w[ builder cabal cgi coffee conf css deface deploy erb example fcgi feature handlebars haml hs htc htm html jinja js json key markdown md opts pem php rabl rake ratom rb rcsv rdf rdoc reek rhtml rip rjs rpdf ru rxml sake sass scss sh sls smil sql svg thor txt vcf xml yml ].freeze
paths = ARGV.flat_map(&Pathname.method(:glob))
paths.each do |path_in|
development:
adapter: master_slave
master:
adapter: mysql
database: master
host: master_server
slave:
adapter: mysql
database: slave
host: localhost
@dkubb
dkubb / test.rb
Created March 17, 2010 23:52
UoW code spike
# NOTE: this is a code spike, and the following code will probably
# not make it into dm-core in it's current form. I wanted to see if it
# were possible to use a topographical sort to ensure parents were
# saved before children, before/after filters were fired in the correct
# order, and foreign keys set before children are saved, but after parents
# are saved.
# The hooks should fire in the following order:
# https://gist.github.com/6666d2818b14296a28ab
@dkubb
dkubb / gist:515866
Created August 9, 2010 18:28
Veritas w/Graphiviz
#!/usr/bin/ruby -Ku
# $LOAD_PATH.unshift '/Users/dankubb/Programming/ruby/open-source/veritas/lib'
# $LOAD_PATH.unshift '/Users/dankubb/Programming/ruby/open-source/veritas-optimizer/lib'
require 'veritas'
require 'veritas-optimizer'
require 'graphviz'
include Veritas
@dkubb
dkubb / yard_dbc.rb
Created August 25, 2010 04:53
YARD based DbC system (code spike)
#!/usr/bin/ruby -Ku
# encoding: utf-8
# The idea with this code spike is to parse some code that has YARD
# documentation, and then wrap the methods at runtime to ensure that
# they match the behavior specified in the docs.
#
# This code will test the input, output and exceptions for every
# documented method. It will also test the provided block's input
@armitage
armitage / subdomain_rewrite
Created November 8, 2010 18:21
This Apache Config takes the subdomain part of a url if available (except www) and tries to find files in the document root with subdomain appended if the file cannot be found their i tries a second directory, in thies case the top level doc root
RewriteEngine on
RewriteLogLevel 2
RewriteLog /var/www/sites/camino_surf/logs/rewrite.log
RewriteCond %{HTTP_HOST} !www.caminosurf.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).caminosurf.com [NC]
# first try to find it in branch dir based on subdomain
# ...and if found stop and be happy:
RewriteCond /var/www/sites/camino_surf/public/%{REQUEST_FILENAME} -f
@dkubb
dkubb / dm_query_graph.rb
Created December 19, 2010 09:07
Code spike to see if joins can be modelled using a DAG
require 'set'
require 'tsort'
module DataMapper
class Query
class Graph
include TSort
def initialize
@graph = Hash.new { |graph, target| graph[target] = Set.new }
module DataMapper
module Model
module Relationship
alias :has_without_polymorphism :has
# Defines a 1:n or 1:1 relationship.
#
# = Options
# :as => Symbol defines this relationship as polymorphic
#
@solnic
solnic / dm_property_2.0.rb
Created January 18, 2011 12:12
An introduction to DataMapper Property API v. 2.0 (draft)
##
#
# The most important aspect of the new Property API is that
# property inheritance should not be used to instruct
# adapters how to persist data. It means, for example, that
# you should not use Integer as the base class for your custom
# property just because it is persisted as an integer. Right now
# Enum inherits from Integer because it is stored as an integer.
# It is a mistake, because a value of Enum property can be either
# a string or a symbol, not integer. The fact that it is persisted
@xaviershay
xaviershay / gist:787378
Created January 20, 2011 04:12
Bad idea of the week: ARel + DataMapper
# Because I can't figure out how the fuck to get SQL out of datamapper itself
class PGEngine < Arel::Visitors::PostgreSQL
attr_accessor :engine
def initialize(engine)
super
self.engine = engine
end
def connection_pool