Skip to content

Instantly share code, notes, and snippets.

View mpereira's full-sized avatar

Murilo Pereira mpereira

View GitHub Profile
require 'test/unit'
require 'test/unit/ui/console/testrunner'
def scrubble(array)
array.dup.inject([]) do |scrubbled, element|
scrubbled << array.reject { |e| e == element }
end
end
class ScrubbleTest < Test::Unit::TestCase

If you want to do something like

Then the output should contain "\"bob saget\",1234123412"

This is the step definition you would probably write

Then /^the output should contain "(.*)$" do |text|
  Output.string.should be_include(text)
# encoding: utf-8
# Copyright (C) 2011 by Murilo Pereira <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
battle_cries = [{ king_leonidas: 'This is where we fight! This is where they die!' },
{ he_man: 'By the power of Greyskull... I have the powerrr!' },
{ sindel: 'You are pathetic and weak.' },
{ shang_tsung: 'Your soul is mine!' },
{ klingons: 'Today is a good day to die!' }]
def from_mortal_kombat?(battle_cry)
[:sindel, :shang_tsung].include?(battle_cry.keys.first)
end

Remove trailing whitespace, convert tabs to spaces and file format to unix (remove ugly ^M carriage returns) from files using a single command:

vim -es -c 'set et ts=2 | bufdo retab | %s/\s\+$//e | set ff=unix | w' -c 'q' FILES

You could get your FILES using find

vim -es -c 'set et ts=2 | bufdo retab | %s/\s\+$//e | set ff=unix | w' -c 'q' $(find scripts -name '*.sh' -type f)

If in doubt, ask man.

# Add all gems in the global gemset to the $LOAD_PATH so they can be used even
# in bundled ruby projects without declaring them in the Gemfile.
if defined?(::Bundler)
$LOAD_PATH.concat(Dir.glob("#{ENV['rvm_ruby_global_gems_path']}/gems/*/lib"))
end
#include <gtk/gtk.h>
#include <libappindicator/app-indicator.h>
int main(int argc, char **argv) {
gtk_init(&argc, &argv);
AppIndicator *app_indicator;
app_indicator = app_indicator_new("foo",
"",
APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
@mpereira
mpereira / gist:3072187
Created July 8, 2012 18:26
A little help to stop unconsciously checking distracting web sites.
alias focus="sudo sh -c \"echo '127.0.0.1 www.facebook.com twitter.com mail.google.com # aab6de513ab5de9359809f3cdb62d352' >> /etc/hosts\""
alias unfocus='sudo sed -i "" "/aab6de513ab5de9359809f3cdb62d352/d" /etc/hosts'
name of display: :0
display: :0 screen: 0
direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.4
server glx extensions:
GLX_ARB_create_context, GLX_ARB_create_context_profile,
GLX_ARB_multisample, GLX_EXT_create_context_es2_profile,
GLX_EXT_import_context, GLX_EXT_texture_from_pixmap, GLX_EXT_visual_info,
GLX_EXT_visual_rating, GLX_INTEL_swap_event, GLX_MESA_copy_sub_buffer,
[ 7.114]
X.Org X Server 1.13.4
Release Date: 2013-04-17
[ 7.114] X Protocol Version 11, Revision 0
[ 7.114] Build Operating System: Linux 2.6.24-32-xen x86_64 Ubuntu
[ 7.114] Current Operating System: Linux pluto 3.8.0-27-generic #40-Ubuntu SMP Tue Jul 9 00:17:05 UTC 2013 x86_64
[ 7.114] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-3.8.0-27-generic root=UUID=12054a51-399c-4846-a704-1d3fecf982ab ro modprobe.blacklist=xhci_hcd quiet splash vt.handoff=7
[ 7.114] Build Date: 08 May 2013 02:34:03PM
[ 7.114] xorg-server 2:1.13.4~git20130508+server-1.13-branch.10c42f57-0ubuntu0ricotz~raring (For technical support please see http://www.ubuntu.com/support)
[ 7.114] Current version of pixman: 0.28.2