Skip to content

Instantly share code, notes, and snippets.

View fweep's full-sized avatar

Jim Stewart fweep

View GitHub Profile
@fweep
fweep / gist:5148336
Created March 13, 2013 00:16
Clean up duplicate rows in a PostgreSQL table with differing IDs
-- Expensive sub-query method:
delete from questions_tags qt using questions_tags qt2 where qt.question_id = qt2.question_id and qt.tag_id = qt2.tag_id and qt.id != qt2.id and qt.id not in (select min(id) from questions_tags qt3 where qt.question_id = qt3.question_id and qt.tag_id = qt3.tag_id);
@fweep
fweep / .vimrc
Last active August 23, 2017 11:08
Vim configuration for interacting with cscope databases (focus on Ruby).
if has("cscope")
"TODO: turn this all into a plugin.
set nocscopetag
set cscopequickfix=s-,c-,d-,i-,t-,e-
set nocscopeverbose
if filereadable(".git/cscope.out")
cscope add .git/cscope.out
endif
set cscopeverbose
@fweep
fweep / quickfix_spec.rb
Created March 20, 2013 02:23
Simple RSpec example
describe "testing quickfix" do
it "should pass" do
true
end
it "should fail" do
fail "this test is broken"
end
end
@fweep
fweep / vim_formatter.rb
Last active December 15, 2015 04:29
Vim quickfix formatter for RSpec 2
# Adapted from https://github.com/bronson/vim-runtest/blob/master/rspec_formatter.rb.
require 'rspec/core/formatters/base_text_formatter'
class VimFormatter < RSpec::Core::Formatters::BaseTextFormatter
def example_failed example
exception = example.execution_result[:exception]
path = $1 if exception.backtrace.find do |frame|
frame =~ %r{\b(spec/.*_spec\.rb:\d+)(?::|\z)}
@fweep
fweep / quickfix_spec.rb
Created March 20, 2013 03:34
Simple RSpec spec.
describe "testing quickfix" do
it "should pass" do
true
end
it "should fail" do
fail "this test is broken"
end
end
@fweep
fweep / load_quickfix.vim
Last active December 15, 2015 04:29
Vim function to load .git/quickfix.out into the quickfix window.
function! LoadAndDisplayRSpecQuickfix()
let quickfix_filename = ".git/quickfix.out"
if filereadable(quickfix_filename) && getfsize(quickfix_filename) != 0
silent execute ":cfile " . quickfix_filename
botright cwindow
cc
else
redraw!
echohl WarningMsg | echo "Quickfix file " . quickfix_filename . " is missing or empty." | echohl None
endif
@fweep
fweep / gist:5241832
Created March 25, 2013 23:26
Host config with Vimrunner hanging
$ uname -a
Darwin lemur.wired.fweep.com 12.3.0 Darwin Kernel Version 12.3.0: Sun Jan 6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64 i386 MacBookAir4,2 Darwin
$ vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Mar 19 2013 10:54:27)
Included patches: 1-244, 246-762
Compiled by jim@lemur.wired.lan.fweep.com
Huge version with GTK2 GUI. Features included (+) or not (-):
+arabic +autocmd +balloon_eval +browse ++builtin_terms +byte_offset +cindent
+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
@fweep
fweep / gist:5306664
Created April 4, 2013 00:20
before filter example
class StudentsController < ApplicationController
before_filter :find_student, only: [:show, :update]
def show
# @student will already be loaded here
# do whatever
end
private
@fweep
fweep / test_login.py
Last active December 20, 2015 13:39
Pyramid, WebTest, SQLAlchemy functional test
import unittest
from myapp.tests.helper import create_user
SQLALCHEMY_URL = "postgresql://unireg@localhost/myapp"
def _init_testing_db():
from sqlalchemy import create_engine
from myapp.models import DBSession, Base
engine = create_engine(SQLALCHEMY_URL)
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from myapp.tests.base import ViewTestBase
from myapp.views.authentication.login import login_view
from myapp.tests.helper import create_user
class LoginViewTests(ViewTestBase):
def setUp(self):