Skip to content

Instantly share code, notes, and snippets.


Andrés Álvarez aalvrz

View GitHub Profile
Django ORM Optimization Tips
* Only use optimizations that obfuscate the code if you need to.
* Not all of these tips are hard and fast rules.
* Use your judgement to determine what improvements are appropriate for your code.
# ---------------------------------------------------------------------------
indiesquidge /
Created Jan 19, 2016
how to access subdomains locally with Rails 5

Subdomaining Localhost with Rails 5

I've been following this blog post on how to set up an api-only Rails 5 application. One of the sections talks about creating a subdomain for your api

Rails.application.routes.draw do
  constraints subdomain: "api" do
    scope module: "api" do
danielpuglisi / users_controller.rb
Last active Apr 21, 2020
Rails examples: Single Table Inheritance (STI), strong parameters, single controller.
View users_controller.rb
# Variant 1
def user_params(type)
# Variant 2
def user_params(type)
case type
when "user"
JosefJezek /
Created Jan 21, 2014
Zenoss Uninstall / Remove / Delete

Zenoss Uninstall / Remove / Delete

service zenoss stop

yum remove zenoss mysql-server mysql-client mysql-shared rabbitmq-server redis memcached
rpm -ef --nodeps MySQL-shared-compat

rm -rf /var/lib/mysql/
rm -rf /var/lib/rabbitmq/
them0nk / rspec_rails_cheetsheet.rb
Created Mar 23, 2012
Rspec Rails cheatsheet (include capybara matchers)
View rspec_rails_cheetsheet.rb
@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
response.should render_template(:index)
response.should redirect_to(movies_path)
cluther / zenoss-shell-functions
Last active Jan 7, 2020
Zenoss JSON API Examples (curl)
View zenoss-shell-functions
# This shell script is intended to be sourced into your shell. It adds
# Default Zenoss server settings.
[ -z "$ZENOSS_URL" ] && export ZENOSS_URL="http://localhost:8080"
[ -z "$ZENOSS_USERNAME" ] && export ZENOSS_USERNAME="admin"
[ -z "$ZENOSS_PASSWORD" ] && export ZENOSS_PASSWORD="zenoss"
# Generic call to make Zenoss JSON API calls easier on the shell.
zenoss_api () {
henkm / gist:952240
Created May 2, 2011
Add new items via JQuery TokenInput / Ruby on Rails
View gist:952240
#model (idea 100% stolen from ryanb)
def author_tokens=(ids)
ids.gsub!(/CREATE_(.+?)_END/) do
Author.create!(:name => $1).id
self.author_ids = ids.split(",")
# jquery.tokeninput.js
You can’t perform that action at this time.