Skip to content

Instantly share code, notes, and snippets.

View dinks's full-sized avatar

Dinesh Vasudevan dinks

View GitHub Profile
@them0nk
them0nk / rspec_rails_cheetsheet.rb
Created March 23, 2012 03:39
Rspec Rails cheatsheet (include capybara matchers)
#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)
@domenic
domenic / 1flickrApi.js
Last active April 4, 2018 07:35
Flickr API experiments
"use strict";
// Uses jQuery and Q.
var API_KEY = "whatever";
function getFlickrResponseAsync(method, responseProperty, params) {
var deferred = Q.defer();
$.ajax("http://www.flickr.com/services/rest/", {
@rogercampos
rogercampos / spec_utils.rb
Created June 29, 2012 14:07
Capybara helpers
def saop
save_and_open_page
end
def screenshot
page.driver.render("/home/roger/shot.jpg", :full => true)
end
def select_should_have(locator, text)
node = page.find_field(locator)
@xdite
xdite / 42-things.md
Created July 14, 2012 05:11
Ten (42) Things You Didn't Know Rails Could Do
@dinks
dinks / configuring tire for bonsai.md
Created December 11, 2012 13:08 — forked from nz/configuring tire for bonsai.md
Configuring Tire to work with Bonsai

1. Configure Tire to use the Bonsai ElasticSearch Heroku add-on

gem 'tire'

config/initializers/bonsai.rb

ENV['ELASTICSEARCH_URL'] = ENV['BONSAI_URL']

check_http: A Small Part of the Modern Monitoring Pipeline

[note: this was originally published on 08/27/2012. Other writing can be found here.]

Monitoring tooling has been a fascination of mine since I began hacking on computing systems. Every ops engineer wants to write their own. I get that. I'm one of those guys, too.

However, these endeavours always end up spitting out large, monolithic applications that just aren't as good as the already existing (and somewhat crappy) monolithic applications. I'd prefer to avoid that approach, if only to make it a point that the monitoring story can never be finalized. We will never reach an end state, but the more flexible our tooling the better.

Traditional Unix philsophy gives us something to go on here. What if, instead of writing large applications, we just wrote a bunch of tiny tools. AND - rather than writing each of these tiny tools as sexy network daemons (which

# Copyright (c) 2013 Stan Chang Khin Boon (http://lxcid.com/)
#
# 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:
#
# The above copyright notice and this permission notice shall be included in
@shaicoleman
shaicoleman / patcher.rb
Last active July 5, 2023 18:03
Initializer for mitigating CVE-2013-0156 and CVE-2013-0333 on all versions of rails
def rails_between(min, max)
Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new(min) && Gem::Version.new(Rails::VERSION::STRING) <= Gem::Version.new(max)
end
if rails_between('3.0.0', '3.0.18') || rails_between('3.1.0', '3.1.9') || rails_between('3.2.0', '3.2.10')
ActionDispatch::ParamsParser::DEFAULT_PARSERS.delete(Mime::XML)
end
if rails_between('2.0.0', '2.3.14')
ActionController::Base.param_parsers.delete(Mime::XML)
end
@turadg
turadg / application.rb
Last active August 1, 2024 08:35
Handle only 404s dynamically. It uses a normal controller and route for 404s, letting everything else go to the Rails default /public error pages. In my case it was to use the subdomain logic in my ApplicationController.
module MyApp
class Application < Rails::Application
require Rails.root + 'lib/custom_public_exceptions'
config.exceptions_app = CustomPublicExceptions.new Rails.public_path
end
end
@yury
yury / application.css.scss
Last active December 17, 2015 19:39
Example of tiny, smalll and large column and shortcuts for bootstrap 3.0.x grid
// Grid shortcuts
// use with https://github.com/anjlab/bootstrap-rails
//
// Columns for phones
// - columns: .x[1-12]
// For small devices (tablets and small desktops)
// - columns: .s[1-12]
// - offsets: .so[0-11]
// - pushes: .sr[0-11]
// - pulls: .sl[0-11]