Skip to content

Instantly share code, notes, and snippets.

View waterlink's full-sized avatar

Alex Fedorov waterlink

View GitHub Profile
@waterlink
waterlink / rake.rb
Created March 18, 2014 15:15
RSpec setup for testing rake tasks
# spec/support/rake.rb
require 'rake'
module Rake::TestHelpers
def run_task(name=subject)
Rake::Task[name].reenable
Rake.application.invoke_task name
end
end
@waterlink
waterlink / database_cleaner.rb
Last active August 29, 2015 13:57
database_cleaner support config file for RSpec
# spec/support/database_cleaner.rb
# inspired by this article http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/
# and later edited according to thoughtbot/suspenders setup (truncation => deletion)
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:deletion)
end
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@waterlink
waterlink / skype-on-docker.sh
Created July 23, 2014 16:10
Skype on docker
# vi: syn=sh :
from ubuntu:12.04
run echo "deb http://archive.ubuntu.com/ubuntu precise main universe multiverse" > /etc/apt/sources.list
run echo "deb http://archive.canonical.com/ precise partner" >> /etc/apt/sources.list
run apt-get -qqyy update
run apt-get install -qqyy x11vnc xvfb skype pulseaudio pavucontrol openssh-server
@waterlink
waterlink / gist:1d03dffd6615a513bea8
Created September 20, 2014 18:48
tmux + vim moves
# smart pane switching with awareness of vim splits
bind -n C-h run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-h) || tmux select-pane -L"
bind -n C-j run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-j) || tmux select-pane -D"
bind -n C-k run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-k) || tmux select-pane -U"
bind -n C-l run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys C-l) || tmux select-pane -R"
bind -n C-\ run "(tmux display-message -p '#{pane_current_command}' | grep -iq vim && tmux send-keys 'C-\\') || tmux select-pane -l"
target/john: error while loading shared libraries: libgenerator-e170cac01c08bdc6.so: cannot open shared object file: No such file or directory
@waterlink
waterlink / lib.rs
Last active August 29, 2015 14:08
Rust: How to get +50 to karma when implementing an Open Source library ?
// Use these lines in your root crate source code
#![deny(missing_docs)]
#![deny(warnings)]
// This stuff really works. It adds +50 to karma.
// And frequency of trains being delayed when you want to get
// somewhere in hurry really drops :)
@waterlink
waterlink / deriving.rs
Created November 4, 2014 15:29
Rust: Clone, Show, Send & friends
// Clone - for cloning non-owned resources to
// make actions that require ownership
// over them
// Show - if you ever want to log the value of
// this enum
// Send - if you ever want to send it over
// channel to a different task
// PartialEq - if you want to check if two instances
// of this enum are the same
@waterlink
waterlink / tips.md
Created November 6, 2014 10:17
Some tips
  • Use CONTRIBUTING.md for github to show a link when creating a pull request
  • http://tom.preston-werner.com/2010/08/23/readme-driven-development.html
  • git checkout - to switch to previous branch (that way you can switch between 2 branches forth and back)
  • The first commit of a repo, as the first commit cannot be rebased later: git commit -m "init repo" --allow-empty
  • git status -sb
@waterlink
waterlink / struct_dsl.rb
Created November 7, 2014 09:54
Struct implementation as a module to extend
require 'rspec'
module StructDsl
def with_attributes(*args)
include Enumerable
args.map!(&:to_sym)
args.freeze
args.each { |p| attr_accessor p }