Skip to content

Instantly share code, notes, and snippets.

View route's full-sized avatar
🕛
Things only change when we change them

Dmitry Vorotilin route

🕛
Things only change when we change them
View GitHub Profile
import re
import shutil
import argparse
from os import path
from sys import stderr
#
# Author: Daxda
# Date: 02.04.2014
# WTF: This is a quick tool I've hacked together to easily remove the meta
@route
route / template.rb
Last active November 25, 2022 10:24
AR template
class Example < ActiveRecord::Base
## includes
## plugins
## associations
## validations
## callbacks
## attr_*, delegate aliases, accepts_nested_attributes_for
## scopes
## class methods
## public methods
@route
route / gist:4372148
Last active December 10, 2015 03:08
async_exec can return nil
require 'pg'
c = PG::Connection.open(dbname: 'database')
[
Thread.new { Thread.current[:r] = c.async_exec("SELECT * FROM users") },
Thread.new { Thread.current[:r] = c.async_exec("SELECT * FROM users") }
].each { |t| t.join; p t[:r] }
#<NoMethodError: undefined method `sub' for nil:NilClass>
/Users/route/.rvm/gems/ruby-1.9.3-p194@grabber/gems/actionpack-3.2.8/lib/action_dispatch/testing/assertions/routing.rb:176:in `method_missing': undefined local variable or method `method_name' for #<ControllerSpec:0x007fa3c6560c68> (NameError)
puts e.backtrace
raise unless defined?(method_name)
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'bundler/setup' unless defined?(Bundler)
require 'minitest/autorun'
# Database cleaner strategy
require 'database_cleaner'
DatabaseCleaner.strategy = :transaction
require 'minitest/spec'
require 'minitest/autorun'
describe "Capture" do
it "should capture all output in the same process" do
out, err = capture_io do
puts "STDOUT"
warn "STDERR"
end
@route
route / gist:3412287
Created August 21, 2012 05:50
TextMate 2 .tm_properties

This is all based on the [alpha release][1].

Properties

From the built-in help system:

For many settings TextMate will look for a .tm_properties file in the current folder and in any parent folders (up to the user’s home folder).

These are simple setting = value listings where the value is a format string in which other variables can be referenced.

@route
route / gist:2601441
Created May 5, 2012 10:45
Static page generator
namespace :app do
namespace :error_pages do
desc "Generates static pages 500, 403, 404, 422"
task :generate => :environment do
av = ActionView::Base.new
av.class_eval do
include ApplicationHelper
include Rails.application.routes.url_helpers
end
@route
route / gist:2489600
Created April 25, 2012 13:11
Additions to rr stubbing
# Dynamic method stubbing
# user = Factory(:user)
# callbacks = User._create_callbacks.map(&:filter)
# stub_methods("user", callbacks)
def stub_methods(name, methods)
methods.each do |method|
eval "stub(#{name}).#{method}"
end
end
@route
route / .ackrc
Created March 28, 2012 15:33
Ackrc for TextMate
--type-add=html=.haml,.erb,.jade
--type-add=css=.sass,.scss,.erb
--type-add=js=.coffee,.erb,.haml
--type-add=objc=.pch
--type-set=xcode=.pbxproj,.pbxuser,.perspectivev3
--type-set=ragel=.rl
--type-set=nib=.xib
--type-set=plist=.plist
--type-set=tmstuff=.tmproj,.tm_build_errors
--nonib