Skip to content

Instantly share code, notes, and snippets.

@showaltb
showaltb / remove-accidentally-added-file.md
Created August 1, 2015 14:25
Remove a file accidentally added with git commit

If you've created a git commit and accidentally included one or more files you didn't intend to, you can remove those files from the commit and place them back in the "Changed but not updated" or "Untracked files" state. Note: do this only if you have not pushed the commit, since this will rewrite history.

git reset HEAD^ file(s)...

git commit --amend -C HEAD

@showaltb
showaltb / gist:2394751
Created April 15, 2012 20:47
Install ElasticSearch 0.19.2 on CentOS 6.0
# (thanks to https://gist.github.com/1556657)
# As root:
yum install java-1.6.0-openjdk.i686
wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.2.tar.gz
tar xf elasticsearch-0.19.2.tar.gz
rm elasticsearch-0.19.2.tar.gz
mv elasticsearch-0.19.2 /usr/local/share/elasticshare
@showaltb
showaltb / notes.rb
Last active December 16, 2015 16:20
Add Rspec and Cucumber to Rails "rake notes"
# add to lib/tasks/notes.rb:
task :configure_annotations do
Rails.application.configure do
config.annotations.directories.concat %w(spec features)
config.annotations.register_extensions('feature') { |tag| /#\s*(#{tag}):?\s*(.*)$/ }
end
end
task :notes => :configure_annotations
@showaltb
showaltb / refactor_spec.rb
Last active May 4, 2016 16:09
Example of refactoring a spec
# BEFORE
describe '#remove_existing_ife_documents' do
it 'removes any existing documents on the item with the ife_id field set' do
item.documents << FactoryGirl.create(:document, document_type: document_type)
item.documents << FactoryGirl.create(:document, document_type: document_type, ife_id: '1234')
expect(item.documents.count).to eql(2)
ife_document_creator.send(:remove_existing_ife_documents)
expect(item.documents.count).to eql(1)
end
@showaltb
showaltb / gist:2975239
Created June 22, 2012 21:14
Configuring full stack on CentOS 6.x
# Install JDK
yum install java-1.6.0-openjdk-devel
# Install ActiveMQ
cd /package
wget http://www.carfab.com/apachesoftware/activemq/apache-activemq/5.6.0/apache-activemq-5.6.0-bin.tar.gz
cd /opt
tar xf /package/apache-activemq-5.6.0-bin.tar.gz
@showaltb
showaltb / become_matchers.rb
Last active October 20, 2016 02:59
RSpec become, become_truthy, become_falsey matchers
# Matchers that will wait for a value to change.
# Tested with Ruby 2.3, RSpec 3.3
# Ex. expect { email.reload.delivered? }.to become_truthy
RSpec::Matchers.define :become_truthy do
supports_block_expectations
match do |block|
begin
Timeout.timeout(Capybara.default_max_wait_time) do
sleep(0.1) until value = block.call
#!/usr/bin/env perl
#
# A solution to http://blogs.perl.org/users/ovid/2014/12/a-small-puzzle-for-you.html
use Modern::Perl;
use Data::Printer multiline => 0;
my @a = ( 'b', 'c', 'f' );
my @b = ( 'a', 'd' );
my @c = ( 'c', 'd', 'e' );
@showaltb
showaltb / proxy.yml
Created November 4, 2016 13:14
Ansible playbook to provision a tinyproxy server on an Ubuntu or CentOS (7.1+) host
# provision a tinyproxy server on an Ubuntu or CentOS (7.1+) host
- hosts: proxies
become: true
roles:
- geerlingguy.firewall
vars:
firewall_allowed_tcp_ports: [ 22, 8888 ]
@showaltb
showaltb / gist:8542626
Created January 21, 2014 15:50
Install PhantomJS on Amazon AMI x86_64
# download and unpack distribution
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.6-linux-x86_64.tar.bz2
tar xf phantomjs-1.9.6-linux-x86_64.tar.bz2
# copy binary
cd phantomjs-1.9.6-linux-x86_64
cp bin/phantomjs /usr/local/bin
@showaltb
showaltb / define_method.rb
Created November 22, 2018 17:38
Example of using define_method in a mixin to define a method in an including class/module
module MyMixin
def self.included(other)
other.instance_eval do
define_method :bar do
puts 'bar called'
end
end
end
end