Skip to content

Instantly share code, notes, and snippets.

View maestromac's full-sized avatar

Mac Siri maestromac

View GitHub Profile
@kinopyo
kinopyo / omniauth_macros.rb
Created November 4, 2011 05:44
Integration test with Omniauth. This example is using twitter, and assume you've installed rspec and capybara. Official document is here: https://github.com/intridea/omniauth/wiki/Integration-Testing
# in spec/support/omniauth_macros.rb
module OmniauthMacros
def mock_auth_hash
# The mock_auth configuration allows you to set per-provider (or default)
# authentication hashes to return during integration testing.
OmniAuth.config.mock_auth[:twitter] = {
'provider' => 'twitter',
'uid' => '123545',
'user_info' => {
'name' => 'mockuser',
@andreyvit
andreyvit / tmux.md
Created June 13, 2012 03:41
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a

@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@ryanb
ryanb / issues_with_modules.md
Created November 29, 2012 22:38
Points on how modules can make code difficult to read.

My issues with Modules

In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.

A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval.

You can find instance_eval used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.

class Article < ActiveRecord::Base
@joost
joost / ruby_google_analytics_server_to_server.md
Last active November 27, 2023 15:43
Google Analytics API (server-to-server) using Ruby
@paulodeleo
paulodeleo / .tmux.conf
Last active July 15, 2022 10:16
Tmux configuration to enable mouse scroll and mouse panel select, taken from: http://brainscraps.wikia.com/wiki/Extreme_Multitasking_with_tmux_and_PuTTY
# Make mouse useful in copy mode
setw -g mode-mouse on
# Allow mouse to select which pane to use
set -g mouse-select-pane on
# Allow mouse dragging to resize panes
set -g mouse-resize-pane on
# Allow mouse to select windows
@pglombardo
pglombardo / gist:7630100
Last active May 24, 2022 19:14
How to open your private Github repository and still keep a couple things under wrap

We're happy to say that we recently released the code for the TraceView Ruby instrumentation on Github as Open Source. There are a ton of benefits for AppNeta (and the community) in doing this so making the decision was easy... but the process of actually opening the repository and still keeping a few things private was slightly trickier. Here's the route we took that has worked out really well.

The Situation and Strategy

The Ruby instrumentation has always been sheltered on Github - albeit always in a private Github repository. We used the issues, pull requests and wiki pages extensively for everything from new employee resources to hosting screenshots, customer issues, internal discussions and links to other project and management tools (e.g. Asana).

Outside of the commits and the code, everything else was either of little use to the public or potentially company or customer confidential - stuff that shouldn't or couldn't be shared publicly. So this put us

@spilliton
spilliton / delayed_job_monkey_patch
Created January 18, 2014 19:06
Monkey patch for delayed_job to to ignore Delayed::DeserializationError when a job is run against a deleted active record model.
# config/initializers/delayed_job_config.rb
module Delayed
module Backend
module Base
def invoke_job_with_deserialize_catch
begin
invoke_job_without_deserialize_catch
rescue Delayed::DeserializationError
Rails.logger.error "Record was deleted when job ran!"
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@iangreenleaf
iangreenleaf / gist:b206d09c587e8fc6399e
Last active June 20, 2024 02:39
Rails naming conventions

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.